Advertisement

an idea for a game design...

Started by August 11, 2000 03:18 AM
2 comments, last by Moe 24 years, 4 months ago
I have the basic idea of how to make a game down pat. So far I have my program broken into 3 parts: the init function, the main loop, and the cleanup function. I had an idea. Why not have a variable for keeping track of the state of the main game loop? Lets suppose Game_State is an average integer which represents the game state (duh!). In the main game loop you would check the game state variable to see what would be needed to be done. For example, if the game state was 0, then the function for rendering and processing the ''main menu'' would be called. If the game state was 1, then the function for the ''new game menu'' would be called. Do you see what I mean? I have tried to impliment this, but to no avail. Here is a code snippet from my main game loop: int Game_Main(void *parms) { //temporarily set the game state Game_State = 0; //check the game state if (Game_State = 0) Main_Menu(); //call the main menu function which displays the main menu lpddsprimary->Flip(0,DDFLIP_WAIT); // return success return(1); } // end Game_Main For some odd reason, nothing appears (and i am sure that my Main_Menu function works fine). Any ideas of what is causing this? Shrapnel Games
Hi,

Your "idea" resembles a technique called FSM (finite state automatons), which checks states and changes them according to some rules, (in short).

Well, concerning your problem, while just skimming through your code I saw the scapegoat, I think.
change this:
                if (Game_State = 0)[/source]to this:[source]if (Game_State == 0)    


the former is an initialisation and the latter a comparison.
The former will set gamestate to 0 and then checks if it's true, which it never will!!!

That will certainly solve the problem.


/Mankind gave birth to God.

Edited by - DDnewbie on August 11, 2000 5:19:36 AM

Edited by - DDnewbie on August 11, 2000 5:20:15 AM

Edited by - DDnewbie on August 11, 2000 5:20:50 AM

Edited by - DDnewbie on August 11, 2000 5:21:42 AM
/Mankind gave birth to God.
Advertisement
Alternately, you could use a switch statement which branches off into other functions. Like:

switch (game_state)
{
case 0:
//etc...
case 1:
//etc..
}

You could also add some defines at the top of your program like:

#define GAME_STATE_MENU 0
#define GAME_STATE_GAME 1

And then check against these (makes the code more readable later on..)

Good luck.




- Daniel
VG Games
- DanielMy homepage
Yeah, thnaks! I always knew that double equals sign would come back and bite me in the butt some time! I will get around to putting more states in my game, but for the mean time, I am just going to get things working. ...and i believe FSM it finite state machine, rather than automation.

Shrapnel Games

This topic is closed to new replies.

Advertisement