changed worldmap to be stored inside the same directory as the levelsubset, fixed...
[supertux.git] / src / badguy / nolok_01.cpp
index 69a91dd..1a5768f 100644 (file)
@@ -6,17 +6,16 @@
 
 #define WALK_TIME 2.5
 #define SHOOT_TIME 0.4
-#define JUMP_TIME 0.3
+#define JUMP_TIME 0.5
 
 static const float WALKSPEED = 90;
 
 //TODO: Create sprite, give multiple hitpoints, limit max number of snowballs
-//      Can only be killed when jumping, no idea why
 //      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");
 }
@@ -30,12 +29,12 @@ 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.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");
 }
@@ -52,27 +51,36 @@ Nolok_01::activate()
 void
 Nolok_01::active_action(float elapsed_time)
 {
-   movement = physic.get_movement(elapsed_time);
    if (action_timer.check()) {
-     if (action == WALKING) {
-        physic.set_velocity_y(700);
-        action = JUMPING;
-        action_timer.start(JUMP_TIME);
-     }
-     else if (action == JUMPING) {
+     switch (action) {       
+       case WALKING:
+        {
+         sprite->set_action("jump");
+         physic.set_velocity_y(700);
+         action = JUMPING;
+         action_timer.start(JUMP_TIME);
+         break;
+        }
+       case JUMPING:
+       {
         sprite->set_action("throw");
         action = SHOOTING;
         action_timer.start(SHOOT_TIME);
-     }
-     else if (action == SHOOTING) {
+        break;
+       }
+       case SHOOTING:
+       {
         Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT));
         Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT));
         physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
         sprite->set_action(dir == LEFT ? "left" : "right");
         action = WALKING;
         action_timer.start(WALK_TIME);
+        break;
+       }
      }
    }
+   movement = physic.get_movement(elapsed_time);
 }
 
 bool
@@ -87,8 +95,8 @@ Nolok_01::collision_squished(Player& player)
 HitResponse
 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
 {
-  if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
-    //physic.set_velocity_y(0);
+  if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
+    if (action != JUMPING) physic.set_velocity_y(0);
   } else { // hit right or left
     dir = dir == LEFT ? RIGHT : LEFT;
     sprite->set_action(dir == LEFT ? "left" : "right");