Jump to content
  • Advertisement
Sign in to follow this  
sterry

Structure of a game framework?

This topic is 2299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

I wanted to ask if there are any good ressources on how to structure a basic game framework.

I am not completely new to game programming, but all my games tend to have the same "ugly" structure, i.e:

-Player Class (which holds the attributes for the player, i.e. health, movementspeed, position,...)
-Enemy Class (almost the same as player, only with some sort of an AI)
-Game Class (extended from a jpanel, has an instance of player and a collection of enemies, handles input, drawing, looping, etc.)

My problem here is, that the "Game" class becomes bloated rather fast and with that it gets more and more difficult to add things to it.

So, are there any ressources you can recommend to look at, for a decent game framework structure?
Or can you give me some hints and tips on how to structure my games better? How to separate Input from Drawing and everything else?

PS: I doesn't need to be specifically for Java, I would appreciate it though.

Share this post


Link to post
Share on other sites
Advertisement
Put stuff in classes and functions if you use it more than once.

A class should only handle 1 thing and you should try to keep dependencies between classes at minimum. If 2 classes need same functionality make a class with that functionality and make the 2 classes inherit from that.

Share this post


Link to post
Share on other sites

Hey,

I wanted to ask if there are any good ressources on how to structure a basic game framework.

I am not completely new to game programming, but all my games tend to have the same "ugly" structure, i.e:

-Player Class (which holds the attributes for the player, i.e. health, movementspeed, position,...)
-Enemy Class (almost the same as player, only with some sort of an AI)
-Game Class (extended from a jpanel, has an instance of player and a collection of enemies, handles input, drawing, looping, etc.)

My problem here is, that the "Game" class becomes bloated rather fast and with that it gets more and more difficult to add things to it.

So, are there any ressources you can recommend to look at, for a decent game framework structure?
Or can you give me some hints and tips on how to structure my games better? How to separate Input from Drawing and everything else?

PS: I doesn't need to be specifically for Java, I would appreciate it though.

First of all you should use inheritance. Your Enemy and Player classes should extend from a common [abstract] class, seeing as how they are so similar. You could call this "Entity" or "Object". You could create interfaces to support the AI which individual extensions of the class (ie, WolfEnemy) could inherit and edit to their liking.

As for keeping the input/logic and display seperate, you're going to want to use threads and java's concurrency packages. You could use a CyclicBarrier to signal the display thread to start rendering, and then reset it when you're done rendering so the input/logic thread can Sleep and then run a new iteration. Display and Logic/Input are generally handled on seperate threads in bigger games, *however* if you are doing something simple like Pong, or something that doesn't have very intensive math calculations, you could just stick Display and Logic/input on the same thread to simplify things (do *not* do this in a team setting) while you get the hang of things.

A few things for you to look at:
http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
http://en.wikipedia.org/wiki/Object-oriented_programming

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!