-optimized and cleaned up collision_object_map
[supertux.git] / src / player.cpp
index 77aaa1b..afc4eb5 100644 (file)
@@ -92,6 +92,7 @@ Player::init()
   skidding_timer.init(true);
   safe_timer.init(true);
   frame_timer.init(true);
+  kick_timer.init(true);
 
   physic.reset();
 }
@@ -264,6 +265,7 @@ Player::action(double frame_ratio)
   skidding_timer.check();
   invincible_timer.check();
   safe_timer.check();
+  kick_timer.check();
 }
 
 bool
@@ -369,7 +371,7 @@ Player::handle_horizontal_input()
 void
 Player::handle_vertical_input()
 {
-  if(input.up == DOWN)
+  if(input.up == DOWN && input.old_up == UP)
     {
       if (on_ground())
         {
@@ -408,6 +410,7 @@ Player::handle_input()
     {
       handle_vertical_input();
     }
+  input.old_up = input.up;
 
   /* Shoot! */
 
@@ -440,7 +443,7 @@ Player::handle_input()
     }
 
   /* Duck! */
-  if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0)
+  if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground())
     {
       duck = true;
       base.height = 32;                             
@@ -453,11 +456,25 @@ Player::handle_input()
       duck = false;
       base.y -= 32;
       base.height = 64;
-      old_base = previous_base = base;
+      // changing base size confuses collision otherwise
+      old_base = previous_base = base;                        
     }
 }
 
 void
+Player::grow()
+{
+  if(size == BIG)
+    return;
+  
+  size = BIG;
+  base.height = 64;
+  base.y -= 32;
+
+  old_base = previous_base = base;
+}
+
+void
 Player::grabdistros()
 {
   /* Grab distros: */
@@ -508,48 +525,52 @@ Player::draw()
           else
             sprite = &largetux;
           
-          if (skidding_timer.started())
+          if (duck && size != SMALL)
+            {
+              if (dir == RIGHT)
+                sprite->duck_right->draw(base.x - scroll_x, base.y);
+              else 
+                sprite->duck_left->draw(base.x - scroll_x, base.y);
+            }
+          else if (skidding_timer.started())
             {
               if (dir == RIGHT)
                 sprite->skid_right->draw(base.x - scroll_x, base.y);
               else
                 sprite->skid_left->draw(base.x - scroll_x, base.y); 
             }
+          else if (kick_timer.started())
+            {
+              if (dir == RIGHT)
+                sprite->kick_right->draw(base.x - scroll_x, base.y);
+              else
+                sprite->kick_left->draw(base.x - scroll_x, base.y); 
+            }
+          else if (physic.get_velocity_y() != 0)
+            {
+              if (dir == RIGHT)
+                sprite->jump_right->draw(base.x - scroll_x, base.y);
+              else
+                sprite->jump_left->draw(base.x - scroll_x, base.y);                   
+            }
           else
             {
-              if (duck)
+              if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
                 {
                   if (dir == RIGHT)
-                    sprite->duck_right->draw(base.x - scroll_x, base.y);
-                  else 
-                    sprite->duck_left->draw(base.x - scroll_x, base.y);
-                }                    
-              else if (physic.get_velocity_y() != 0)
-                {
-                  if (dir == RIGHT)
-                    sprite->jump_right->draw(base.x - scroll_x, base.y);
+                    sprite->stand_right->draw( base.x - scroll_x, base.y);
                   else
-                    sprite->jump_left->draw(base.x - scroll_x, base.y);                   
+                    sprite->stand_left->draw( base.x - scroll_x, base.y);
                 }
-              else
+              else // moving
                 {
-                  if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
-                    {
-                      if (dir == RIGHT)
-                        sprite->stand_right->draw( base.x - scroll_x, base.y);
-                      else
-                        sprite->stand_left->draw( base.x - scroll_x, base.y);
-                    }
-                  else // moving
-                    {
-                      if (dir == RIGHT)
-                        sprite->walk_right->draw(base.x - scroll_x, base.y);
-                      else
-                        sprite->walk_left->draw(base.x - scroll_x, base.y);
-                    }
+                  if (dir == RIGHT)
+                    sprite->walk_right->draw(base.x - scroll_x, base.y);
+                  else
+                    sprite->walk_left->draw(base.x - scroll_x, base.y);
                 }
             }
-          
+                      
           // Draw arm overlay graphics when Tux is holding something
           if (holding_something && physic.get_velocity_y() == 0)
             {
@@ -590,7 +611,8 @@ Player::collision(void* p_c_object, int c_object)
           !safe_timer.started() &&
           pbad_c->mode != BadGuy::HELD)
         {
-          if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN)
+          if (pbad_c->mode == BadGuy::FLAT && input.fire == DOWN
+               && !holding_something)
             {
               holding_something = true;
               pbad_c->mode = BadGuy::HELD;
@@ -624,7 +646,7 @@ Player::collision(void* p_c_object, int c_object)
                 }
               else
                 {
-                  pbad_c->kill_me();
+                  pbad_c->kill_me(25);
                 }
             }
           player_status.score_multiplier++;