Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Menu and Game Loop Structure

Author
Message
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 18th Aug 2006 23:59
I came into a problem the other day while I was writing a small prototype program as a test for a game I will be making. If you were to have a Menu, and have the ability to press "New Game", what would the structure of it look like? Would you have to do multiple loops? For Example, if you have to load images, and then load a level if the user presses "New Game"?

Would it be...

Load Images for Menu
DO
USER INTERACTION (If user clicks the sprite "NewGame" Gosub Load)
LOOP

Load: Load Level and materials
DO
USER INTERACTION (If user presses mouse, shoot gun)
LOOP

Jrock is pronouned Jay-Rock
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Aug 2006 00:09
Looks about right.


Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 19th Aug 2006 00:12
So having multiple loops doesn't suck up CPU Usage?

Jrock is pronouned Jay-Rock
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Aug 2006 00:21
I wouldn't think so... But repeat-until is good too! That way you can make a condition

Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 19th Aug 2006 00:23
Quote: "So having multiple loops doesn't suck up CPU Usage?"


Not if they aren't running at the same time

If you're menu code is completely separate from your gameplay code, its fine.

Searching for files named 'sanity'...
No files were found.
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 19th Aug 2006 00:25
So is there a way to cancel a loop? Would you use an Exit Command?

Jrock is pronouned Jay-Rock
Whisper Wind
21
Years of Service
User Offline
Joined: 5th Apr 2003
Location:
Posted: 19th Aug 2006 00:36
If you want to get out of a loop, an easy way would be to use the goto command, in conjunction with a label placed at the end of the loop.

Searching for files named 'sanity'...
No files were found.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Aug 2006 00:37 Edited at: 19th Aug 2006 00:55
Neve, Never, Never use GOTO it is bad coding practice!
Depsite which with Whisper Winds suggestion the code would still be in the loop and there will be errors down the line.

I would use a REPEAT ... UNTIL for the menu code, which will then exit back to your main loop when finished.

Here ... a small demonstration. Consider the rotating cube to be your main game and the rotating cylinder to be your menu. Access the menu by pressing the SpaceBar and exit by pressing Return:



Login to post a reply

Server time is: 2024-11-26 14:24:21
Your offset time is: 2024-11-26 14:24:21