Code design structure

BlitzMax Forums/BlitzMax Beginners Area/Code design structure

MarkSponge(Posted 2006) [#1]
What is the best practice when designing your code.

I have wrote a little game where things drop from the top and you have to catch them at the bottom. I did not think about adding a game menu when I started writing.

How do you structure your code?

Most games I've seen written in Blitzmax just use while not keyhit(KEY_ESCAPE) around the whole code.

How would I incorporate a game menu with the ability to pause a game, start a new one and exit (using the exit button, not pressing escape).

Anyone know any tutorials on menu creation and code structure.

Thanks in advance.

Mark


Grey Alien(Posted 2006) [#2]
My game framework has all that and more. Click the link in my sig, run the demo, it might give you some ideas... I like to get all this in place BEFORE writing the game so the game is just good fun then as all the "boring" stuff is done.

Anyway, your mainloop shouldn't really be based around the escape key (mostly that's just demos, code samples or mini-games). It should be something like While Loop=True Wend. Then in the while loop you can set Loop to False when the user clicks exit or presses escape or whatever. Pausing is easy, when P is pressed set a variable called Paused to True and make sure your logic code is contained in an If not Paused then ... End If structure. Menus take a bit more work...


MarkSponge(Posted 2006) [#3]
Ha ha , I was just looking at your framework 2 secs ago.

I'll look into it further.....

Mark


Grey Alien(Posted 2006) [#4]
cool. There's also plenty of people here who'll help you.


ImaginaryHuman(Posted 2006) [#5]
If you know what kind of structure your game will have, and drawing it on paper helps, then you can probably divide it up into parts with separate types for each part.


FlameDuck(Posted 2006) [#6]
What is the best practice when designing your code.
There are two prevailent methodologies. upfront design (Waterfall) and itterative prototyping (Agile). Each have their streangths and weaknesses.

How do you structure your code?
In such a way that it is readable and maintainable.

Most games I've seen written in Blitzmax just use while not keyhit(KEY_ESCAPE) around the whole code.
Yup. This is what's known as the main loop.

How would I incorporate a game menu with the ability to pause a game, start a new one and exit (using the exit button, not pressing escape).
You can do it procedurally with states and branching, or you can do it object orientedly with different objects representing what you want to do at any given time.


kronholm(Posted 2006) [#7]
I've only made one game but my structure is about this:

Everything in classes, and in seperate files, included in the main file, or included in their parents file.

Main loop contains this:

Delta time update
States (different states of the game, e.g. singleplayer, multiplayer, menu, login etc.) I just use a global variable called state and check it with a switch statement, and execute various functions such as startgame(), initeditor() etc.
Mouse update and of course flip and cls. That's it.