Im trying to get my code to revert to the beginning , but im having a lot of problems at the moment.I've tried gosub and goto but it just hangs at the endgame credits.Maybe a fresh pair of eyes could point out my problem.?
cls
REM SET DEFAULT DISPLAY CONFIGURATION
set display mode 640,480,32
hide mouse
start_of_game:
cls
REM LOAD TITLE SCREEN
load image "images/title.bmp", 20
REM DRAW TITLE SCREEN
do
paste image 20, 0,0
if spacekey()=1 then exit
loop
delete image 20
return
REM LOAD SECOND TITLE SCREEN
options:
load image "images/options.bmp", 21
do
paste image 21 ,0,0
if keystate(2)=1 then gosub characters
if keystate(3)=1 then gosub howtoplay
if keystate(4)=1 then gosub credits
loop
delete image 21
return
REM CHARACTER SCREEN
characters:
load image "images/character.bmp", 22
do
paste image 22, 0,0
if keystate(2)=1 then gosub playgame
loop
delete image 22
return
REM MAIN GAME LOOP
playgame:
REM SET INITIAL COORDINATES OF IMAGE1 AND IMAGE2
a = 10
b = 10
x = 590
y = 400
p1health = 100
p2health = 100
rem LOAD PLANE SPRITES GRAPHICS INTO HIDDEN BITMAP
load bitmap "images/plane1_sprite.bmp",1
REM GRAB IMAGES FOR PLANE SPRITE ANIMATION
get image 1,0,0,50,50
get image 2,50,0,100,50
get image 3,100,0,150,50
get image 4,150,0,200,50
get image 5,200,0,250,50
get image 6,250,0,300,50
get image 7,300,0,350,50
get image 8,350,0,400,50
REM DELETE ORIGINAL BITMAP AS TO FREE MEMORY SPACE
delete bitmap 1
REM LOAD BITMAP 2
load bitmap "images/plane2_sprite.bmp",1
REM CHOP IMAGES OUT OF BITMAP
get image 9,0,0,50,50
get image 10,50,0,100,50
get image 11,100,0,150,50
get image 12,150,0,200,50
get image 13,200,0,250,50
get image 14,250,0,300,50
get image 15,300,0,350,50
get image 16,350,0,400,50
REM DELETE BITMAP 1 AS TO FREE MEMORY SPACE
delete bitmap 1
REM LOAD BULLET BITMAP
load image "images/bullet-single.bmp",66
remstart
load bitmap "images/bullets.bmp",1
REM CHOP IMAGES OUT OF BITMAP
get image 30,0,0,50,50
get image 31,50,0,100,50
get image 32,100,0,150,50
get image 33,150,0,200,50
get image 34,200,0,250,50
get image 35,250,0,300,50
get image 36,300,0,350,50
get image 37,350,0,400,50
REM DELETE BITMAP 1 AS TO FREE MEMORY SPACE
delete bitmap 1
remend
REM LOAD OTHER IMAGES
load image "images/coastline.bmp",17
REM SYNC TELLS PROGRAM TO ONLY DRAW TO SCREEN WHEN INSTRUCTED
sync on
REM SET THE VALUES IF CURRENTIMAGE TO THE NUMBER OF THE IMAGE YOU WANT TO START WITH
currentimage = 1
currentimage2 = 9
PLANE_SPEED = 6
winner = 0
REM THESE ARE VARIABLES FOR BULLETS HERE
BULLET_SPEED = 11
BULLET_POWER = 3
p1b_active = 0
p1b_xpos = 10
p1b_ypos = 10
p1b_dir = 1
p2b_active = 0
p2b_xpos = 10
p2b_ypos = 10
p2b_dir = 1
rem setup bullets
gosub initialise_bullets
REM PLAY BGMUSIC
load music "music\topgun3.mp3",1
play music 1
REM START THE MAIN LOOP
do
paste image 17,0,0
REM SET CONDITIONS
REM IF ARROW KEYS IS PRESSED THE CORRESPONDING IMAGE SHOWS
if upkey()=1 then y=y-PLANE_SPEED : currentimage=1
if downkey()=1 then y=y+PLANE_SPEED : currentimage=3
if rightkey()=1 then x=x+PLANE_SPEED : currentimage=2
if leftkey()=1 then x=x-PLANE_SPEED : currentimage=4
REM SET CONDITIONS IF TWO KEYS ARE PRESSED
REM N.B CAN ONLY DETECT ONE SCANCODE AT A TIME, SO COMBINED CODE
if upkey()=1 AND rightkey()=1 then currentimage=7
if upkey()=1 AND leftkey()=1 then currentimage=5
if downkey()=1 AND rightkey()=1 then currentimage=6
if downkey()=1 AND leftkey()=1 then currentimage=8
REM SET CONTROL RULES FOR SECOND SPRITE
if keystate(17)=1 then b=b-PLANE_SPEED : currentimage2=9
if keystate(31)=1 then b=b+PLANE_SPEED : currentimage2=11
if keystate(32)=1 then a=a+PLANE_SPEED : currentimage2=10
if keystate(30)=1 then a=a-PLANE_SPEED : currentimage2=12
if keystate(17)=1 AND keystate(32)=1 then currentimage2=15
if keystate(17)=1 AND keystate(30)=1 then currentimage2=13
if keystate(31)=1 AND keystate(32)=1 then currentimage2=14
if keystate(31)=1 AND keystate(30)=1 then currentimage2=16
REM NOW PUT CURRENT IMAGE TO SCREEN X,Y BY PUTTING IMAGE INTO SPRITE
REM A SPRITE IS A SIMPLE ANIMATION OF FRAMES OR PICTURE
sprite 1, x, y, currentimage
sprite 2, a, b, currentimage2
REM CODE TO MAKE PLANE RE_APPEAR AFTER EXITIING SCREEN
rem plane one
if a > 640 then a = -30
if a < -30 then a = 640
if b > 480 then b = -30
if b < -30 then b = 480
rem plane two
if x > 640 then x = -30
if x < -30 then x = 640
if y > 480 then y = -30
if y < -30 then y = 480
REM TEST TO SEE IF WE NEED TO ADD A BULLET
if keystate(53) then gosub add_bullet_p1
if keystate(33) then gosub add_bullet_p2
rem update bullets
gosub update_bullets
rem render bullets
gosub render_bullets
rem check bullets for collisions
gosub collide_bullets
rem draw health information
rem box l, t, r, b
rem player one
ink 0, 0
box 9, 229, 19, 331
ink rgb(0,255,0),0
if p1health < 66 then ink rgb(255,128,0),0
if p1health < 33 then ink rgb(255,0,0),0
box 10, 330 - p1health, 18, 330
rem player two
ink 0, 0
box 621, 229, 631, 331
ink rgb(0,255,0),0
if p2health < 66 then ink rgb(255,128,0),0
if p2health < 33 then ink rgb(255,0,0),0
box 622, 330 - p2health, 630, 330
rem check for end game
if p1health <= 0 then winner = 2
if p2health <= 0 then winner = 1
if winner > 0 then goto endgame
rem this actually makes things appear
sync
rem end main loop
loop
rem end game subroutine
return
REM SET howtoplay subroutine
howtoplay:
load image "images/howtoplay.bmp",26
do
paste image 26,0,0
if spacekey()=1 then gosub options
loop
delete image 26
return
REM CREDITS SUBROUTINE
credits:
load image "images/credits.bmp",27
do
paste image 27,0,0
if spacekey()=1 then gosub options
loop
delete image 27
return
add_bullet_p1:
rem test for activity at current position
if p1b_active = 0
rem we can add a bullet
rem set to alive
p1b_active = 1
rem set correct direction (also is sprite number)
p1b_dir = currentimage
rem get x and y position
p1b_xpos = x + 25
p1b_ypos = y + 25
endif
return
add_bullet_p2:
rem test for activity at current position
if p2b_active = 0
rem we can add a bullet
rem set to alive
p2b_active = 1
rem set correct direction (also is sprite number)
p2b_dir = currentimage2 - 8
rem get x and y position
p2b_xpos = a + 25
p2b_ypos = b + 25
endif
return
update_bullets:
rem player one
if p1b_active = 1
rem simple directions
if p1b_dir = 1 then p1b_ypos = p1b_ypos - BULLET_SPEED
if p1b_dir = 3 then p1b_ypos = p1b_ypos + BULLET_SPEED
if p1b_dir = 2 then p1b_xpos = p1b_xpos + BULLET_SPEED
if p1b_dir = 4 then p1b_xpos = p1b_xpos - BULLET_SPEED
rem complex directions
if p1b_dir = 5
p1b_xpos = p1b_xpos - BULLET_SPEED
p1b_ypos = p1b_ypos - BULLET_SPEED
endif
if p1b_dir = 6
p1b_xpos = p1b_xpos + BULLET_SPEED
p1b_ypos = p1b_ypos + BULLET_SPEED
endif
if p1b_dir = 7
p1b_xpos = p1b_xpos + BULLET_SPEED
p1b_ypos = p1b_ypos - BULLET_SPEED
endif
if p1b_dir = 8
p1b_xpos = p1b_xpos - BULLET_SPEED
p1b_ypos = p1b_ypos + BULLET_SPEED
endif
rem check if x or y has left screen dimensions
if p1b_xpos > 640
p1b_active = 0
hide sprite 3
endif
if p1b_xpos < -50
p1b_active = 0
hide sprite 3
endif
if p1b_ypos > 480
p1b_active = 0
hide sprite 3
endif
if p1b_ypos < -50
p1b_active = 0
hide sprite 3
endif
endif
r em player two
if p2b_active = 1
rem simple directions
if p2b_dir = 1 then p2b_ypos = p2b_ypos - BULLET_SPEED
if p2b_dir = 3 then p2b_ypos = p2b_ypos + BULLET_SPEED
if p2b_dir = 2 then p2b_xpos = p2b_xpos + BULLET_SPEED
if p2b_dir = 4 then p2b_xpos = p2b_xpos - BULLET_SPEED
rem complex directions
if p2b_dir = 5
p2b_xpos = p2b_xpos - BULLET_SPEED
p2b_ypos = p2b_ypos - BULLET_SPEED
endif
if p2b_dir = 6
p2b_xpos = p2b_xpos + BULLET_SPEED
p2b_ypos = p2b_ypos + BULLET_SPEED
endif
if p2b_dir = 7
p2b_xpos = p2b_xpos + BULLET_SPEED
p2b_ypos = p2b_ypos - BULLET_SPEED
endif
if p2b_dir = 8
p2b_xpos = p2b_xpos - BULLET_SPEED
p2b_ypos = p2b_ypos + BULLET_SPEED
endif
rem check if x or y has left screen dimensions
if p2b_xpos > 640
p2b_active = 0
hide sprite 4
endif
if p2b_xpos < -50
p2b_active = 0
hide sprite 4
endif
if p2b_ypos > 480
p2b_active = 0
hide sprite 4
endif
if p2b_ypos < -50
p2b_active = 0
hide sprite 4
endif
endif
return
collide_bullets:
rem player two and p1 bullet
if p1b_active = 1
if sprite collision(2, 3) = 1
dec p1health, BULLET_POWER
hide sprite 3
p1b_active = 1
endif
endif
rem player one and p2 bullet
if p2b_active = 1
if sprite collision(1, 4) = 1
dec p2health, BULLET_POWER
hide sprite 4
p2b_active = 1
endif
endif
return
render_bullets:
rem player one
if p1b_active = 1
rem show sprite
sprite 3, p1b_xpos, p1b_ypos, 66
show sprite 3
endif
rem player two
if p2b_active = 1
rem show sprite
sprite 4, p2b_xpos, p2b_ypos, 66
show sprite 4
endif
return
initialise_bullets:
sprite 3, p1b_xpos, p1b_ypos, 66
hide sprite 3
sprite 4, p2b_xpos, p2b_ypos, 66
hide sprite 4
return
endgame:
rem setup screen
ink 0, 0
cls
rem hide all sprites
hide sprite 1
hide sprite 2
hide sprite 3
hide sprite 4
rem play movie
load music "music/spitfire1.wav",2
load animation "movies/dogfight.avi", 1
load image "images/wings.bmp", 99
if winner = 1
load image "images/player1win.bmp", 100
else
load image "images/player2win.bmp", 100
endif
stop music 1
play music 2
play animation 1, 0, 100, 640, 370
rem draw raf wings and player win image
paste image 99, 195, 0, 1
paste image 100, 120, 384, 1
wait 12000
stop animation 1
delete animation 1
delete image 99
delete image 100
goto start_of_game
return
Thanks