fixed broken 1-time animations in sprites, fixed collision code returning no-collisio...
[supertux.git] / src / player.cpp
index 3f5bb93..6608f8c 100644 (file)
 #include "gameloop.h"
 #include "trigger/trigger_base.h"
 
-// behavior definitions:
-#define TILES_FOR_BUTTJUMP 3
-// animation times (in ms):
-#define SHOOTING_TIME .150
-
-// time before idle animation starts
-#define IDLE_TIME 2.500
+static const int TILES_FOR_BUTTJUMP = 3;
+static const float SHOOTING_TIME = .150;
+/// time before idle animation starts
+static const float IDLE_TIME = 2.5;
+
+static const float WALK_ACCELERATION_X = 300;
+static const float RUN_ACCELERATION_X = 400;
+static const float SKID_XM = 200;
+static const float SKID_TIME = .3;
+static const float MAX_WALK_XM = 230;
+static const float MAX_RUN_XM = 320;
+static const float WALK_SPEED = 100;
 
 // growing animation
 Surface* growingtux_left[GROWING_FRAMES];
@@ -131,7 +136,7 @@ Player::init()
 {
   holding_something = false;
 
-  bbox.set_size(32, 32);
+  bbox.set_size(31.8, 31.8);
 
   size = SMALL;
   got_power = NONE_POWER;
@@ -388,6 +393,14 @@ Player::handle_horizontal_input()
   }
 #endif
 
+  // extend/shrink tux collision rectangle so that we fall through/walk over 1
+  // tile holes
+  if(fabsf(vx) > MAX_WALK_XM) {
+    bbox.set_width(33);
+  } else {
+    bbox.set_width(31.8);
+  }
+
   physic.set_velocity(vx, vy);
   physic.set_acceleration(ax, ay);
 }
@@ -660,13 +673,13 @@ Player::handle_input()
     {
       duck = true;
       bbox.move(Vector(0, 32));
-      bbox.set_height(32);
+      bbox.set_height(31.8);
     }
   else if(input.down == UP && size == BIG && duck)
     {
       // try if we can really unduck
       bbox.move(Vector(0, -32));
-      bbox.set_height(64);
+      bbox.set_height(63.8);
       duck = false;
       // FIXME
 #if 0
@@ -676,7 +689,7 @@ Player::handle_input()
       } else {
         // undo the ducking changes
         bbox.move(Vector(0, 32));
-        bbox.set_height(32);
+        bbox.set_height(31.8);
       }
 #endif
     }
@@ -689,7 +702,7 @@ Player::grow(bool animate)
     return;
   
   size = BIG;
-  bbox.set_height(64);
+  bbox.set_height(63.8);
   bbox.move(Vector(0, -32));
 
   if(animate)
@@ -916,7 +929,7 @@ Player::kill(HurtMode mode)
           growing_timer.start(GROWING_TIME);
           safe_timer.start(TUX_SAFE_TIME + GROWING_TIME);
           size = SMALL;
-          bbox.set_height(32);
+          bbox.set_height(31.8);
           duck = false;
         }
     }
@@ -938,7 +951,7 @@ Player::remove_powerups()
 {
   got_power = NONE_POWER;
   size = SMALL;
-  bbox.set_height(32);
+  bbox.set_height(31.8);
 }
 
 void