Hi... This code is a space simulator that when you press "Space", you will move at an increasing speed. However, I noticed that you went too fast, so I tried to slow it down. But the speed always goes into negative numbers and the ship moves backwards! Can someone help?
Source Code:
REM Project: Spaceflight Sim
REM Created: 1/21/2007 7:20:25 PM
REM
REM ***** Main Source File *****
REM
sync on
sync rate 0
randomize timer()
hide mouse
make object sphere 1,1
for x = 3 to 1000
make object sphere x,5
position object x,rnd(500),rnd(500),rnd(500)
next x
color backdrop 0
xpos = 0
ypos = 0
zpos = 0
gear$ = "forward"
speed# = 0.01
do
position camera object position x (1), object position y (1), object position z (1)
CAMY#=CAMY#+mousemovex()*.1
CAMX#=CAMX#+mousemovey()*.1
if CAMX#>90 and CAMX#<135 then CAMX#=90
if CAMX#>270 and CAMX#<225 then CAMX#=90
yrotate camera CAMY#
xrotate camera CAMX#
yrotate object 1,CAMY#
xrotate object 1,CAMX#
circle screen width()/2,screen height()/2,5
text 5,5, "X: " + str$(object position x(1))
text 5,20, "Y: " + str$(object position y(1))
text 5,35, "Z: " + str$(object position z(1))
text 5,50, "FPS: " + str$(screen fps())
text 5,65, "Speed: " + str$(speed#)
if shiftkey()=1
if gear$ = "forward" then gear$ = "reverse"
if gear$ = "reverse" then gear$ = "forward"
endif
if spacekey()=1
if gear$ = "forward" then move object 1, speed#
if gear$ = "reverse" then move object 1, speed#
if slow# = 0 then speed# = speed# * 1.1
if speed# > 10 then slow# = 100
if speed# <= 0.1 then slow# = 0
if speed# <= -2 then speed = 1
endif
if speed# <= -2 then speed = 1
if slow# = 100 then dec speed#,0.1
sync
loop