Menu system

Hi

What's the best way of dealing with game states?

I'm leaning on having a system like this:

gameLoop(){

while(true){

if (gameState == GameState.INGAME){

updateGameObjects();

drawGame();

}

elseif (gameState == GameState.MENU){

drawMenu();

}

}

keyPressed(){

if (gameState == GameState.INGAME){

If uparrow is pressed move player up

}

elseif (gameState == GameState.MENU){

If uparrow is pressed select menu item above

}

}

Or what do you think is the best way? Maybe having a launcher window instead of ingame menus?

Looking forward to see lots of opinios here.

[1386 byte] By [namnet] at [2007-9-30 11:51:25]
# 1
All the keypressed/released events should do is set/clear flags.There is no need for any form of logic in there at all.
Abuse at 2007-7-4 13:41:13 > top of Java-index,Other Topics,Java Game Development...
# 2
Hrm... Didn't see this thread: http://forum.java.sun.com/thread.jsp?forum=406&thread=521772&tstart=0&trange=15
namnet at 2007-7-4 13:41:13 > top of Java-index,Other Topics,Java Game Development...
# 3
As for the issue of handling gamestate, that solution is perfectly adequate. (though you might consider using a switch, rather than dozens of 'if's
Abuse at 2007-7-4 13:41:13 > top of Java-index,Other Topics,Java Game Development...
# 4
**** Abuse you'r fast! :)Yeah I know they should only set flags, my question was more like how you should approach this. Having a launcher window or a lot of if/else in the game loop....
namnet at 2007-7-4 13:41:13 > top of Java-index,Other Topics,Java Game Development...
# 5
Yeah, this is like chatting... Thanks :)
namnet at 2007-7-4 13:41:13 > top of Java-index,Other Topics,Java Game Development...
# 6
I have used something very similar to what you describe for a long period of time now, and actually have a class called GameState with respective constants =p The system works quite successfully for me, so as abuse has said, it should be perfectly adequate.
Seekely at 2007-7-4 13:41:13 > top of Java-index,Other Topics,Java Game Development...