fixed kugelblitz, added electrifier object
[supertux.git] / src / badguy / kugelblitz.cpp
index 1f861fe..94be058 100644 (file)
@@ -20,7 +20,6 @@
 #include <config.h>
 
 #include "kugelblitz.hpp"
-#include "sector.hpp"
 #include "object/tilemap.hpp"
 #include "tile.hpp"
 
@@ -61,16 +60,37 @@ Kugelblitz::activate()
 }
 
 HitResponse
-Kugelblitz::collision_solid(GameObject& other, const CollisionHit& chit)
+Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit)
 {
-  //TODO: Explode when Tux is hit
   return hit(chit);
 }
 
 HitResponse
+Kugelblitz::collision_player(Player& player, const CollisionHit& )
+{
+  if(player.is_invincible()) {
+    explode();
+    return ABORT_MOVE;
+  }
+  // hit from above?
+  if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y <
+      (get_bbox().p1.y + get_bbox().p2.y) / 2) {
+    // if it's not is it possible to squish us, then this will hurt
+    if(!collision_squished(player))
+      player.kill(Player::SHRINK);
+      explode();
+    return FORCE_MOVE;
+  }
+  player.kill(Player::SHRINK);
+  explode();
+  return FORCE_MOVE;
+}
+
+HitResponse
 Kugelblitz::collision_badguy(BadGuy& other , const CollisionHit& chit)
 {
-  //Let the Kugelblitz explode, too?
+  //Let the Kugelblitz explode, too? The problem with that is that
+  //two Kugelblitzes would cancel each other out on contact...
   other.kill_fall();
   return hit(chit);
 }
@@ -105,12 +125,7 @@ void
 Kugelblitz::active_update(float elapsed_time)
 {
   if (lifetime.check()) {
-    if (!dying) {
-      sprite->set_action("pop");
-      lifetime.start(0.2);
-      dying = true;
-    }
-    else remove_me();
+    explode();
   }
   else {
     if (groundhit_pos_set) {
@@ -123,6 +138,9 @@ Kugelblitz::active_update(float elapsed_time)
     }
     if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) {
       //HIT WATER
+      Sector::current()->add_object(new Electrifier(75,1421,1.5));
+      Sector::current()->add_object(new Electrifier(76,1422,1.5));
+      explode();
     }
   }
   BadGuy::active_update(elapsed_time);  
@@ -133,4 +151,15 @@ Kugelblitz::kill_fall()
 {
 }
 
+void
+Kugelblitz::explode()
+{
+  if (!dying) {
+    sprite->set_action("pop");
+    lifetime.start(0.2);
+    dying = true;
+  }
+  else remove_me();
+}
+
 IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz")