Original Post
🔒 Locked
easy question
Advertisement
I kinda like to use function pointers. Figure out when the the state of your game changes and then just assing the function ptr. That does get a bit tricky sometimes. There's an article somewhere on this site about creating multiple threads for you game. You might want to consider that also.
EDIT: typo
Edited by - Abstraction on December 3, 2001 2:36:23 PM
EDIT: typo
Edited by - Abstraction on December 3, 2001 2:36:23 PM
I agree with the Abstraction that function pointers combined with a state machine give an efficient and tight game loop. An simple example is given below. In each state all you need to do is figure out what state you need to be in next time round the game loop and change (or not as the case may be) the DoState function pointer as approptiate.
henry
//main program
void main(void)
{
InitGfx(); //Initialise PSX graphics
InitPads(); //Initialise the controller pads
FntID = LoadFont(); //Load debug fonts into VRAM
LoadGFX(); //Load game graphics into VRAM
GameState = RUNNING; //set the initial game state
DoState = Intro; //set the initial DoState pointer
do //game loop
{
GetUserInput(); //Get input from controllers
DoState(); //Execute game state function
}while(GameState != FINISH);
ResetGraph(3);
}
henry
//main program
void main(void)
{
InitGfx(); //Initialise PSX graphics
InitPads(); //Initialise the controller pads
FntID = LoadFont(); //Load debug fonts into VRAM
LoadGFX(); //Load game graphics into VRAM
GameState = RUNNING; //set the initial game state
DoState = Intro; //set the initial DoState pointer
do //game loop
{
GetUserInput(); //Get input from controllers
DoState(); //Execute game state function
}while(GameState != FINISH);
ResetGraph(3);
}
G''day!
I define an interface called IGameState and then subclass it for the various game states that I need. Basically an OOP spin on the function pointer method. I used it in my Doodle Invaders tutorial on my site. Full source, if you''re interested.
Stay Casual,
Ken
Drunken Hyena
I define an interface called IGameState and then subclass it for the various game states that I need. Basically an OOP spin on the function pointer method. I used it in my Doodle Invaders tutorial on my site. Full source, if you''re interested.
Stay Casual,
Ken
Drunke
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement