Trouble making my ship shoot in C++

I'm trying to program a basic game sort of resembling Galaga or Space Invaders.
I'm writing in C++ using Visual Studio and OpenGL. Basically I need a class that is the game, a class for my player, a class for my bullets and a class for my enemies. I need the enemies and bullets to know each other so that they will destroy each other and and my player to know his bullet.

I would like an array that holds a few bullets and a for loop to cycle through to see what bullets aren't on screen and to fire them from the ship.

I especially need help with creating and deleting the bullets and any help would be appreciated.

Thank you,
Kira666.
use new and delete to create nd delete ur objects like bulllets etc
Last edited on
As a beginner, I recommend you consider using a vector.

Your bullet objects are instances of a struct or class; each bullet should know its own location, speed etc.

As each bullet is created, it gets added to the end of the vector. Each time your game moves time forwards, every bullet in the vector should have its update function called, and it will use its own knowledge of its speed and location to set its new position. It is easy to apply a function to every member of a vector.

Then, traverse the vector (which means start at the beginning and go through each bullet in turn), removing any bullets that are no longer on screen.

When a new bullet is created, add it to the end of the vector with a simple
vectorOfBullets.push_back(theBullet);

You can remove them with a simple
vectorOfBullets.erase(numberOfElementToErase);

Using a vector has the advantages that all the bullets are held in the same place, and you don't need to keep track of the memory manually. You just create a bullet, and push it onto the end, and let them take care of themselves.
Topic archived. No new replies allowed.