Right long story short. Im making a game and have created a bullet class. It only fires one bullet so ofc I have to make it an array. I have tried the following and it doesn't work -
bullet class:
And in main -
Yet it is still only firing one bullet :S. The IfMouseNewLeftDown() only is true if the previous sample of the mouse is false meaning only one bullet is fired at a time and not all fired at once
bullet class:
class Bullet {
private:
bool alive;
double x, y;
double s;
double ang;
public:
Bullet(){
}
void Bullet::Update() {
if(alive) {
x += s * cos(ang);
y += s * sin(ang);
}
}
void Bullet::Fire(double startX, double startY, double angle, double speed) {
if (alive == false) {
x = startX;
y = startY;
ang = angle;
s = speed;
alive = true;
}
}
void Bullet:raw() {
if (alive) {
bulletSourceRect.top = 0;
bulletSourceRect.bottom = 25;
bulletSourceRect.left = 75;
bulletSourceRect.right = 100;
bulletDestRect.top = (long)y;
bulletDestRect.bottom = bulletDestRect.top + 15;
bulletDestRect.left = (long)x;
bulletDestRect.right = bulletDestRect.left + 15;
pTheDrawEngine->Blit(bulletDestRect, bulletSourceRect, pBullet);
}
}
};
And in main -
Bullet bullets[20];
if (pTheInputs -> IfMouseNewLeftDown() ) {
bullets.Fire(132, player.getYPosition() + 32, player.getAngle(), 5);
}
bullets.Update();
bullets.Draw();
}
Yet it is still only firing one bullet :S. The IfMouseNewLeftDown() only is true if the previous sample of the mouse is false meaning only one bullet is fired at a time and not all fired at once