--- a/src/Projectile.cc Sun Dec 07 22:48:46 2008 +0000
+++ b/src/Projectile.cc Sun Dec 07 23:10:30 2008 +0000
@@ -2,22 +2,42 @@
#include "Graphics.hh"
#include "Timer.hh"
-Projectile::Projectile (GameState &state, Vector position, Vector velocity, bool visible, float explosionRadius, float radius, TickCount age) :
- PhysicsObject(state.world, PLAYER_MASS, position, velocity, PROJECTILE), state(state), visible(visible), explosionRadius(explosionRadius), radius(radius), age(age)
+Projectile::Projectile (GameState &state, Vector position, Vector velocity, float explosionRadius, float radius,
+ TickCount expire, bool visible) :
+ PhysicsObject(state.world, PLAYER_MASS, position, velocity, PROJECTILE), state(state), visible(visible),
+ explosionRadius(explosionRadius), radius(radius), expire(expire)
{
+ initialize();
+}
+
+Projectile::Projectile (GameState &state, Vector position, Vector velocity, Weapon *weapon, bool visible) :
+ PhysicsObject(state.world, PLAYER_MASS, position, velocity, PROJECTILE), state(state), visible(visible),
+ explosionRadius(weapon->getExplosionRadius()), radius(weapon->getRadius()), expire(weapon->getExpire())
+{
+ initialize();
+}
+
+void Projectile::initialize (void) {
+ // set birth tick
birth_tick = world.tick_timer.get_ticks();
- // Don't think these are needed anymore
+
+ // XXX: projectiles should be particles?
std::vector<Vector> shape(4);
+
shape[0] = Vector(0, -radius );
shape[1] = Vector(+radius, 0 );
shape[2] = Vector(0, +radius );
shape[3] = Vector(-radius, 0 );
+
setShape(shape);
+
+ // XXX: get this as an argument
+ collision_elasticity = 0.9;
- collision_elasticity = 0.9; // = shotType.elasticity
+ // add to state
state.addProjectile(this);
}
-
+
Projectile::~Projectile (void) {
state.projectiles.remove(this);
}
@@ -36,7 +56,7 @@
void Projectile::tick (TimeMS dt) {
// expire projectiles
- if (world.tick_timer.get_ticks() > birth_tick + age)
+ if (world.tick_timer.get_ticks() > birth_tick + expire)
onDestroy(position, true);
// super