Finally!!
[supertux.git] / src / player.cpp
index ddb8104..f95f163 100644 (file)
@@ -83,10 +83,7 @@ Player::init()
 
   frame_main = 0;
   frame_ = 0;
-  lives = 3;
-  score = 0;
-  distros = 0;
-
+  
   player_input_init(&input);
 
   keymap.jump  = SDLK_UP;
@@ -284,13 +281,6 @@ Player::action(double frame_ratio)
       play_current_music();
     }
 
-  /* End of level? */
-  if (base.x >= World::current()->get_level()->endpos
-      && World::current()->get_level()->endpos != 0)
-    {
-      player_status.next_level = 1;
-    }
-
   // check some timers
   skidding_timer.check();
   invincible_timer.check();
@@ -379,7 +369,20 @@ Player::handle_horizontal_input()
           ax = WALK_ACCELERATION_X * -1.5;
       }
   }
+
+  // if we're on ice slow down acceleration or deceleration
+  if (isice(base.x, base.y + base.height))
+  {
+    /* the acceleration/deceleration rate on ice is inversely proportional to
+     * the current velocity.
+     */
+
+    // increasing 1 will increase acceleration/deceleration rate
+    // decreasing 1 will decrease acceleration/deceleration rate
+    //  must stay above zero, though
+    if (ax != 0) ax *= 1 / fabs(vx);
+  }
+
   physic.set_velocity(vx, vy);
   physic.set_acceleration(ax, ay);
 }
@@ -491,11 +494,11 @@ Player::grabdistros()
     }
 
   /* Enough distros for a One-up? */
-  if (distros >= DISTROS_LIFEUP)
+  if (player_status.distros >= DISTROS_LIFEUP)
     {
-      distros = distros - DISTROS_LIFEUP;
-      if(lives < MAX_LIVES)
-        lives++;
+      player_status.distros = player_status.distros - DISTROS_LIFEUP;
+      if(player_status.lives < MAX_LIVES)
+        ++player_status.lives;
       /*We want to hear the sound even, if MAX_LIVES is reached*/
       play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
     }
@@ -710,9 +713,6 @@ Player::draw()
         }
     }
 
-  if(dying)
-    gold_text->drawf("Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1);
-
   if (debug_mode)
     fillrect(base.x - scroll_x, base.y, 32, 32, 75,75,75, 150);
 }
@@ -726,8 +726,8 @@ Player::collision(void* p_c_object, int c_object)
     {
     case CO_BADGUY:
       pbad_c = (BadGuy*) p_c_object;
-      /* Hurt the player if he just touched it: */
 
+     /* Hurt player if he touches a badguy */
       if (!pbad_c->dying && !dying &&
           !safe_timer.started() &&
           pbad_c->mode != HELD)
@@ -737,30 +737,24 @@ Player::collision(void* p_c_object, int c_object)
               pbad_c->mode = HELD;
               pbad_c->base.y-=8;
             }
+          else if (pbad_c->mode == FLAT)
+            {
+              // Don't get hurt if we're kicking a flat badguy!
+            }
           else if (pbad_c->mode == KICK)
             {
-              if (base.y < pbad_c->base.y - 16)
+              /* Hurt if you get hit by kicked laptop: */
+              if (!invincible_timer.started())
                 {
-                  /* Step on (stop being kicked) */
-
-                  pbad_c->mode = FLAT;
-                  play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
+                  kill(SHRINK);
                 }
               else
                 {
-                  /* Hurt if you get hit by kicked laptop: */
-                  if (!invincible_timer.started())
-                    {
-                      kill(SHRINK);
-                    }
-                  else
-                    {
-                      pbad_c->dying = DYING_FALLING;
-                      play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
-                      World::current()->add_score(pbad_c->base.x - scroll_x,
-                                                  pbad_c->base.y,
-                                                  25 * player_status.score_multiplier);
-                    }
+                   pbad_c->dying = DYING_FALLING;
+                   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
+                   World::current()->add_score(pbad_c->base.x - scroll_x,
+                                               pbad_c->base.y,
+                                               25 * player_status.score_multiplier);
                 }
             }
           else
@@ -815,9 +809,6 @@ Player::kill(int mode)
 void
 Player::is_dying()
 {
-  /* He died :^( */
-
-  --lives;
   remove_powerups();
   dying = DYING_NOT;
 }