I have been stuck on this for 3 days now so im finally going to ask.
What I am trying to do is end my game, Show the score, and back to menu.
Here is what I am trying to do.
Menu -> LoadGame -> gameloop ---- GameOver -> ShowScore and back to menu.
I have tried using gosubs and functions. I am just having trouble understanding how to call them / use properly.
So what I have tried is.
Menu = 0
GameOver = 0
LoadGame = 0
do
If Menu = 0 Then GameMenu()
sync()
loop
Function GameMenu()
Print ( " Touch Screen to Play " )
If GetPointerPressed () = 1
Menu = Menu + 1
LoadGame()
endif
Endfunction
Function LoadGame()
///////////////////////////////////////
Load all your static objects
///////////////////////////////////////
---------------------------------------
//Run your loop
do
If GetSpriteCollision ( 1, 2 ) = 1
GameOver = GameOver + 1
endif
If GameOver > 1
Menu = 0
GameOver()
endif
sync()
loop()
endfunction
Function GameOver()
Print ( Score )
Print ( " Game Over " )
endfunction
I have never seen an example with 2 loops but this is the only way I know as of now to load the static objects after menu().
I don't think Im anywhere close to being right on how to do this.\
When this runs it goes to menu and once you click it starts LoadGame() as soon as you die it goes back to menu but does not display menu images only the text with LoadGame() Still running. And once you click it starts LoadGame() all over but does not delete the existing game. Its running 2 games on top of each other it seems like. the old sprites are static no longer moving and just stuck on screen.
I have bought Daniels eBook and spent the whole day reading about gosubs and functions it only explained the very basics and its hard to find his examples of menu on my small kindle.
If anyone could shed some light on this matter I would much appreciate it.
It has had me stumped for a few days now
Some More code...This is an old project im using it as an example of whats happening.
// Project: Wills World
// Created: 2015-02-10
// set window properties
SetWindowTitle( "Wills World" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
//Load Images
Loadimage ( 1, "Ground.jpg" )
LoadImage ( 2, "Player.jpg" )
LoadImage ( 3, "Rock.jpg" )
LoadImage ( 4, "sky.jpg" )
// score
score = 0
menu = 0
gameover = 0
death = 0
do
If Menu = 0 then GameMenu()
sync()
loop
Function GameMenu()
Print ( "Click THE SCREEN TO START GAME" )
If GetPointerPressed() = 1
Menu = Menu + 1
LoadGame()
endif
endfunction
Function LoadGame()
//make background
CreateSprite ( 4, 4 )
FixSpriteToScreen ( 4, 2 )
SetSpriteSize ( 4, 1024, 768 )
// floor sprites
for f = 1 to 1000
i = CreateSprite ( 1 )
SetSpritePosition ( i, f * 100, 600 )
SetSpritePhysicsOn ( i, 1 )
next f
global dim Object[200] // Create an array with 200 slots
//blocks to jump over
for i = 1 to 200
Object[i] = CreateSprite ( 1 ) // Create a sprite for each array slot
SetSpritePosition ( Object[i], i * 500, 500 )
SetSpritePhysicsOn ( Object[i], 1 )
next i
//Player
CreateSprite ( 2, 2 )
Setspriteposition ( 2, 120, 525 )
SetSpritePhysicsOn ( 2, 2 )
setspriteshape (2, 2)
do
Print ( "Touch the screen to jump over Objects" )
Print ( "Score" ) : Print ( Score )
SetViewOffset ( GetSpriteX ( 2 ) - 150, 0 )
if ( GetPointerPressed ( ) = 1 )
Jump = 1
endif
If (GetPointerPressed ( ) = 0 )
Jump = 0
endif
If Jump = 1
score = score +5
// find the input location
x# = getspritex(2)
y# = getspritey (2)
SetSpritePosition ( 2, x#, y#-200 )
endif
If Jump = 0
x# = getspritex(2)
y# = getspritey (2)
Setspriteposition ( 2, x#+8, y#+3.8 )
setspriteangle ( 2, 0 )
endif
for i = 1 TO 200
If GetSpriteCollision ( Object[i], 2 ) =1
Death = Death + 1
endif
next i
If Death > 1
Print ( " Game Over " )
Sleep ( 100 )
Menu = 0
endif
Sync()
loop
Endfunction
Edit: Im not asking you to rewrite this code. Just a simple explanation would be fine.