I want top move the spaceship forward and backwards!... i managed to make it turn around but i struggled to make it move forwared and backward... please can you help me to slove the problem...
#CONSTANT ship 1
#CONSTANT firstmissile 101
#CONSTANT firstasteroid 51
GLOBAL keypressed AS BYTE
GLOBAL missileno AS INTEGER
GLOBAL angle AS BYTE
GLOBAL lastfired AS FLOAT
GLOBAL DIM missilemoves(5)
missileno = firstmissile
Initialisegame()
do
handlekeyboard()
handleship()
HandleMissles()
handleasteroids()
loop
end
FUNCTION initialisegame()
REM *** SET THE SCREEN RESOLUTION ***
SET DISPLAY MODE 1280,1024,32
REM *** MAKE MAGENTA THE TRANSPARENT COLOUR ***
SET IMAGE COLORKEY 255,0,255
REM *** LOAD image ***
LOAD IMAGE \"background.bmp\",4
sprite 1001,0,0,4
LOAD IMAGE \"ship.bmp\",2
LOAD IMAGE \"missilemag.bmp\",3
SPRITE ship,SCREEN WIDTH()/2,SCREEN HEIGHT()/2,2
OFFSET SPRITE ship,SPRITE WIDTH (ship)/2,SPRITE HEIGHT(ship)/2
lastfired = TIMER()
For c=0 to 5
missilemoves(c)=0
next c
createasteroids()
startpositionforasteroids()
ENDFUNCTION
function HandleKeyBoard()
rem *** INITIALISE VARIABLE
keypressed = 0
rem
if keystate(203) = 1 `left
keypressed = 1
else
rem
if keystate(205) = 1 `right
keypressed = 2
else
rem
if keystate(200) = 1 `up
keypressed = 4
else
rem
if keystate(208) = 1 `down
keypressed = 5
endif
endif
endif
endif
rem
if keystate(57) = 1 `space
keypressed = 3
endif
endfunction
function handleship()
rem
if keypressed = 1 `left
rem angle = WRAPVALUE(angle - 5) `old
angle = angle - 5
ENDIF
rem
if keypressed = 2 `right
rem angle = WRAPVALUE(angle + 5) `old
angle = angle + 5
endif
rem
if keypressed = 3 and timer() - lastfired >1000 `space
launchmissile()
endif
rem
if keypressed = 4 `up
move sprite ship,1
endif
rem
if keypressed = 5 `down
move sprite ship,-1
endif
rem
rotate sprite ship,angle
endfunction
Function LaunchMissile()
Rem ***
sprite missileno, sprite x(ship), sprite y(ship),3
rem ***
offset sprite missileno, sprite width(missileno)/2, sprite height (missileno)/2
rotate sprite missileno, sprite angle (ship)
move sprite missileno, 70
rem ***
rem ***
missileno = missileno mod 1 + firstmissile
endfunction
function HandleMissles()
rem
for spriteno = firstmissile to firstmissile + 5
rem
if sprite exist(spriteno)
move sprite spriteno, 15
rem
spritehit = sprite hit (spriteno,0)
if spritehit > 1
delete sprite spritehit
delete sprite spriteno
post = spriteno - firstmissile
missilemoves(post) = 0
else
rem
post = spriteno - firstmissile
inc missilemoves(post)
rem
rem
if missilemoves(post)>=40
delete sprite spriteno
missilemoves(post) = 0
endif
endif
endif
next spriteno
endfunction
Function HandleAsteroids()
rem
for spriteno = firstasteroid to firstasteroid + 5
if sprite exist (spriteno)
rem
move sprite spriteno,1
rem
if sprite y(spriteno) < 0 `top
sprite spriteno, sprite x (spriteno), screen height(),1
endif
if sprite y (spriteno) > screen height() ` bottom
sprite spriteno, sprite x(spriteno),0,1
endif
if sprite x (spriteno)< 0 `left
sprite spriteno, screen width(), sprite y(spriteno),1
endif
if sprite x(spriteno) > screen width() `right
sprite spriteno,0,sprite y(spriteno),1
endif
rem
play sprite spriteno ,1,16,20
endif
next spriteno
endfunction
function createasteroids()
rem
create animated sprite firstasteroid,\"animspr.bmp\",4,4,1
OFFSET SPRITE firstasteroid, sprite width (firstasteroid)/2,sprite height(firstasteroid)/2
rem
for spriteno = firstasteroid + 1 TO firstasteroid + 5
clone sprite firstasteroid,spriteno
next spriteno
endfunction
function startpositionforasteroids()
rem
for spriteno = firstasteroid to firstasteroid + 5
rem
side = rnd(3)
rem
select side
case 0 `top of the screen
x = rnd(screen width())
y = 0
angle = rnd(180)+90
endcase
case 1 `right side
x = screen width()
y = rnd(screen height())
angle = rnd (180)+180
endcase
case 2 `bottom of the screen
x = rnd(screen width())
y = screen height()
angle = rnd(180)-90
endcase
case 3 `left side
x = 0
y = rnd (screen height())
angle = rnd(180)
endcase
endselect
rem
rotate sprite spriteno,angle
sprite spriteno,x,y,1
next spriteno
endfunction