Archived

This topic is now archived and is closed to further replies.

Xeee

a problem in game design, i think.....

Recommended Posts

hi there, i''m currently working on a small game, it''s not my first one, but it''s the first time for me to run into such problem let''s suppose the following design //gameloop while (1) { drawscene(); updatescene(); takeinput(); } void drawscene() { level.draw(); drawobjects(); } void takeinput() { if (up pressed) object.move(UP); if (down pressed) object.move(DOWN); } i think that nothing''s wrong with the above code, but how to make a external menu(before begining the game) and another one inside the game, and also a gameover screen using the above design? one solution i thought about is a switch case inside each of drawscene(), updatescene() and takeinput() containing as many cases as there is states in the game, for the above problem we have 4 states/cases for the above example which are (EXTERNAL_MENU, INGAME, INGAME_MENU, GAMEOVER), but i think this solution is processor expensive. another solution i thought about is the same as the above but with function pointers (there''ll b draw_ingame(), draw_external_menu(), draw_ingame_menu() and draw_gameover()) and drawscene() will b a funtion pointer pointing initially at draw_external_menu(), and everytime i move on from a state to another i''ll adjust drawscene() to point at the draw function for the next state tell me am i wrong or right, or this is absolute shit and there is another perfect solution i don''t know thanks for ur help. xee..

Share this post


Link to post
Share on other sites
Well, when you draw the in game menu it would be drawn when you draw the level. So you have to find a way to display the menu along with the level. As far as an external menu, that would be its own seperate thing. It would be called when you initialize the game I guess. The gameover menu would be it''s own seperate thing and go inside the game logic and display itself if certain conditions were met.

Share this post


Link to post
Share on other sites
You should "stop" the time when menu is active and render the menu. Something like that:

if(isMenuActive)
RenderMenu();
GetMouseActivityOverMenu();
else
GetUserInput();
UpdateScene(deltaTime);
RenderScene();


I hope it helps :D

Share this post


Link to post
Share on other sites
You could encapsulate the menu into a class and have it run a while loop within it that keeps the game at the menu then when it exits it would drop into the games while. The solution you suggested with the states I believe would be a reasonable solution aswell. Or maybe even encapsulate your whole game into a class and place the menu code within the gameInit function. There are many ways to accomplish the task you are doing. There is no defined way to do it atleast none that I know of, thats the great part about game programming, There is no book that says "you have to do it this way or its not a game" so do whatever works as long as you have fun and your game is fun..and effecient..hehe.Hope this helps. I also have some code you can look at that they gave me at school on how to solve the problem you described if you would like to see it e-mail me at rebelcoder2@hotmail.com.

enhanced code on contact

Share this post


Link to post
Share on other sites
A statemanager would be a good idea..

Something like:

statemanager.addfunc(''some pointer'')

statemanager.process where the topmost function is processed. With such a designe you can add functions everywhere in your programm. If you want the menu to be renderd you just push the menu op the stack and the next process will render it. I find it a pretty well working solution

Share this post


Link to post
Share on other sites
what tiutiu said is the same as a switch case, it''s just replacing the switch with if else construct, and replacing the value to b tested in the switch with a bool for every state. but thanks for help.

Scheermesje: i got ya, but please explain in more details so that i can figure the whole thing out

xee..

Share this post


Link to post
Share on other sites