Jump to content
  • Advertisement
Sign in to follow this  
Quantumstring

Code design question of a simple game

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

Hello! Currently I am working on a very simple space shooter and the very first version is going to be like "Asteroids". In my initial code design game objects are represented by a simple class with the following (partly shown) interface GameObject // Game messages +OnGameTick +OnPrepare // Called once, when the Object is put into the scene +OnCollide(GameObject*) +OnDestroy +getID . . . All of the methods (except getID) are overridables that can be customized in concrete implementations (i.e. Playership, Enemy, Asteroid, Missle and so ). I also implemented a very simple game class that holds all the game objects, renders them and calls the overridables declared above. While specific behavoir can be customized in the concrete Game Object implementations, problems arise when multiple Game Objects have to be involved in an event. For example, if a missile explodes not only the object to be hit by the missile should be informed (via a collission call) but also all other objects nearby the explosion. However, in this case either the missile itself has to check the area for other objects and call the collide method (or something like OnDamage(Gobject*) ) or the Game class itself has to do this. I personally don't like the first approach because I'd like to keep the Objects independend. However, coding the behaviour of a missile explosion in the Game Object is far from appropriate either because of the loss of dynamic behaviour. Another problem arises when an astroid gets destroyed and is to be split up into several smaller astroids (which logically would be game objects themselves). Because game objects are maintaned in the game class the Astroid object would have to create smaller asteroids and attach them to the Game class, requiring awareness of the Game class of course (which also doesn't appeal to me). My goal is to keep the game logic as flexible as possible in OOP ways but I just can't think of a good solution. Maybe you can help me out with some ideas? Thanks in advance, Quantumstring

Share this post


Link to post
Share on other sites
Advertisement
Quote:

Because game objects are maintaned in the game class the Astroid object would have to create smaller asteroids and attach them to the Game class, requiring awareness of the Game class of course (which also doesn't appeal to me).


I think game objects should know about the game class because technically the asteroids would have to know about the world they are in. This "world" would be the game 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!