Fixed crashes at tiles that are not defined in supertux.stgt - throwing a warning...
[supertux.git] / src / player.cpp
index b3ecd98..ce98871 100644 (file)
@@ -39,6 +39,7 @@
 #define TILES_FOR_BUTTJUMP 3
 // animation times (in ms):
 #define SHOOTING_TIME 320
+#define STOMP_TIME 250
 // others stuff:
 #define AUTOSCROLL_DEAD_INTERVAL 300
 
@@ -115,7 +116,8 @@ Player::init()
   jumping = false;
   can_jump = true;
   butt_jump = false;
-
+  
+  stomp_pos = Vector(0,0);
   frame_main = 0;
   frame_ = 0;
 
@@ -287,7 +289,7 @@ Player::action(float elapsed_time)
           if (isbrick(base.x, base.y) ||
               isfullbox(base.x, base.y))
             {
-              Sector::current()->trygrabdistro(
+             Sector::current()->trygrabdistro(
                   Vector(base.x, base.y - 32), BOUNCE);
               Sector::current()->trybumpbadguy(Vector(base.x, base.y - 64));
 
@@ -301,7 +303,7 @@ Player::action(float elapsed_time)
           if (isbrick(base.x+ 31, base.y) ||
               isfullbox(base.x+ 31, base.y))
             {
-              Sector::current()->trygrabdistro(
+             Sector::current()->trygrabdistro(
                   Vector(base.x+ 31, base.y - 32), BOUNCE);
               Sector::current()->trybumpbadguy(Vector(base.x+ 31, base.y - 64));
 
@@ -496,7 +498,7 @@ Player::handle_vertical_input()
 
    /* In case the player has pressed Down while in a certain range of air,
       enable butt jump action */
-  if (input.down == DOWN && !butt_jump)
+  if (input.down == DOWN && !butt_jump && !duck)
     if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping)
       butt_jump = true;
 
@@ -507,6 +509,13 @@ Player::handle_vertical_input()
   // Do butt jump
   if (butt_jump && on_ground() && size == BIG)
   {
+    
+    if (duck) 
+      stomp_pos = Vector(base.x - 32, base.y);
+    else 
+      stomp_pos = Vector(base.x - 32, base.y + 32);    
+    stomp_timer.start(STOMP_TIME);
+    
     butt_jump = false;
 
     // Break bricks beneath Tux
@@ -528,8 +537,9 @@ Player::handle_vertical_input()
       BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
       if(badguy)
       {
-        if (fabsf(base.x - badguy->base.x) < 300 &&
-            fabsf(base.y - badguy->base.y) < 300 &&
+        
+       if (fabsf(base.x - badguy->base.x) < 150 &&
+            fabsf(base.y - badguy->base.y) < 60 &&
             (issolid(badguy->base.x + 1, badguy->base.y + badguy->base.height) ||
               issolid(badguy->base.x + badguy->base.width - 1, badguy->base.y + badguy->base.height)))
           badguy->kill_me(25);
@@ -648,7 +658,6 @@ Player::grabdistros()
     {
       Sector::current()->trygrabdistro(Vector(base.x, base.y), NO_BOUNCE);
       Sector::current()->trygrabdistro(Vector(base.x+ 31, base.y), NO_BOUNCE);
-
       Sector::current()->trygrabdistro(
           Vector(base.x, base.y + base.height), NO_BOUNCE);
       Sector::current()->trygrabdistro(
@@ -656,7 +665,7 @@ Player::grabdistros()
 
       if(size == BIG)
         {
-          Sector::current()->trygrabdistro(
+         Sector::current()->trygrabdistro(
               Vector(base.x, base.y + base.height / 2), NO_BOUNCE);
           Sector::current()->trygrabdistro(
               Vector(base.x+ 31, base.y + base.height / 2), NO_BOUNCE);
@@ -763,6 +772,10 @@ Player::draw(DrawingContext& context)
     else
       sprite->grab_left->draw(context, pos, LAYER_OBJECTS + 1);
   }
+  
+  // Draw stomp clouds when doing a butt jump
+  if (stomp_timer.check())
+      sprite->stomp->draw(context, stomp_pos, LAYER_OBJECTS + 1);
 
   // Draw blinking star overlay
   if (invincible_timer.started() &&