Game framework / Game state engine

Started by
4 comments, last by MyNiceDisplayName 10 years ago

I want to try make an RPG game(in Java), and have encountered some questions regarding the framework of the game. I have very little experience with game framework, and the only tutorials I've found on this don't seem to work well for a largert RPG.

The post ended up being quite long, so if you don't feel like reading all of it I'd be grateful if you could share some links if you know about any good tutorials on this!

Since there is going to be a lot of code I suppose I will need to create separate classes for the different "game states", such as Main Menu, World Map, Local Map, Start Screen, etc. To handle these different states of the game, I decided that I will make a "game state" class (or "framework" class if you want) which has a variable "GameState(enum)" and. Furthermore, I do not want to create a new screen to draw on for each of these classes, so I should also create a separate class for the screen.

My question is: How do I go about putting all this together?

The first thing that came to mind was to start the actual game in the "game state" class. The Screen class extends JFrame, and classes that will draw on the screen extend Canvas. If the game state changes from "Loading" to "Main Menu", the "game state" class says something like "Screen.add(MainMenu)", so that everything drawn in the Main Menu class will be showed on the Screen. The "game state" class will be the core of the game, and can controll all the different classes. Does this sound like a good idea? If the player leaves the "local map" and needs to enter "world map", somehow I need to tell the State Engine to change the state. Should I simply declare an instance of "StateEngine" in the local map class, so that the local map class has access to its state engine? (and let the state engine class set it to "LocalMap.StateEngine = this"?)

I'm very sorry if my questions seem confusing. I am quite confused about this, so any suggestions for a good game framework are more than welcome!

Advertisement

Welcome to the forums!

I don't know Java well if it's about games but what you are describing is a FSM (Finite State Machine). There are plenty of resources on the internet that show how to program one, even though a FSM can be used for many different things. I would usually create a base interface/class with methods like update(), draw() and such. Then you could make a StateManager class that keeps the current state loaded and also has the methods update() and draw() but only calls these methods on the state itself. The rest of your ideas are quite good. An enum is a good possibility.

Should I simply declare an instance of "StateEngine" in the local map class, so that the local map class has access to its state engine? (and let the state engine class set it to "LocalMap.StateEngine = this"?)

You could always make a static field inside the StateEngine class that governs the state, this would allow you to access the game's state without having to create multiple instances of StateEngine.

Ok, thank you very much!

Also, here's a good tutorial to get you started:

http://www.cokeandcode.com/main/tutorials/space-invaders-101/

Also, check out the source code for 2D game programming with Java (shameless plug for my book)

http://www.indiegameprogramming.com/BookInformation.php

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

Thank you!
I got some ideas from watching this tutorial.
The book seems very interesting too.

This topic is closed to new replies.

Advertisement