Sign in to follow this  

Structuring and organising classes

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

This topic is 1272 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this