Skip to main content
GameDev.net gamedev.net
🔒 Locked

Object Managment

Started by steveharper Jan 24, 2006 at 8:04 PM 2 replies 700+ views
Original Post
steveharper
steveharper
Hi i have been developing a 2D space shooter in OpenGL. And have run into a design problem. I have a CShip class for the players space ship, and i can't see how to track a projectile within the class, rather than in the main game loop. There must be a simple way to update multiple projectiles fired by one instance of a ship in a neat efficiant way. Thanks, Steve
Ravuya
Ravuya
I'd set it up so projectiles are managed by a central projectile manager, rather than by the individual ships.

Imagine if ship Q shot, and then was deleted (presumably from you blowing it up). What happens? The shot disappears.

I'd figure it's also much cleaner code to update "all" the shots and ship collisions in one take from a giant pool than it is to iterate through each ship, handle its shots, pass in all the ships the bullet might collide with, and then see if there were any collisions.
Shamino
Shamino
Yesss, projectile manager...

Basically a resource_manager that manages temporary caches of projectile objects, such as rockets, laser beams, bullets, etc...

The objects themselves, such as CShip, might make the request to the resource_manager to handle his bullet or laser beam, but he doesn't do it himself, otherwise the previous would happen, what the other poster mentioned...

You shoot a rocket, you die, rocket goes away, no good!
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
furiousuk
furiousuk
If you're worried about keeping track of who fired which projectile (for score update or whatever) then simply have eadch CProjectile object contain a pointer back to their CShip parent.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.