- reduced jump tolleranze to two tiles
[supertux.git] / src / player.cpp
index fe5604f..785860b 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;
@@ -371,7 +372,8 @@ 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())
         {
@@ -383,12 +385,14 @@ Player::handle_vertical_input()
 
           --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;
@@ -396,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
@@ -406,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();
     }
@@ -455,6 +474,8 @@ Player::handle_input()
       duck = false;
       base.y -= 32;
       base.height = 64;
+      // changing base size confuses collision otherwise
+      old_base = previous_base = base;                        
     }
 }
 
@@ -467,13 +488,6 @@ Player::grow()
   size = BIG;
   base.height = 64;
   base.y -= 32;
-  // eventually go in duck mode if there's no space
-  if(collision_object_map(base))
-    {
-      base.height = 32;
-      base.y += 32;
-      duck = true;
-    }
 
   old_base = previous_base = base;
 }
@@ -585,7 +599,7 @@ 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 % 2))
             {
               if (size == SMALL || duck)
                 smalltux_star->draw(base.x - scroll_x, base.y);