Fix music not properly fading in again
[supertux.git] / src / badguy / zeekling.cpp
index 69cba10..0ca8a56 100644 (file)
@@ -34,7 +34,7 @@ Zeekling::Zeekling(const Reader& reader) :
   last_self_pos()
 {
   state = FLYING;
-  speed = systemRandom.rand(130, 171);
+  speed = gameRandom.rand(130, 171);
   physic.enable_gravity(false);
 }
 
@@ -48,7 +48,7 @@ Zeekling::Zeekling(const Vector& pos, Direction d) :
   last_self_pos()
 {
   state = FLYING;
-  speed = systemRandom.rand(130, 171);
+  speed = gameRandom.rand(130, 171);
   physic.enable_gravity(false);
 }
 
@@ -64,12 +64,16 @@ Zeekling::collision_squished(GameObject& object)
 {
   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
   kill_squished(object);
-  kill_fall();
   return true;
 }
 
 void
 Zeekling::onBumpHorizontal() {
+  if (frozen)
+  {
+    physic.set_velocity_x(0);
+    return;
+  }
   if (state == FLYING) {
     dir = (dir == LEFT ? RIGHT : LEFT);
     sprite->set_action(dir == LEFT ? "left" : "right");
@@ -93,6 +97,12 @@ Zeekling::onBumpHorizontal() {
 
 void
 Zeekling::onBumpVertical() {
+  if (frozen)
+  {
+    physic.set_velocity_y(0);
+    physic.set_velocity_x(0);
+    return;
+  }
   if (state == FLYING) {
     physic.set_velocity_y(0);
   } else
@@ -110,6 +120,12 @@ Zeekling::onBumpVertical() {
 void
 Zeekling::collision_solid(const CollisionHit& hit)
 {
+  if(sprite->get_action() == "squished-left" ||
+     sprite->get_action() == "squished-right")
+  {
+    return;
+  }
+
   if(hit.top || hit.bottom) {
     onBumpVertical();
   } else if(hit.left || hit.right) {
@@ -122,6 +138,8 @@ Zeekling::collision_solid(const CollisionHit& hit)
  */
 bool
 Zeekling::should_we_dive() {
+  if (frozen)
+    return false;
 
   const MovingObject* player = this->get_nearest_player();
   if (player && last_player && (player == last_player)) {
@@ -195,6 +213,26 @@ Zeekling::active_update(float elapsed_time) {
   }
 }
 
-IMPLEMENT_FACTORY(Zeekling, "zeekling");
+void
+Zeekling::freeze()
+{
+  BadGuy::freeze();
+  physic.enable_gravity(true);
+}
+
+void
+Zeekling::unfreeze()
+{
+  BadGuy::unfreeze();
+  physic.enable_gravity(false);
+  state = FLYING;
+  initialize();
+}
+
+bool
+Zeekling::is_freezable() const
+{
+  return true;
+}
 
 /* EOF */