Module based game design question.
-
3DModelerMan
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Module based game design question.
I've been starting to setup a framework for my game. And now for switching between different levels and menu screens, I am trying to use this http://www.cprogramming.com/tutorial/gamedesign.html . But there is something that isn't covered in there that I wanted to ask. In the tutorial, it doesn't mention what the first module is set to. Should it be the first one in the module array that I stored?
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
I always use something similiar to that in my projects.
anyway the approach showed there says u don't have list or array of moduls. just one. the mainloop calls ExecuteModule every frame and the function either resturns itself or a instance to another Module incase u change the module. basicly:
anyway the approach showed there says u don't have list or array of moduls. just one. the mainloop calls ExecuteModule every frame and the function either resturns itself or a instance to another Module incase u change the module. basicly:
Code: Select all
struct Module
{
virtual ~Module(void)
{
}
virtual void Initialize()=0;
virtual Module* ExecuteModule(float timediff)=0;
virtual void Shutdown()=0;
};
struct MainMenu : Module
{
void Initialize()
{
printf("Loading images and meshes...\n");
printf("Adding scenenodes and gui elements(images), storing pointers to them...\n");
StartGame = false;
shutdown = false;
}
Module* ExecuteModule(float timediff)
{
if (StartGame) //well if game is startet...
{
//return instance to game module
}
else if (shutdown) //if u want to close the game
{
return NULL;
}
return this;
}
void Shutdown()
{
printf("Unload scenenodes and guielements from stored pointers..\n");
}
bool StartGame;
bool shutdown;
};
struct Spalshscreen : Module
{
void Initialize()
{
printf("Loading images and meshes...\n");
printf("Adding scenenodes and gui elements(images), storing pointers to them...\n");
counter = 0;
}
Module* ExecuteModule(float timediff)
{
counter+=timediff;
if (counter > 10.f) //after 10 seconds
{
return new MainMenu;
}
return this;
}
void Shutdown()
{
printf("Unload scenenodes and guielements from stored pointers..\n");
}
float counter;
};
int main(void)
{
Module* gamemod = new Spalshscreen();
gamemod->Initialize();
while (gamemod)
{
Module* oldMod = gamemod;
if ((gamemod=gamemod->ExecuteModule(0.01f))!=oldMod)
{
oldMod->Shutdown();
delete oldMod;
if (gamemod)
gamemod->Initialize();
}
}
return 0;
}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
3DModelerMan
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Thanks for the help, I'll do that.
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
-
3DModelerMan
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Okay. I implemented it and it's working so far. Thanks again. 
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar