Getting rid of nasty tabs
[supertux.git] / src / object / player.cpp
index 489283e..63770ef 100644 (file)
@@ -60,7 +60,7 @@ static const float SHOOTING_TIME = .150f;
 static const float IDLE_TIME = 2.5f;
 
 /** acceleration in horizontal direction when walking
- * (all acceleratiosn are in  pixel/s^2) */
+ * (all accelerations are in  pixel/s^2) */
 static const float WALK_ACCELERATION_X = 300;
 /** acceleration in horizontal direction when running */ 
 static const float RUN_ACCELERATION_X = 400;
@@ -70,7 +70,7 @@ static const float SKID_XM = 200;
 static const float SKID_TIME = .3f;
 /** maximum walk velocity (pixel/s) */
 static const float MAX_WALK_XM = 230;
-/** maximum run velcoity (pixel/s) */
+/** maximum run velocity (pixel/s) */
 static const float MAX_RUN_XM = 320;
 /** maximum horizontal climb velocity */
 static const float MAX_CLIMB_XM = 48;
@@ -86,6 +86,9 @@ static const float CHEER_TIME = 1.0f;
 
 /** if Tux cannot unduck for this long, he will get hurt */
 static const float UNDUCK_HURT_TIME = 0.25f;
+/** gravity is higher after the jump key is released before
+    the apex of the jump is reached */
+static const float JUMP_EARLY_APEX_FACTOR = 3.0;
 
 namespace{
   bool no_water = true;
@@ -108,9 +111,8 @@ Player::Player(PlayerStatus* _player_status, const std::string& name)
   sound_manager->preload("sounds/hurt.wav");
   sound_manager->preload("sounds/skid.wav");
   sound_manager->preload("sounds/flip.wav");
-  sound_manager->preload("sounds/invincible.wav");
+  sound_manager->preload("sounds/invincible_start.ogg");
   sound_manager->preload("sounds/splash.ogg");
-  sound_manager->preload("sounds/shoot.wav");
 
   init();
 }
@@ -136,10 +138,12 @@ Player::init()
   dead = false;
 
   dying = false;
-  peeking = AUTO;
+  peekingX = AUTO;
+  peekingY = AUTO;
   last_ground_y = 0;
   fall_mode = ON_GROUND;
   jumping = false;
+  jump_early_apex = false;
   can_jump = true;
   wants_buttjump = false;
   does_buttjump = false;
@@ -341,12 +345,12 @@ Player::update(float elapsed_time)
       Vector paccel = Vector(0, 0);
       // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
       if (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) {
-       // make every other a longer sparkle to make trail a bit fuzzy
-       if (size_t(game_time*20)%2) {
-         Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
-       } else {
-         Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
-       }
+        // make every other a longer sparkle to make trail a bit fuzzy
+        if (size_t(game_time*20)%2) {
+          Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+        } else {
+          Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+        }
       } else {
         Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
       }
@@ -567,6 +571,24 @@ Player::do_jump(float yspeed) {
 }
 
 void
+Player::early_jump_apex() {
+  if(jump_early_apex) {
+    return;
+  }
+  jump_early_apex = true;
+  physic.set_gravity(physic.get_gravity() * JUMP_EARLY_APEX_FACTOR);
+};
+
+void
+Player::do_jump_apex() {
+  if(!jump_early_apex) {
+    return;
+  }
+  jump_early_apex = false;
+  physic.set_gravity(physic.get_gravity() / JUMP_EARLY_APEX_FACTOR);
+}
+
+void
 Player::handle_vertical_input()
 {
   // Press jump key
@@ -583,10 +605,14 @@ Player::handle_vertical_input()
   else if(!controller->hold(Controller::JUMP)) {
     if (!backflipping && jumping && physic.get_velocity_y() < 0) {
       jumping = false;
-      physic.set_velocity_y(0);
+      early_jump_apex();
     }
   }
 
+  if(jump_early_apex && physic.get_velocity_y() >= 0) {
+    do_jump_apex();
+  }
+
   /* In case the player has pressed Down while in a certain range of air,
      enable butt jump action */
   if (controller->hold(Controller::DOWN) && !duck && is_big() && !on_ground()) {
@@ -625,28 +651,29 @@ Player::handle_input()
 
   /* Peeking */
   if( controller->released( Controller::PEEK_LEFT ) ) {
-    peeking = AUTO;
+    peekingX = AUTO;
   }
   if( controller->released( Controller::PEEK_RIGHT ) ) {
-    peeking = AUTO;
+    peekingX = AUTO;
   }
-  if( controller->released( Controller::UP ) ) {
-    peeking = AUTO;
+  if( controller->released( Controller::PEEK_UP ) ) {
+    peekingY = AUTO;
   }
-  if( controller->released( Controller::DOWN ) ) {
-    peeking = AUTO;
+  if( controller->released( Controller::PEEK_DOWN ) ) {
+    peekingY = AUTO;
   }
   if( controller->pressed( Controller::PEEK_LEFT ) ) {
-    peeking = LEFT;
+    peekingX = LEFT;
   }
   if( controller->pressed( Controller::PEEK_RIGHT ) ) {
-    peeking = RIGHT;
+    peekingX = RIGHT;
   }
-  if( controller->pressed( Controller::UP ) ) {
-    peeking = UP;
-  }
-  if( controller->pressed( Controller::DOWN ) ) {
-    peeking = DOWN;
+  if(!backflipping && !jumping && on_ground()) {
+    if( controller->pressed( Controller::PEEK_UP ) ) {
+      peekingY = UP;
+    } else if( controller->pressed( Controller::PEEK_DOWN ) ) {
+      peekingY = DOWN;
+    }
   }
 
   /* Handle horizontal movement: */
@@ -1088,7 +1115,7 @@ Player::collision(GameObject& other, const CollisionHit& hit)
 void
 Player::make_invincible()
 {
-  sound_manager->play("sounds/invincible.wav");
+  sound_manager->play("sounds/invincible_start.ogg");
   invincible_timer.start(TUX_INVINCIBLE_TIME);
   Sector::current()->play_music(HERRING_MUSIC);
 }
@@ -1120,6 +1147,7 @@ Player::kill(bool completely)
       safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
       adjust_height(30.8f);
       duck = false;
+      backflipping = false;
       set_bonus(NO_BONUS, true);
     } else if(player_status->bonus == NO_BONUS) {
       safe_timer.start(TUX_SAFE_TIME);