Cool. There seems to be some problems with some of the auto-iuntenting. It is quite irregular so I can't explain it. Just use it on this code and look at the if-endifs, do-loops etc. to see the irregularities...
SYNC ON
HIDE MOUSE
type XYZType
x AS FLOAT
y AS FLOAT
z AS FLOAT
endtype
`Constant keeping program going whatever the framerate
GLOBAL programSpeed AS INTEGER = 60
GLOBAL lastTime AS INTEGER
GLOBAL loopVar AS FLOAT
SYNC RATE 10
`For-next loop variables
GLOBAL x AS INTEGER
GLOBAL y AS INTEGER
GLOBAL z AS INTEGER
`Mouse variables
mouseMovementX AS INTEGER
mouseMovementY AS INTEGER
mouseHold AS INTEGER
`General variables
gravity AS FLOAT = 0.05
`Player temp variables
xPos AS FLOAT
yPos AS FLOAT = 200.0
zPos AS FLOAT
playerGrav AS FLOAT
turn AS FLOAT
look AS FLOAT
speed AS FLOAT
sideSpeed AS FLOAT
`Player constants
playerHeight AS FLOAT = 50.0
maxSpeed AS FLOAT = 5.0
accel AS FLOAT = 0.5
turnSpeed AS FLOAT = 3.0
jumpPower AS FLOAT = 10.0
`Adjust to adjust height at which collision is done
collisionOffset AS FLOAT = 0.0
LOAD OBJECT "C:\Program Files\Dark Basic Software\DeleD\X Files\winter.x",10000
SET OBJECT FILTER 10000,2
SET OBJECT TRANSPARENCY 10000,1
SET AMBIENT LIGHT 100
SET OBJECT AMBIENCE 10000,RGB(255,255,255)
POSITION OBJECT 10000,0,-100,0
SET CAMERA RANGE 1,10000
time AS INTEGER
time = TIMER()
`Stablize sync rate
REPEAT
loopVar=(TIMER()-lastTime)/(1000.0/programSpeed)
lastTime=TIMER()
TEXT 20,20,"Sync rate stablizing"
SYNC
UNTIL TIMER()-time > 500
do
mouseMovementX=MOUSEMOVEX()
mouseMovementY=MOUSEMOVEY()
GOSUB _controlPlayer
GOSUB _playerCollision
GOSUB _positionPlayer
loopVar=(TIMER()-lastTime)/(1000.0/programSpeed)
lastTime=TIMER()
TEXT 20,20,"FPS: "+STR$(SCREEN FPS())
TEXT 20,40,"LoopVar: "+STR$(loopVar)
TEXT 20,60,"YPos: "+STR$(yPos)
if ESCAPEKEY()=1 THEN END
SYNC
loop
`Contol the players movement
_controlPlayer:
`Player movement
if UPKEY()=1
speed = accelerateVar(speed,accel,maxSpeed)
ELSE
if DOWNKEY()=1
speed = decelerateVar(speed,accel,-maxSpeed)
ELSE
speed = minimizeVar(speed,accel)
endif
endif
if RIGHTKEY()=1
sideSpeed = accelerateVar(sideSpeed,accel,maxSpeed)
ELSE
if LEFTKEY()=1
sideSpeed = decelerateVar(sideSpeed,accel,-maxSpeed)
ELSE
sideSpeed = minimizeVar(sideSpeed,accel)
endif
endif
`Turning
turn=WRAPVALUE(turn+mouseMovementX/4.0)
look=WRAPVALUE(look+mouseMovementY/4.0)
`Adjust variables
INC xPos,SIN(turn)*speed*loopVar
INC zPos,COS(turn)*speed*loopVar
INC xPos,SIN(WRAPVALUE(turn+90))*sideSpeed*loopVar
INC zPos,COS(WRAPVALUE(turn+90))*sideSpeed*loopVar
`Jumping
if MOUSECLICK()=2 AND jump=0
playerGrav = -jumpPower
jump=1
endif
for x=1 TO programSpeed*loopVar
INC playerGrav,gravity
DEC yPos,playerGrav
next x
RETURN
`Control the collision between player and environment
_playerCollision:
`Upward collision
for x=1 TO 2
height#=INTERSECT OBJECT(10000,xPos,yPos-playerHeight,zPos,xPos,yPos,zPos)
if height#>0
playerGrav=0
yPos=yPos+height#
jump=0
endif
next x
`Sideways collision
for x=0 TO 3
dist#=INTERSECT OBJECT(10000,xPos+SIN(x*90)*30,yPos+collisionOffset,zPos+COS(x*90)*30,xPos,yPos+collisionOffset,zPos)
if dist#>0
xPos=xPos-SIN(x*90)*dist#
zPos=zPos-COS(x*90)*dist#
endif
next x
RETURN
`Position the camera and player object
_positionPlayer:
POSITION CAMERA xPos,yPos,zPos
ROTATE CAMERA look,turn,0
RETURN
`Acceleration
FUNCTION accelerateVar(speed AS FLOAT, accel AS FLOAT, maxSpeed AS FLOAT)
INC speed,accel*loopVar
if speed>maxSpeed THEN speed=maxSpeed
ENDFUNCTION speed
`Deceleration
FUNCTION decelerateVar(speed AS FLOAT, accel AS FLOAT, minSpeed AS FLOAT)
DEC speed,accel*loopVar
if speed<minSpeed THEN speed=minSpeed
ENDFUNCTION speed
`Gradually make variable 0
FUNCTION minimizeVar(speed AS FLOAT, accel AS FLOAT)
if speed>-accel/2.0*loopVar AND speed<accel/2.0*loopVar
speed = 0
ELSE
if speed>0
DEC speed,accel*loopVar
ELSE
INC speed,accel*loopVar
endif
endif
ENDFUNCTION speed
I'm quite confused about this. The indentation ends half way through!
do
mouseMovementX=MOUSEMOVEX()
mouseMovementY=MOUSEMOVEY()
GOSUB _controlPlayer
GOSUB _playerCollision
GOSUB _positionPlayer
loopVar=(TIMER()-lastTime)/(1000.0/programSpeed)
lastTime=TIMER()
TEXT 20,20,"FPS: "+STR$(SCREEN FPS())
TEXT 20,40,"LoopVar: "+STR$(loopVar)
TEXT 20,60,"YPos: "+STR$(yPos)
if ESCAPEKEY()=1 THEN END
SYNC
loop
Also I think subroutines should be indented. You could always give further options to choose the cases where you should indent.
Thanks.
Trying is the first step towards faliure.
The Basics of DBPro Tutorial, on my site now!
Athelon XP 1600 Plus (1.4ghz) - ATI Radeon 9600 Pro - 256mb RAM