Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Structure of a game framework?


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 sterry   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 April 2012 - 09:55 AM

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.

Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2642

Like
1Likes
Like

Posted 06 April 2012 - 10:03 AM

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.

o3o


#3 Neglected   Members   -  Reputation: 111

Like
1Likes
Like

Posted 06 April 2012 - 11:03 AM

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




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