Stop dispense_timer on deactivate.
[supertux.git] / src / badguy / zeekling.cpp
index 65abb0c..85b2d47 100644 (file)
 Zeekling::Zeekling(const lisp::Lisp& reader)
        : BadGuy(reader, "images/creatures/zeekling/zeekling.sprite")
 {
-  set_direction = false;
   state = FLYING;
 }
 
 Zeekling::Zeekling(const Vector& pos, Direction d)
-       : BadGuy(pos, "images/creatures/zeekling/zeekling.sprite")
+       : BadGuy(pos, d, "images/creatures/zeekling/zeekling.sprite")
 {
-  set_direction = true;
-  initial_direction = d;
   state = FLYING;
 }
 
@@ -55,7 +52,6 @@ void
 Zeekling::activate()
 {
   speed = systemRandom.rand(130, 171);
-  if (set_direction) {dir = initial_direction;}
   physic.set_velocity_x(dir == LEFT ? -speed : speed);
   physic.enable_gravity(false);
   sprite->set_action(dir == LEFT ? "left" : "right");
@@ -70,7 +66,7 @@ Zeekling::collision_squished(Player& player)
   return true;
 }
 
-void 
+void
 Zeekling::onBumpHorizontal() {
   if (state == FLYING) {
     dir = (dir == LEFT ? RIGHT : LEFT);
@@ -88,17 +84,19 @@ Zeekling::onBumpHorizontal() {
     dir = (dir == LEFT ? RIGHT : LEFT);
     sprite->set_action(dir == LEFT ? "left" : "right");
     physic.set_velocity_x(dir == LEFT ? -speed : speed);
+  } else {
+    assert(false);
   }
 }
 
-void 
+void
 Zeekling::onBumpVertical() {
   if (state == FLYING) {
     physic.set_velocity_y(0);
   } else
   if (state == DIVING) {
     state = CLIMBING;
-    physic.set_velocity_y(speed);
+    physic.set_velocity_y(-speed);
     sprite->set_action(dir == LEFT ? "left" : "right");
   } else
   if (state == CLIMBING) {
@@ -107,22 +105,20 @@ Zeekling::onBumpVertical() {
   }
 }
 
-HitResponse
-Zeekling::collision_solid(GameObject& , const CollisionHit& hit)
+void
+Zeekling::collision_solid(const CollisionHit& hit)
 {
-  if(fabsf(hit.normal.y) > .5) {
-    onBumpVertical(); 
-  } else {
+  if(hit.top || hit.bottom) {
+    onBumpVertical();
+  } else if(hit.left || hit.right) {
     onBumpHorizontal();
   }
-
-  return CONTINUE;
 }
 
 /**
  * linear prediction of player and badguy positions to decide if we should enter the DIVING state
  */
-bool 
+bool
 Zeekling::should_we_dive() {
   const MovingObject* player = this->get_nearest_player();
   if (!player) return false;
@@ -148,7 +144,7 @@ Zeekling::should_we_dive() {
 
   // guess number of frames to descend to same height as player
   float estFrames = height / relSpeed;
-  
+
   // guess where the player would be at this time
   float estPx = (playerPos.x + (estFrames * playerMov.x));
 
@@ -161,32 +157,30 @@ Zeekling::should_we_dive() {
   return false;
 }
 
-void 
+void
 Zeekling::active_update(float elapsed_time) {
-  BadGuy::active_update(elapsed_time);
-
   if (state == FLYING) {
     if (should_we_dive()) {
       state = DIVING;
-      physic.set_velocity_y(-2*fabsf(physic.get_velocity_x()));
+      physic.set_velocity_y(2*fabsf(physic.get_velocity_x()));
       sprite->set_action(dir == LEFT ? "diving-left" : "diving-right");
     }
+    BadGuy::active_update(elapsed_time);
     return;
-  }
-
-  if (state == DIVING) {
+  } else if (state == DIVING) {
+    BadGuy::active_update(elapsed_time);
     return;
-  }
-
-  if (state == CLIMBING) {
+  } else if (state == CLIMBING) {
     // stop climbing when we're back at initial height
     if (get_pos().y <= start_position.y) {
       state = FLYING;
       physic.set_velocity_y(0);
     }
+    BadGuy::active_update(elapsed_time);
     return;
+  } else {
+    assert(false);
   }
-
 }
 
 IMPLEMENT_FACTORY(Zeekling, "zeekling")