Heres the bullet coding. (yet to put in any velocity or frame rate smoothing)
Code: Select all
#define BULLETS 5
class Bullet {
public:
Bullet();
void Update();
void Fire(float, float);
void Draw();
bool alive;
private:
float radius;
float x, y;
//float xv, yv;
};
Bullet bullet[BULLETS];
Bullet::Bullet():alive(false), radius(10), x(0), y(0){}
void Bullet::Update() {
if (alive) {
y += .1;
//
if (y > (windowHeight - 50)) {
alive = false;
}
}
}
void Bullet::Fire(float startx, float starty) {
x = startx;
y = starty;
alive = true;
}
void Bullet::Draw() {
if (alive) {
glBegin(GL_LINE_LOOP);
glVertex3f(x-(radius*0.5), y-(radius*0.5), 0.0f);
glVertex3f(x+(radius*0.5), y-(radius*0.5), 0.0f);
glVertex3f(x+(radius*0.5), y+(radius*0.5), 0.0f);
glVertex3f(x-(radius*0.5), y+(radius*0.5), 0.0f);
glEnd();
/*glBegin(GL_LINE_LOOP);
for (int i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f(x + cos(degInRad)* (radius*1.5), y + sin(degInRad)*(radius*1.5));
}
glEnd();*/
}
}
if (key[SPACE]) {
for (int i = 0; i < BULLETS; i++) {
if (bullet[i].alive == false) {
bullet[i].Fire(ship.x, ship.y);
break;
}
}
}
for (int i = 0; i < BULLETS; i++) {
if (bullet[i].alive) {
bullet[i].Update();
bullet[i].Draw();
}
}
Code: Select all
if (key[SPACE]) {
for (int i = 0; i < BULLETS; i++) {
if (i == 1) //<<<<<<<<<<<<<<
ship.x = 300;//<<<<<<<<<<<<<
if (bullet[i].alive == false) {
bullet[i].Fire(ship.x, ship.y);
break; // <<<<<<<<<<<<<<<<<<<<<<<<<<< Is this not working?
}
}
}
Any help would be really appreciated