Game Object Design

Posted by oisin on Game Development See other posts from Game Development or by oisin
Published on 2011-04-26T04:00:10Z Indexed on 2012/04/05 17:46 UTC
Read the original article Hit count: 123

Filed under:
|

I'm having a problem with the way I designed my first simple game in C++.

I have GameObject (abstract class) and ObjectA which inherits the update() and draw() methods from GameObject.

My main loop contains a linked list of GameObject*, and while that list is not empty it cycles through it, calling update on each one.

Up until this point, I thought the design was standard(?) and would work.

However, when I call update on ObjectA() I run into two problems:

  • ObjectA can die which messes up the list, which in turn throws off the loop in main.
  • ObjectA can spawn more ObjectA's but these are local scope and the update() goes out of scope, creating problems in main's list of GameObjects.

I think my design if alright, but I'm having such problems with segmentation faults that there must be something seriously wrong with at least one part of my implementation. If anyone could point out any serious mistakes or simple examples of this being done (or even alternative designs) then I would greatly appreciate it!

© Game Development or respective owner

Related posts about c++

Related posts about objects