1 #include "Projectile.hh" |
1 #include "Projectile.hh" |
2 #include "Timer.hh" |
2 #include "Timer.hh" |
3 |
3 |
4 Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) : |
4 Projectile::Projectile(GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age) : |
5 PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), destroyed(false), age(age) { |
5 PhysicsObject(state.world, PLAYER_MASS, position, velocity), state(state), visible(visible), radius(radius), age(age) { |
6 birth_tick = world.tick_timer.get_ticks(); |
6 birth_tick = world.tick_timer.get_ticks(); |
7 // Don't think these are needed anymore |
7 // Don't think these are needed anymore |
8 std::vector<Vector> shape(4); |
8 std::vector<Vector> shape(4); |
9 shape[0] = Vector(-1, -1); |
9 shape[0] = Vector(-1, -1); |
10 shape[1] = Vector(-1, 1); |
10 shape[1] = Vector(-1, 1); |
12 shape[3] = Vector(1, -1); |
12 shape[3] = Vector(1, -1); |
13 setShape(shape); |
13 setShape(shape); |
14 |
14 |
15 target_visible = false; |
15 target_visible = false; |
16 collision_elasticity = 0.9; // = shotType.elasticity |
16 collision_elasticity = 0.9; // = shotType.elasticity |
17 world.addProjectile(this); |
17 state.addProjectile(this); |
18 } |
18 } |
19 |
19 |
|
20 Projectile::~Projectile (void) { |
|
21 state.projectiles.remove(this); |
|
22 } |
20 |
23 |
21 void Projectile::onCollision() { |
24 void Projectile::onCollision() { |
22 world.removeGround(position, radius); |
25 world.removeGround(position, radius); |
23 this->destroyed = true; |
26 |
24 } |
27 destroy(); |
25 |
|
26 bool Projectile::isDestroyed (void) const { |
|
27 return this->destroyed; |
|
28 } |
28 } |
29 |
29 |
30 void Projectile::draw(CL_GraphicContext *gc) const { |
30 void Projectile::draw(CL_GraphicContext *gc) const { |
31 if (visible) { |
31 if (visible) { |
32 |
32 |