OK sorted it myself, though I think I need to study it to be sure I understand...
Here is my fixed code. I would very much like comments on the code. So I can do better next time.
I know the map needs to be better to even out the game play and I could do something with graphics to improve the score, restart bits, and add a title
rem ***** Main Source File *****
set display mode 640,480,32
hide mouse
set image colorkey 255,0,255
sync rate 30
sync on
color backdrop 0
create animated sprite 1,"helicopter.bmp",3,1,100
offset sprite 1,21,24
set sprite priority 1,0
load image "wall.bmp",1,1
sprite 2,-1000,-1000,1
create animated sprite 3,"myboom.bmp",16,1,101
offset sprite 3,24,24
load sound "boom.wav",1
load sound "Heliloop.wav",2
rem sprite 1 Helicopter
rem sprite 2 Wall
rem sprite 3 Explosion
restart:
global backgroundscrollrate
global backgroundxoffset
global backgroundx
global characterx
global charactery
global characterspeed
global score
global playexplosion
init()
build_map()
loop sound 2
`Game Loop
do
scroll_background()
move_character()
draw_background()
sprite 1, characterx, charactery, 100
play sprite 1,1,3,20
`Give them chance to get moving before checking for a crash
`if check_crash() = 1 and score > 3
if check_crash() = 1 and score > 30
`stop the background moving
backgroundscrollrate = 0
`stop the helicopter moving
characterspeed = 0
stop sound 2
`hide the copter
hide sprite 1
`display explosion
sprite 3, characterx, charactery, 101
`start playing explosion sound first time through the loop
if playexplosion = 1 then play sound 1
playexplosion=0
if sprite frame(3) = 16
hide sprite 3
else
show sprite 3
play sprite 3,1,16,20
endif
showscore()
center text screen width()/2,10,"Right Click To Try Again"
if mouseclick()=2 then exit
else
score = score + 1
showscore()
endif
sync
loop
`clean up
sprite 1, -100,-100,100
show sprite 1
set sprite frame 3,1
cls
sync
goto restart
end
function move_character()
if mouseclick() = 1
dec charactery, characterspeed : if charactery < 22 then charactery = 22
else
inc charactery, characterspeed : if charactery > 463 then charactery = 463
endif
endfunction
function scroll_background()
inc backgroundxoffset, backgroundscrollrate
if backgroundxoffset > 15360
backgroundxoffset = 0
inc backgroundx, 1
endif
endfunction
function draw_background()
for x = 0 to 500
for y = 0 to 14
if map(x,y) = 2 then paste sprite 2,x*32-backgroundxoffset,y*32
next y
next x
endfunction
function check_crash()
backdropcollision = 0
`Check for collision above or below helicopter
if point(characterx,charactery+21) <> 0 OR point(characterx,charactery-21) <> 0 THEN backdropcollision = 1
`Check for collision In front ofhelicopter
if point(characterx+25 ,charactery) <> 0 THEN backdropcollision = 1
endfunction backdropcollision
function build_map()
rem build the map
load bitmap "level1map.bmp",10
dim map(500,20)
for x=0 to 500
for y = 0 to 20
if point(x,y)=0 then map(x,y) = 2
next y
next x
delete bitmap 10
endfunction
function showscore()
showscore$ = str$(score/3)
text 10,10, "Score: " + showscore$
endfunction
function init()
backgroundscrollrate = 2
backgroundxoffset = 0
backgroundx = 0
characterx = screen width() / 4
charactery = screen height() / 2
characterspeed = 2
score = 0
playexplosion = 1
endfunction