Jump to content

  • Log In with Google      Sign In   
  • Create Account


How should I implement a state based game?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 nkarasch   Members   -  Reputation: 171

Like
1Likes
Like

Posted 01 November 2012 - 10:00 PM

I would like to handle game states the way Slick does, without using Slick. I think that is the best solution.

I would want a state for the main menu, options screen, each level, game over and the ending.

I'm pretty new to developing games. I currently only have one "level" and I'm accessing it like this

public class StateHub {
public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.add(new LevelOne());
  frame.setVisible(true);
  frame.setSize(800, 600);
  frame.setResizable(false);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

For my last game I had a huge series of booleans changing what was drawn to the panel, it got unmanageable fast. Just trying to clean things up. Is there a simple way to turn this into a state-like system where I could do something like destroy the instance of LevelOne and add LevelTwo instead? Is there an easier solution?

Thanks a ton.

Sponsor:

#2 ultramailman   Prime Members   -  Reputation: 1561

Like
1Likes
Like

Posted 02 November 2012 - 12:43 AM

Hello
How about a finite state machine (FSM)? Each machine can have some states defined by you, and each state will have an action to perform.

You want to have "main menu, options screen, each level, game over and the ending", so you can use multiple state machines. So I would have 2 state machines:

screen machine - have the following states: main menu state, options state, game over state, ending state, gameplay state
gameplay machine - this is a state machine inside a state machine, only active when screen machine is in gameplay state. this will have level1 state, level2 state, ...

What do you think of that? ;o

#3 nkarasch   Members   -  Reputation: 171

Like
0Likes
Like

Posted 02 November 2012 - 02:04 AM

Very cool, I tried reading about it on google before I even posted here but I wasn't entirely sure that was what I wanted. The machine term threw me off. I'll work on it some more now, thank you.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS