-Apply door fix to hatch as well (evil code duplication here...)
[supertux.git] / src / badguy / nolok_01.cpp
index 1090d97..7d66504 100644 (file)
@@ -6,16 +6,17 @@
 
 #define WALK_TIME 2.5
 #define SHOOT_TIME 0.4
-#define JUMP_TIME 0.3
+#define JUMP_TIME 0.5
+#define INITIAL_HITPOINTS 3
 
 static const float WALKSPEED = 90;
 
-//TODO: Create sprite, give multiple hitpoints, limit max number of snowballs
+//TODO: Create sprite, limit max number of snowballs
 //      Stop actions when pause button is hit (probably a general problem of timers)
-Nolok_01::Nolok_01(LispReader& reader)
+Nolok_01::Nolok_01(const lisp::Lisp& reader)
 {
-  reader.read_float("x", start_position.x);
-  reader.read_float("y", start_position.y);
+  reader.get("x", start_position.x);
+  reader.get("y", start_position.y);
   bbox.set_size(31.8, 63.8);
   sprite = sprite_manager->create("dummyguy");
 }
@@ -29,19 +30,20 @@ Nolok_01::Nolok_01(float pos_x, float pos_y)
 }
 
 void
-Nolok_01::write(LispWriter& writer)
+Nolok_01::write(lisp::Writer& writer)
 {
-  writer.start_list("nolok01");
+  writer.start_list("nolok_01");
 
-  writer.write_float("x", get_pos().x);
-  writer.write_float("y", get_pos().y);
+  writer.write_float("x", start_position.x);
+  writer.write_float("y", start_position.y);
 
-  writer.end_list("nolok01");
+  writer.end_list("nolok_01");
 }
 
 void
 Nolok_01::activate()
 {
+  hitpoints = INITIAL_HITPOINTS;
   physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
   sprite->set_action(dir == LEFT ? "left" : "right");
   action = WALKING;
@@ -55,6 +57,7 @@ Nolok_01::active_action(float elapsed_time)
      switch (action) {       
        case WALKING:
         {
+         sprite->set_action("jump");
          physic.set_velocity_y(700);
          action = JUMPING;
          action_timer.start(JUMP_TIME);
@@ -85,10 +88,15 @@ Nolok_01::active_action(float elapsed_time)
 bool
 Nolok_01::collision_squished(Player& player)
 {
-  sprite->set_action("dead"); 
-  kill_squished(player);
-  Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
-  return true;
+  bool result = false;
+  player.bounce(*this);
+  if (hitpoints <= 0) {
+    sprite->set_action("dead"); 
+    kill_squished(player);
+    Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
+    result = true;
+  }
+  return result;
 }
 
 HitResponse
@@ -105,3 +113,4 @@ Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+IMPLEMENT_FACTORY(Nolok_01, "nolok_01")