This code is suppose to be for managing bullets in my space invaders clone. The part that I have trouble on is firing the bullets and tracking which ones are active and whichs are not. Any help on this?
Code:struct bullet{
int x;
int y;
int alive;
};
struct bullet bullets[256];
int bulletsUsed = 0; // tracks how many bullets are active
void createBullet(struct bullet bullets[])
{
bulletsUsed++;
bullets[bulletsUsed].x = ship.x
bullets[bulletsUsed].y = ship.y
bullets[bulletsUsed].alive = true
}
void fireBullets(struct bullet bullets[])
{
int i;
for(i = 0; i < bulletsUsed; i++)
{
bullets[i].y--;
if(bullets[i].y < 0)
bullets[i].alive = false;
}
}