Quote:Original post by starrulerQuote:Original post by Ravyne
The Splitbullet class wouldn't be responsible for tracking the three bullets, it would simply spawn the additional bullets at it's current location.
If the 3 bullets "fan out" eg: one breaks left, one right, and one stays on course, then you might just want to spawn the left and right as regular bullets and just let the SplitBullet continue it's course. Alternatively, you can adjust the course of the SplitBullet to a new trajectory, or simply remove it and replace it with a standard Bullet, depending on what you're most comfortable with.
Right, but how do the spawned bullets get added to the game class's bullet vector so they can be updated? I could pass the vector to the update function of the bullet, or maybe have the game object be global. Actually the game object being global doesn't seem like a terrible idea.
Actually, making the game object global just for the simple ability to have a bullet get access to the bullet list (or bullet factory, or what-have-you) is a terrible idea. Think of all the things you'd be making globally available -- do you really want to make all that global just so you can have one specific object access to another specific object?
You have some other options --
- Pass a reference to the bullet list/factory/etc to each bullet on creation.
- Have bullet hold a static member specifying the list. That way, the reference will only exist in one place rather than being duplicated per bullet. You'll need to initialize this variable after the list/factory/whatever has been created, and this will restrict a given bullet class to one specific list/factory/whatever. This is probably acceptible, but there are ways around it if you need, such as creating a BulletGroup class or templatizing bullets based on their list/factory/whatever.