Jump to content

  • Log In with Google      Sign In   
  • Create Account

Game framework / Game state engine


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
5 replies to this topic

#1 MyNiceDisplayName   Members   -  Reputation: 135

Like
0Likes
Like

Posted 05 April 2014 - 01:14 AM

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!

 



Sponsor:

#2 ProtectedMode   Members   -  Reputation: 1287

Like
1Likes
Like

Posted 05 April 2014 - 03:56 AM

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.


Edited by ProtectedMode, 05 April 2014 - 03:57 AM.


#3 Ku134   Members   -  Reputation: 176

Like
1Likes
Like

Posted 05 April 2014 - 05:38 AM

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.



#4 MyNiceDisplayName   Members   -  Reputation: 135

Like
0Likes
Like

Posted 05 April 2014 - 08:45 AM

Ok, thank you very much!



#5 Glass_Knife   Moderators   -  Reputation: 5056

Like
1Likes
Like

Posted 05 April 2014 - 09:26 AM

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


Edited by Glass_Knife, 05 April 2014 - 09:27 AM.

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

#6 MyNiceDisplayName   Members   -  Reputation: 135

Like
0Likes
Like

Posted 05 April 2014 - 10:53 AM

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






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