Jump to content
  • Advertisement
Sign in to follow this  
Cosmic R

Structuring and organising classes

This topic is 1486 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

Hi all, I've been a long time lurker for a few years after a long break from the site.


I'm still a beginner, but am really pushing to get a few games under my belt.


Anyway, I've set up a basic game design like this:


Game class Singleton

Game State Class  (for playing/paused etc)

 - handle input

 - draw

 - update


Sprite Class


Game Object Class

 - list of sprites for animation

 - virtual handle input (calls state->handle_input)

 - virtual update (calls state->update)

 - virtual draw (calls state->draw)


 - Monster Class (derived from GameObject)

 - Player Class (derived from GameObject)


State Class

 - virtual handle_input

 - virtual update

 - virtual draw

MonsterState Class (derived from State)

PlayerState Class (derived from State)


Object Manager Class

 - manages a list of game objects of a type eg ObjectManager<Monster> monster_manager;

 - calling monster_manager.update() runs the update command on all the monster objects etc


Okay, so now that's out of the way, my problem is how do I get my objects talking to the manager? I want my player object for example to be able to tell the manager to create bullet objects.


But it seems the way I've designed it all only allows for messages to be sent downwards, not upwards. I tried including the calling objectmanager on each update call, but because the objectmanager is templated it didn't work.


I thought of creating a global messaging system, where a list of message objects is kept and every loop they are executed, but that's just moving the problem around, not really changing the structure (ie the message class would need access to the ObjectManager)


Am I going about this the wrong way?


Are there any good examples of basic games (but not Pong) that allow for expansion? Maybe something like object oriented space invaders?

Share this post

Link to post
Share on other sites

thanks for the great reply.  I have taken into account your suggestions. My biggest problems as you noted appear to be numbers 2, 3 and 5. Basically my game should know when the player has fired etc, not have the player class tell it. I was delegating too much down the chain. All my state classes should do is update the object it's attached to.


As far as my sprites go, yeah I need to re-write it - at the moment it works, but not how it should so I'm aware of that one...


And with no 1, the singleton, if I shouldn't use it then how do I instantiate the game? A static class?

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!