- improved verboseness of badguy in wall error message
[supertux.git] / src / player.cpp
index ec3e899..d6f60e9 100644 (file)
@@ -18,7 +18,6 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <math.h>
-
 #include "gameloop.h"
 #include "globals.h"
 #include "player.h"
@@ -57,6 +56,7 @@ void player_input_init(player_input_type* pplayer_input)
   pplayer_input->old_fire = UP;
   pplayer_input->right = UP;
   pplayer_input->up = UP;
+  pplayer_input->old_up = UP;
 }
 
 void
@@ -82,6 +82,7 @@ Player::init()
 
   dying   = DYING_NOT;
   jumping = false;
+  can_jump = true;
 
   frame_main = 0;
   frame_ = 0;
@@ -92,6 +93,7 @@ Player::init()
   skidding_timer.init(true);
   safe_timer.init(true);
   frame_timer.init(true);
+  kick_timer.init(true);
 
   physic.reset();
 }
@@ -264,6 +266,7 @@ Player::action(double frame_ratio)
   skidding_timer.check();
   invincible_timer.check();
   safe_timer.check();
+  kick_timer.check();
 }
 
 bool
@@ -369,24 +372,27 @@ Player::handle_horizontal_input()
 void
 Player::handle_vertical_input()
 {
-  if(input.up == DOWN)
+  // Press jump key
+  if(input.up == DOWN && can_jump)
     {
       if (on_ground())
         {
           // jump higher if we are running
-          if (physic.get_velocity_x() > MAX_WALK_XM)
+          if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
             physic.set_velocity_y(5.8);
           else
             physic.set_velocity_y(5.2);
 
           --base.y;
           jumping = true;
+          can_jump = false;
           if (size == SMALL)
             play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
           else
             play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
         }
     }
+  // Let go of jump key
   else if(input.up == UP && jumping)
     {
       jumping = false;
@@ -394,6 +400,19 @@ Player::handle_vertical_input()
         physic.set_velocity_y(0);
       }
     }
+
+  if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) ||
+        issolid(base.x + 1, base.y + base.height + 64) ||
+        issolid(base.x + base.width - 1, base.y + base.height + 64))
+       && jumping  == false
+       && can_jump == false
+       && input.up == DOWN
+       && input.old_up == UP)
+    {
+      can_jump = true;
+    }
+
+  input.old_up = input.up;
 }
 
 void
@@ -404,7 +423,9 @@ Player::handle_input()
 
   /* Jump/jumping? */
 
-  if ( input.up == DOWN || (input.up == UP && jumping))
+  if (on_ground() && input.up == UP)
+    can_jump = true;
+  if (input.up == DOWN || (input.up == UP && jumping))
     {
       handle_vertical_input();
     }
@@ -453,11 +474,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,13 +543,13 @@ Player::draw()
           else
             sprite = &largetux;
           
-          if (duck)
+          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)
@@ -522,6 +557,13 @@ Player::draw()
               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)
@@ -557,7 +599,8 @@ Player::draw()
             }
 
           // Draw blinking star overlay
-          if (invincible_timer.started())
+          if (invincible_timer.started() &&
+             (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3))
             {
               if (size == SMALL || duck)
                 smalltux_star->draw(base.x - scroll_x, base.y);
@@ -587,7 +630,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;
@@ -621,7 +665,7 @@ Player::collision(void* p_c_object, int c_object)
                 }
               else
                 {
-                  pbad_c->kill_me();
+                  pbad_c->kill_me(25);
                 }
             }
           player_status.score_multiplier++;