src/Projectile.cc
changeset 224 e6faefba2ec1
parent 222 293ddf4c067d
child 226 381487d07d17
--- a/src/Projectile.cc	Sat Dec 06 18:49:51 2008 +0000
+++ b/src/Projectile.cc	Sat Dec 06 19:14:58 2008 +0000
@@ -21,10 +21,25 @@
     state.projectiles.remove(this);
 }
  
+void Projectile::onDestroy (Vector position, bool removeGround) {
+    if (removeGround)
+        world.removeGround(position, radius);
+
+    destroy();
+}
+
 void Projectile::onCollision() {
-    world.removeGround(position, radius);
-    
-    destroy();
+    onDestroy(position, true);
+}
+
+   
+void Projectile::tick (TimeMS dt) {
+    // expire projectiles
+    if (world.tick_timer.get_ticks() > birth_tick + age)
+        onDestroy(position, false);
+
+    // super
+    PhysicsObject::tick(dt);
 }
 
 void Projectile::draw(CL_GraphicContext *gc) const {
@@ -42,7 +57,7 @@
         const uint16_t chlen = 10;
         uint16_t x = projectile.center().x;
         uint16_t y = projectile.center().y;
-        if(target_visible) {
+        if (target_visible) {
             if (facingRight) {
                 gc->draw_line(x, y,
                               x + std::cos(aim)*chlen,
@@ -57,13 +72,4 @@
         }
     }
 }
-    
-void Projectile::tick (TimeMS dt) {
-    // expire projectiles
-    if (world.tick_timer.get_ticks() > birth_tick + age)
-        destroy();
-
-    // super
-    PhysicsObject::tick(dt);
-}
-
+