Hey! I added some code in my game for a menu, doesn't really work. How would I make it so that when my game starts and image appears and if I click Play it plays and if I click Exit, it exits?
Heres my code:
`Main Source File
`Getting Game Ready
SYNC ON
SYNC RATE 30
HIDE MOUSE
`Loading Images.
load image "Images\YourShip.jpg",1
load image "Images\AlienShip.jpg",6
load image "Images\GreenLaser.jpg",4
load image "Images\RedLaser.jpg",5
load image "Images\Stars.jpg",50
`Loading Sounds.
load sound "Sounds\Cannon.wav",1
load sound "Sounds\bpulse.wav",2
`Loop Background Music
loop sound 2
`Menu
main_menu:
`load menu image
load image "Images\Title.jpg",1000
set text size 12
blue=RGB(0,128,255)
white=RGB(255,255,255)
selectedItem=1
do
cls
paste image 1000,0,300
sync
loop
return
`Make Background
MAKE OBJECT PLAIN 4,127,90
POSITION OBJECT 4,0,-4,80
TEXTURE OBJECT 4,50
LOCK OBJECT ON 4
`Color background black
color backdrop rgb(0,0,0)
`Playerfire Score Level and Lives Variables
pf=0:score=0:Level=1:lives=3
`Your Ship X and Y coords
ysx=265:ysy=350
`Places your ship on Screen
sprite 1,ysx,ysy,1
`Enemy Ship X and Y coords
esx=265:esy=90
`Places Enemy ship on Screen
sprite 6,esx,esy,6
`Where lazer shoots from
lx=ysx+23
ly=ysy-60
`set variable for enemy ai
`set nme direction to random 0 or 1
`set amount of time to delay before nme fires with a 500ms min.
nme_fire_delay# = timer()+500+rnd(1500)
nme_left = rnd(1)
screen_wide = screen width()
nme_wide = sprite width(6)
`set enemy bounds
right_bound = (screen_wide-nme_wide)-10
left_bound = 10
`set number of lives
lives = 10
`Start Main Loop
do
`Print Score Level and Lives on screen
set cursor 10,10: Print "SCORE:";Score; " LEVEL:";level;" LIVES:";lives
`get the current timer value always use this variable in the place of the timer() command
`never call the timer() command more than once per loop it doesn't have to be that accurate.
update_time# = timer()
`setup nme firing timer delay
if update_time# > nme_fire_delay#
`update fire delay timer
nme_fire_delay# = update_time#+500+rnd(1500)
if nme_f = 0
`update nme_lazer positions
nme_lx = esx+23
nme_ly = esy+60
nme_f = 1
gosub nme_shoot
endif
endif
`enemy simple ai
`you used the variable esx for the nme's x position so just change it a bit
`for side to side motion.
if nme_left = 1
dec esx, 5
`if too far left go right
if esx < left_bound
esx = left_bound
`set to go right
nme_left = 0
endif
else
inc esx, 5
`if too far right go left
if esx > right_bound
esx = right_bound
`set to go left
nme_left = 1
endif
endif
`update sprite position
sprite 6,esx,esy,6
`Left Key Control
if leftKEY()=1 and ysx>20
dec ysx,10
endif
`Right Key Control
if rightKEY()=1 and ysx<545
inc ysx,10
endif
`Start Shoot Routine
if inkey$()="z"
if pf=0
if zkp=0
lx=ysx+23
ly=ysy-60
zkp = 1
gosub shoot
pf=1
endif
endif
else
zkp = 0
endif
`If Alien Ship Exists, activate blowitup routine.
if SPRITE EXIST(2)=1
if SPRITE HIT(2,6)=1
gosub blowitup
endif
endif
`If Your Ship Exists, decrease your lives.
if SPRITE EXIST(1)=1
if SPRITE HIT(1,7)=1
delete sprite 7
nme_f = 0
lives = lives - 1
if lives = 0
end
endif
endif
endif
`Refresh Your Ship Position
sprite 1,ysx,ysy,1
`Activate Moveall Routine
gosub moveall
`Activate Movestars Routine
gosub movestars
`Refresh Screen
sync
`End of Loop
loop
`Movestars Routine
movestars:
SCROLL OBJECT TEXTURE 4,0.00,-0.01
return
`Shoot Routine
shoot:
sprite 2,lx,ly,4
`show the bullet as it was hidden when hitting the enemy
show sprite 2
PLAY SOUND 1
return
`Shoot Routine
nme_shoot:
sprite 7,nme_lx,nme_ly,5
`show the bullet as it was hidden when hitting the enemy
show sprite 7
PLAY SOUND 1
return
`Moveall Routine
moveall:
if pf = 1
if SPRITE EXIST(2)=1
If sprite y(2)>-200
ly=ly-40
sprite 2,lx,ly,4
else
pf=0
`hide bullet if it goes too far
delete sprite 2
endif
else
pf=0
endif
endif
`move nme bullet
if nme_f = 1
if SPRITE EXIST(7)=1
If sprite y(7)<800
nme_ly=nme_ly+30
sprite 7,nme_lx,nme_ly,5
else
nme_f = 0
`hide bullet if it goes too far
delete sprite 7
endif
else
nme_f = 0
endif
endif
return
`Blow it Up routine
blowitup:
delete sprite 6
`remove bullet when hit nme ship
delete sprite 2
for t=10 to 20
`changed the sprite positions to variable names for easier to keep up with
sprite 6,esx,esy,t
wait 1
next t
`changed this to score = score + 50 DBP doesn't add to variables auto like that
Score = Score+50
`added to make new random location for enemy ship you can also add a esy = rnd(whatever) to make it random the other way
esx = rnd(screen width()-sprite width(6))
delete sprite 6
sprite 6,esx,esy,6
`reset nme direction randomly
nme_left = rnd(1)
return
-If Practice makes Perfect, and nobody is perfect, why practice?-