2

I'm new to stackover and this is my first ever post, so please be gentle :-)

I'm in the middle of developing a multi-level shooting game, and I'm questioning the best OOP design for my purposes, explicitly to manage the bullets.

Generally the game has multiple players and multiple enemies, each of which has a gun which fires bullets. There are bullet classes which manage multiple bullets well, their position, animation, rendering, etc, and these work fine.

My question is, am I better off instantiating an instance of these bullet classes per enemy, or am I better off instantiating one instance for the level which manages all bullets (irrespective of who fired it)?

The benefits of a single instance is that the bullet management and rendering can be optimised for them all at once, however they need additional state information so we remember which bullets belongs to who, how many bullets can exist for each enemy, etc, and it isn't as loosely coupled. The benefit of a separate instance per enemy is that it's neater and less state information needs to be stored per bullet, however they would be managed and rendered on separate calls for each enemy or player. Inter-bullet collisions would also prove more difficult, but luckily this isn't a requirement of this particular game.

Has anyone else written anything similar and how did you structure it? Which factors should I consider before deciding, and are there any game design principles for this?

Regards Nick

Bart van Ingen Schenau
  • 15,488
  • 4
  • 32
  • 41
NickZ
  • 21
  • 1

1 Answers1

0

For general Game-structures you may want to read this.


It may be my personal insight but, I think a level-wide handler for the bullets should be more universal. When a player shoots a bullet, it sends a signal to the Bullet-handler object, and decreases the bullet-count by one. The bullet would have to store which player shot it, so you can look back which player shot which player, or increase stats. Not to mention a level-wide bullet handler could be extended later to handle grenades, mines, exploding gunpowder-filled rabid weasels or whatnot.

Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46
  • That's a really useful link. I think I agree with you. A level-wide bullet handler (and other handlers for that matter) tend to be more scalable, and looks like it's the way to go. Thanks. – NickZ Jan 05 '13 at 13:35
  • awesome! Glad to be of help:) I was in a similar situation in a game prototype with lasers. I decided to build a laser-beam and a laser-handler class. Turned out to be just fine! ^^ – Dávid Tóth Jan 05 '13 at 15:06