update
[supertux.git] / src / player.c
index 759bb82..1f876f3 100644 (file)
@@ -31,6 +31,16 @@ skidfiretux_right,  skidfiretux_left,
 cape_right[2],  cape_left[2],
 bigcape_right[2],  bigcape_left[2];
 
+void player_input_init(player_input_type* pplayer_input)
+{
+  pplayer_input->down = UP;
+  pplayer_input->fire = UP;
+  pplayer_input->left = UP;
+  pplayer_input->old_fire = UP;
+  pplayer_input->right = UP;
+  pplayer_input->up = UP;
+}
+
 void player_init(player_type* pplayer)
 {
   pplayer->base.width = 32;
@@ -43,6 +53,7 @@ void player_init(player_type* pplayer)
   pplayer->base.y = 240;
   pplayer->base.xm = 0;
   pplayer->base.ym = 0;
+  pplayer->old_base = pplayer->base;
   pplayer->dir = RIGHT;
   pplayer->duck = NO;
 
@@ -52,13 +63,10 @@ void player_init(player_type* pplayer)
   pplayer->frame_main = 0;
   pplayer->frame = 0;
   pplayer->lives = 3;
+  pplayer->score = 0;
+  pplayer->distros = 0;
 
-  pplayer->input.down = UP;
-  pplayer->input.fire = UP;
-  pplayer->input.left = UP;
-  pplayer->input.old_fire = UP;
-  pplayer->input.right = UP;
-  pplayer->input.up = UP;
+  player_input_init(&pplayer->input);
 
   pplayer->keymap.jump = SDLK_UP;
   pplayer->keymap.duck = SDLK_DOWN;
@@ -66,9 +74,12 @@ void player_init(player_type* pplayer)
   pplayer->keymap.right = SDLK_RIGHT;
   pplayer->keymap.fire = SDLK_LCTRL;
 
-  timer_init(&pplayer->invincible_timer);
-  timer_init(&pplayer->skidding_timer);
-  timer_init(&pplayer->safe_timer);
+  timer_init(&pplayer->invincible_timer,YES);
+  timer_init(&pplayer->skidding_timer,YES);
+  timer_init(&pplayer->safe_timer,YES);
+  timer_init(&pplayer->frame_timer,YES);
+  physic_init(&pplayer->hphysic);
+  physic_init(&pplayer->vphysic);
 }
 
 int player_key_event(player_type* pplayer, SDLKey key, int state)
@@ -108,29 +119,35 @@ void player_level_begin(player_type* pplayer)
   pplayer->base.y = 240;
   pplayer->base.xm = 0;
   pplayer->base.ym = 0;
+  pplayer->old_base = pplayer->base;
 
-  pplayer->input.down = UP;
-  pplayer->input.fire = UP;
-  pplayer->input.left = UP;
-  pplayer->input.old_fire = UP;
-  pplayer->input.right = UP;
-  pplayer->input.up = UP;
+  player_input_init(&pplayer->input);
 
-  timer_init(&pplayer->invincible_timer);
-  timer_init(&pplayer->skidding_timer);
-  timer_init(&pplayer->safe_timer);
+  timer_init(&pplayer->invincible_timer,YES);
+  timer_init(&pplayer->skidding_timer,YES);
+  timer_init(&pplayer->safe_timer,YES);
+  timer_init(&pplayer->frame_timer,YES);
+  physic_init(&pplayer->hphysic);
+  physic_init(&pplayer->vphysic);
 }
 
 void player_action(player_type* pplayer)
 {
+  int i, jumped_in_solid;
+  jumped_in_solid = NO;
+
   /* --- HANDLE TUX! --- */
 
   player_input(pplayer);
 
   /* Move tux: */
 
-  pplayer->base.x= pplayer->base.x+ pplayer->base.xm * frame_ratio;
-  pplayer->base.y = pplayer->base.y + pplayer->base.ym * frame_ratio;
+  pplayer->previous_base = pplayer->base;
+
+  pplayer->base.x += pplayer->base.xm * frame_ratio;
+  pplayer->base.y += pplayer->base.ym * frame_ratio;
+
+  collision_swept_object_map(&pplayer->old_base,&pplayer->base);
 
   player_keep_in_bounds(pplayer);
 
@@ -138,445 +155,224 @@ void player_action(player_type* pplayer)
 
   if (!pplayer->dying)
     {
-      /* FIXME: this code is COMPLETLY broken!!! */
-       /* if (issolid(pplayer->base.x, pplayer->base.y + 31) &&
-            !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y + 31))
-          {
-            while (issolid(pplayer->base.x, pplayer->base.y + 31))
-              {
-                if (pplayer->base.xm < 0)
-                  pplayer->base.x++;
-                else if (pplayer->base.xm > 0)
-                  pplayer->base.x--;
-              }
-
-            pplayer->base.xm = 0;
-          }*/
-
-        /*if (issolid(pplayer->base.x, pplayer->base.y) &&
-            !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y))
-          {
-            while (issolid(pplayer->base.x, (pplayer->base.y)))
-              {
-                if (pplayer->base.xm < 0)
-                  pplayer->base.x++;
-                else if (pplayer->base.xm > 0)
-                  pplayer->base.x--;
-              }
-
-            pplayer->base.xm = 0;
-          }*/
-
-        if (issolid(pplayer->base.x, pplayer->base.y + 31))
-          {
-            /* Set down properly: */
-
-            int debug_int = 0;
-            while (issolid(pplayer->base.x, pplayer->base.y + 31))
-              {
-                ++debug_int;
-                if(debug_int > 32)
-                  {
-                    DEBUG_MSG("FIXME - UNDER certain circumstances I'm hanging in a loop here!");
-                    /*the circumstances are:
-                    issolid() is true and base.ym == 0
-                    use of floating point varibles for base stuff*/
-                    break;
-                  }
-                if (pplayer->base.ym < 0)
-                  pplayer->base.y++;
-                else if (pplayer->base.ym > 0)
-                  pplayer->base.y--;
-              }
-
-
-            /* Reset score multiplier (for multi-hits): */
-
-            if (pplayer->base.ym > 0)
-              score_multiplier = 1;
-
-
-            /* Stop jumping! */
-
-      pplayer->base.ym = 0;
-      pplayer->jumping = NO;
-      pplayer->input.up = UP;
-      }
-            /* FIXME: this code is COMPLETLY broken!!! */
-      /*if (issolid(pplayer->base.x, pplayer->base.y) ||
-          (pplayer->size == BIG && !pplayer->duck &&
-           (issolid(pplayer->base.x, pplayer->base.y - 32))))
-        {*/
-      /*if (!issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y) &&
-          (pplayer->size == SMALL || pplayer->duck ||
-           !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32)))*/
-
-      if (((!issolid(pplayer->base.x, pplayer->base.y- pplayer->base.ym * frame_ratio) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x, pplayer->base.y+31))))
-      ||((!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y) && (issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)))))
-          /*(pplayer->size == SMALL || pplayer->duck ||
-           !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))*/
-        {
-          pplayer->base.y = pplayer->base.y- pplayer->base.ym * frame_ratio;
-          pplayer->base.ym = 0;
-        }
-          
-      if (((issolid(pplayer->base.x, pplayer->base.y) || issolid(pplayer->base.x+32, pplayer->base.y)) &&  (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y))
-          /*(pplayer->size == SMALL || pplayer->duck ||
-           !issolid(pplayer->base.x- pplayer->base.xm, pplayer->base.y - 32))*/) || 
-          (!issolid(pplayer->base.x - pplayer->base.xm * frame_ratio, pplayer->base.y+pplayer->base.height) && (issolid(pplayer->base.x, pplayer->base.y+pplayer->base.height) || issolid(pplayer->base.x +32, pplayer->base.y+pplayer->base.height))))
-        {
-         pplayer->base.x = pplayer->base.x- pplayer->base.xm * frame_ratio;
-          pplayer->base.xm = 0;
-        }
-       
-          if (pplayer->base.ym <= 0)
-            {
-      if (isbrick(pplayer->base.x, pplayer->base.y) ||
-          isfullbox(pplayer->base.x, pplayer->base.y))
-        {
-          trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
-          trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
-          bumpbrick(pplayer->base.x, pplayer->base.y);
-          tryemptybox(pplayer->base.x, pplayer->base.y);
-        }
 
-      if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
-          isfullbox(pplayer->base.x+ 31, pplayer->base.y))
-        {
-          trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
-          trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
-          bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
-          tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
-        }
-      /* Get a distro from a brick? */
 
-      if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
-          shape(pplayer->base.x, pplayer->base.y) == 'y')
+      if( !player_on_ground(pplayer))
         {
-          add_bouncy_distro(((pplayer->base.x+ 1)
-                             / 32) * 32,
-                            (int)(pplayer->base.y / 32) * 32);
-
-          if (counting_distros == NO)
+          if(player_under_solid(pplayer))
             {
-              counting_distros = YES;
-              distro_counter = 100;
+              physic_set_state(&pplayer->vphysic,PH_VT);
+              physic_set_start_vy(&pplayer->vphysic,0);
+              jumped_in_solid = YES;
             }
-
-          if (distro_counter <= 0)
-            level_change(&current_level,pplayer->base.x,pplayer->base.y, 'a');
-
-          play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
-          score = score + SCORE_DISTRO;
-          distros++;
-        }
-      else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
-               shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
-        {
-          add_bouncy_distro(((pplayer->base.x+ 1 + 31)
-                             / 32) * 32,
-                            (int)(pplayer->base.y / 32) * 32);
-
-          if (counting_distros == NO)
+          else
             {
-              counting_distros = YES;
-              distro_counter = 100;
+              if(!physic_is_set(&pplayer->vphysic))
+                {
+                  physic_set_state(&pplayer->vphysic,PH_VT);
+                  physic_set_start_vy(&pplayer->vphysic,0);
+                }
             }
+          pplayer->base.ym = physic_get_velocity(&pplayer->vphysic);
 
-          if (distro_counter <= 0)
-            level_change(&current_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
-
-          play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
-          score = score + SCORE_DISTRO;
-          distros++;
         }
-       
-       }
-       else
-{
-  pplayer->base.ym = 0;
-  pplayer->jumping = NO;
-  timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
-}
-  /*}*/
-  /* Bump into things: * /
-   
-  if (issolid(pplayer->base.x, pplayer->base.y) ||
-      (pplayer->size == BIG && !pplayer->duck &&
-       (issolid(pplayer->base.x, pplayer->base.y - 32))))
-    {
-   
-      if (!issolid(pplayer->base.x, pplayer->base.y - pplayer->base.ym) &&
-          (pplayer->size == SMALL || pplayer->duck ||
-           !issolid(pplayer->base.x, pplayer->base.y - 32 - pplayer->base.ym)))
+      else
         {
-          if (pplayer->base.ym <= 0)
-            {
-              /* Jumping up? */
-      /* FIXME: this code is COMPLETLY broken!!! */
-  if (pplayer->size == BIG)
-    {
-      /* Break bricks and empty boxes: * /
 
-      if (!pplayer->duck)
-        {
-          if (isbrick(pplayer->base.x, pplayer->base.y - 32) ||
-              isfullbox(pplayer->base.x, pplayer->base.y - 32))
-            {
-              trygrabdistro(pplayer->base.x, pplayer->base.y - 64, BOUNCE);
-              trybumpbadguy(pplayer->base.x, pplayer->base.y - 96);
+          /* Land: */
 
-              if (isfullbox(pplayer->base.x, pplayer->base.y - 32))
-                {
-                  bumpbrick(pplayer->base.x, pplayer->base.y - 32);
-                }
-
-              trybreakbrick(pplayer->base.x, pplayer->base.y - 32);
-              tryemptybox(pplayer->base.x, pplayer->base.y - 32);
+          if (pplayer->base.ym > 0)
+            {
+              pplayer->base.y = (int)(((int)pplayer->base.y / 32) * 32);
+              pplayer->base.ym = 0;
             }
 
-          if (isbrick(pplayer->base.x+ 31, pplayer->base.y - 32) ||
-              isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
-            {
-              trygrabdistro(pplayer->base.x+ 31,
-                            pplayer->base.y - 64,
-                            BOUNCE);
-              trybumpbadguy(pplayer->base.x+ 31,
-                            pplayer->base.y - 96);
+          physic_init(&pplayer->vphysic);
 
-              if (isfullbox(pplayer->base.x+ 31, pplayer->base.y - 32))
-                {
-                  bumpbrick(pplayer->base.x+ 31, pplayer->base.y - 32);
-                }
+          /* Reset score multiplier (for multi-hits): */
 
-              trybreakbrick(pplayer->base.x+ 31,
-                            pplayer->base.y - 32);
-              tryemptybox(pplayer->base.x+ 31,
-                          pplayer->base.y - 32);
-            }
+          score_multiplier = 1;
         }
-      else /* ducking * /
+
+      if(jumped_in_solid == YES)
         {
+
           if (isbrick(pplayer->base.x, pplayer->base.y) ||
               isfullbox(pplayer->base.x, pplayer->base.y))
             {
               trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
               trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
-              if (isfullbox(pplayer->base.x, pplayer->base.y))
-                bumpbrick(pplayer->base.x, pplayer->base.y);
-              trybreakbrick(pplayer->base.x, pplayer->base.y);
-              tryemptybox(pplayer->base.x, pplayer->base.y);
+
+              if(pplayer->size == BIG)
+                trybreakbrick(pplayer->base.x, pplayer->base.y);
+
+              bumpbrick(pplayer->base.x, pplayer->base.y);
+              tryemptybox(pplayer->base.x, pplayer->base.y, RIGHT);
             }
 
           if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
               isfullbox(pplayer->base.x+ 31, pplayer->base.y))
             {
-              trygrabdistro(pplayer->base.x+ 31,
-                            pplayer->base.y - 32,
-                            BOUNCE);
-              trybumpbadguy(pplayer->base.x+ 31,
-                            pplayer->base.y - 64);
-              if (isfullbox(pplayer->base.x+ 31, pplayer->base.y))
-                bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
-              trybreakbrick(pplayer->base.x+ 31, pplayer->base.y);
-              tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
-            }
-        }
-      }
-      else
-      {
-      /* It's a brick and we're small, make the brick
-         bounce, and grab any distros above it: * /
+              trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
+              trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
 
-      if (isbrick(pplayer->base.x, pplayer->base.y) ||
-          isfullbox(pplayer->base.x, pplayer->base.y))
-        {
-          trygrabdistro(pplayer->base.x, pplayer->base.y - 32,BOUNCE);
-          trybumpbadguy(pplayer->base.x, pplayer->base.y - 64);
-          bumpbrick(pplayer->base.x, pplayer->base.y);
-          tryemptybox(pplayer->base.x, pplayer->base.y);
-        }
+              if(pplayer->size == BIG)
+                trybreakbrick(pplayer->base.x+ 31, pplayer->base.y);
 
-      if (isbrick(pplayer->base.x+ 31, pplayer->base.y) ||
-          isfullbox(pplayer->base.x+ 31, pplayer->base.y))
-        {
-          trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32,BOUNCE);
-          trybumpbadguy(pplayer->base.x+ 31, pplayer->base.y - 64);
-          bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
-          tryemptybox(pplayer->base.x+ 31, pplayer->base.y);
-        }
+              bumpbrick(pplayer->base.x+ 31, pplayer->base.y);
+              tryemptybox(pplayer->base.x+ 31, pplayer->base.y, LEFT);
+            }
 
 
-      /* Get a distro from a brick? * /
+          if(pplayer->size == SMALL)
+            {
+              /* Get a distro from a brick? */
 
-      if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
-          shape(pplayer->base.x, pplayer->base.y) == 'y')
-        {
-          add_bouncy_distro(((pplayer->base.x+ 1)
-                             / 32) * 32,
-                            (int)(pplayer->base.y / 32) * 32);
+              if (shape(pplayer->base.x, pplayer->base.y) == 'x' ||
+                  shape(pplayer->base.x, pplayer->base.y) == 'y')
+                {
+                  add_bouncy_distro((((int)pplayer->base.x)
+                                     / 32) * 32,
+                                    ((int)pplayer->base.y / 32) * 32);
+                  if (counting_distros == NO)
+                    {
+                      counting_distros = YES;
+                      distro_counter = 100;
+                    }
 
-          if (counting_distros == NO)
-            {
-              counting_distros = YES;
-              distro_counter = 100;
-            }
+                  if (distro_counter <= 0)
+                    level_change(&current_level,pplayer->base.x,pplayer->base.y - 1, 'a');
 
-          if (distro_counter <= 0)
-            level_change(&current_level,pplayer->base.x,pplayer->base.y, 'a');
+                  play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
+                  score = score + SCORE_DISTRO;
+                  distros++;
+                }
+              else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
+                       shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
+                {
+                  add_bouncy_distro((((int)pplayer->base.x + 31)
+                                     / 32) * 32,
+                                    ((int)pplayer->base.y / 32) * 32);
+                  if (counting_distros == NO)
+                    {
+                      counting_distros = YES;
+                      distro_counter = 100;
+                    }
+
+                  if (distro_counter <= 0)
+                    level_change(&current_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
 
-          play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
-          score = score + SCORE_DISTRO;
-          distros++;
+                  play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
+                  score = score + SCORE_DISTRO;
+                  distros++;
+                }
+            }
         }
-      else if (shape(pplayer->base.x+ 31, pplayer->base.y) == 'x' ||
-               shape(pplayer->base.x+ 31, pplayer->base.y) == 'y')
-        {
-          add_bouncy_distro(((pplayer->base.x+ 1 + 31)
-                             / 32) * 32,
-                            (int)(pplayer->base.y / 32) * 32);
 
-          if (counting_distros == NO)
+      player_grabdistros(pplayer);
+      if(jumped_in_solid == YES)
+        {
+          ++pplayer->base.y;
+          ++pplayer->old_base.y;
+          if(player_on_ground(pplayer))
             {
-              counting_distros = YES;
-              distro_counter = 100;
+              /* Make sure jumping is off. */
+              pplayer->jumping = NO;
             }
-
-          if (distro_counter <= 0)
-            level_change(&current_level,pplayer->base.x+ 31, pplayer->base.y, 'a');
-
-          play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
-          score = score + SCORE_DISTRO;
-          distros++;
         }
-      }
-
-
-      /* Bump head: * /
 
-      pplayer->base.y = (int)(pplayer->base.y / 32) * 32 + 30;
-      }
-      else
-      {
-      /* Land on feet: * /
-
-      pplayer->base.y = (int)(pplayer->base.y / 32) * 32 - 32;
-      }
-
-      pplayer->base.ym = 0;
-      pplayer->jumping = NO;
-      timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
-      }*/
     }
-}
-
-
 
-player_grabdistros(pplayer);
+  timer_check(&pplayer->safe_timer);
 
 
-/* Slow down horizontally: */
+  /* ---- DONE HANDLING TUX! --- */
 
-if (!pplayer->dying)
-  {
-    if (pplayer->input.right == UP && pplayer->input.left == UP)
-      {
-        if (isice(pplayer->base.x, pplayer->base.y + 32) ||
-            !issolid(pplayer->base.x, pplayer->base.y + 32))
-          {
-            /* Slowly on ice or in air: */
+  /* Handle invincibility timer: */
 
-            if (pplayer->base.xm > 0)
-              pplayer->base.xm--;
-            else if (pplayer->base.xm < 0)
-              pplayer->base.xm++;
-          }
-        else
-          {
-            /* Quickly, otherwise: */
 
-            pplayer->base.xm = pplayer->base.xm / 2;
-          }
-      }
-
-
-    /* Drop vertically: */
-
-    if (!issolid(pplayer->base.x, pplayer->base.y + 32))
-      {
-        pplayer->base.ym = pplayer->base.ym + GRAVITY;
-
-        if (pplayer->base.ym > MAX_YM)
-          pplayer->base.ym = MAX_YM;
-      }
-  }
-
-
-
-timer_check(&pplayer->safe_timer);
-
-
-/* ---- DONE HANDLING TUX! --- */
-
-/* Handle invincibility timer: */
+  if (get_current_music() == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
+    {
+      /*
+         no, we are no more invincible
+         or we were not in invincible mode
+         but are we in hurry ?
+       */
 
 
-if (current_music == HERRING_MUSIC && !timer_check(&pplayer->invincible_timer))
-  {
-    /*
-       no, we are no more invincible
-       or we were not in invincible mode
-       but are we in hurry ?
-     */
+      if (timer_get_left(&time_left) < TIME_WARNING)
+        {
+          /* yes, we are in hurry
+             stop the herring_song, prepare to play the correct
+             fast level_song !
+           */
+          set_current_music(HURRYUP_MUSIC);
+        }
+      else
+        {
+          set_current_music(LEVEL_MUSIC);
+        }
 
+      /* start playing it */
+      play_current_music();
+    }
 
-    if (timer_get_left(&time_left) < TIME_WARNING)
-      {
-        /* yes, we are in hurry
-           stop the herring_song, prepare to play the correct
-           fast level_song !
-         */
-        current_music = HURRYUP_MUSIC;
-      }
-    else
-      {
-        current_music = LEVEL_MUSIC;
-      }
+  /* Handle skidding: */
 
-    /* stop the old music if it's being played */
-    if (playing_music())
-      halt_music();
-  }
+  timer_check(&pplayer->skidding_timer);
 
-/* Handle skidding: */
+  /* End of level? */
 
-timer_check(&pplayer->skidding_timer);
+  if (pplayer->base.x >= endpos && endpos != 0)
+    {
+      next_level = 1;
+    }
 
-/* End of level? */
+}
 
-if (pplayer->base.x - scroll_x >= endpos && endpos != 0)
-  {
-    next_level = 1;
-  }
+int player_on_ground(player_type *pplayer)
+{
+  if( issolid(pplayer->base.x + pplayer->base.width / 2, pplayer->base.y + pplayer->base.height) ||
+      issolid(pplayer->base.x + 1, pplayer->base.y + pplayer->base.height) ||
+      issolid(pplayer->base.x + pplayer->base.width - 1, pplayer->base.y + pplayer->base.height)  )
+    {
+      return YES;
+    }
+  else
+    {
+      return NO;
+    }
+}
 
+int player_under_solid(player_type *pplayer)
+{
+  if( issolid(pplayer->base.x + pplayer->base.width / 2, pplayer->base.y) ||
+      issolid(pplayer->base.x + 1, pplayer->base.y) ||
+      issolid(pplayer->base.x + pplayer->base.width - 1, pplayer->base.y)  )
+    {
+      return YES;
+    }
+  else
+    {
+      return NO;
+    }
 }
 
 void player_handle_horizontal_input(player_type *pplayer, int dir)
 {
-  if (pplayer->jumping == NO)
+
+  if ((dir ? (pplayer->base.xm < -SKID_XM) : (pplayer->base.xm > SKID_XM)) && !timer_started(&pplayer->skidding_timer) &&
+      pplayer->dir == !dir && player_on_ground(pplayer))
     {
-      if ((dir ? (pplayer->base.xm < -SKID_XM) : (pplayer->base.xm > SKID_XM)) && !timer_started(&pplayer->skidding_timer) &&
-          pplayer->dir == !dir)
-        {
-          timer_start(&pplayer->skidding_timer, SKID_TIME);
+      timer_start(&pplayer->skidding_timer, SKID_TIME);
 
-          play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
+      play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
 
-        }
-      pplayer->dir = dir;
     }
+  pplayer->dir = dir;
+
 
-  if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + 32) &&
+  if ((dir ? (pplayer->base.xm < 0) : (pplayer->base.xm > 0)) && !isice(pplayer->base.x, pplayer->base.y + pplayer->base.height) &&
       !timer_started(&pplayer->skidding_timer))
     {
       pplayer->base.xm = 0;
@@ -643,31 +439,16 @@ void player_handle_horizontal_input(player_type *pplayer, int dir)
 
 void player_handle_vertical_input(player_type *pplayer)
 {
-  if(!timer_started(&pplayer->jump_timer))
+  if(pplayer->input.up == DOWN)
     {
-      timer_start(&pplayer->jump_timer,MAX_JUMP_TIME);
-
-
-      /* Taking off? */
-
-      if (!issolid(pplayer->base.x, pplayer->base.y + 32) ||
-          pplayer->base.ym != 0)
+      if (player_on_ground(pplayer))
         {
-          /* If they're not on the ground, or are currently moving
-          vertically, don't jump! */
-
-          pplayer->jumping = NO;
-          timer_stop(&pplayer->jump_timer);
-        }
-      else
-        {
-          /* Make sure we're not standing back up into a solid! */
-
-          if (pplayer->size == SMALL || pplayer->duck == NO ||
-              !issolid(pplayer->base.x, pplayer->base.y))
+          if(!physic_is_set(&pplayer->vphysic))
             {
+              physic_set_state(&pplayer->vphysic,PH_VT);
+              physic_set_start_vy(&pplayer->vphysic,5.5);
+              --pplayer->base.y;
               pplayer->jumping = YES;
-
               if (pplayer->size == SMALL)
                 play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
               else
@@ -675,14 +456,32 @@ void player_handle_vertical_input(player_type *pplayer)
             }
         }
     }
-
-  /* Keep jumping for a while: */
-
-  if (timer_check(&pplayer->jump_timer))
+  else if(pplayer->input.up == UP && pplayer->jumping == YES)
     {
-      pplayer->base.ym = pplayer->base.ym - JUMP_SPEED * frame_ratio;
-      if (pplayer->base.ym < -YM_FOR_JUMP)
-        pplayer->base.ym = -YM_FOR_JUMP;
+      if (player_on_ground(pplayer))
+        {
+          physic_init(&pplayer->vphysic);
+          pplayer->jumping == NO;
+        }
+      else
+        {
+          pplayer->jumping = NO;
+          if(physic_is_set(&pplayer->vphysic))
+            {
+              if(physic_get_velocity(&pplayer->vphysic) < 0.)
+                {
+                  physic_set_state(&pplayer->vphysic,PH_VT);
+                  physic_set_start_vy(&pplayer->vphysic,0);
+                }
+            }
+          else
+            {
+              if(!physic_is_set(&pplayer->vphysic))
+                {
+                  physic_set_state(&pplayer->vphysic,PH_VT);
+                }
+            }
+        }
     }
 }
 
@@ -690,24 +489,39 @@ void player_input(player_type *pplayer)
 {
   /* Handle key and joystick state: */
 
-
-  if (pplayer->input.right == DOWN && pplayer->input.left == UP)
+  if(pplayer->duck == NO)
     {
-      player_handle_horizontal_input(pplayer,RIGHT);
-    }
-  else if (pplayer->input.left == DOWN && pplayer->input.right == UP)
-    {
-      player_handle_horizontal_input(pplayer,LEFT);
+      if (pplayer->input.right == DOWN && pplayer->input.left == UP)
+        {
+          player_handle_horizontal_input(pplayer,RIGHT);
+        }
+      else if (pplayer->input.left == DOWN && pplayer->input.right == UP)
+        {
+          player_handle_horizontal_input(pplayer,LEFT);
+        }
+      else
+        {
+          if(pplayer->base.xm > 0)
+            {
+              pplayer->base.xm = (int)(pplayer->base.xm - frame_ratio);
+              if(pplayer->base.xm < 0)
+                pplayer->base.xm = 0;
+            }
+          else if(pplayer->base.xm < 0)
+            {
+              pplayer->base.xm = (int)(pplayer->base.xm + frame_ratio);
+              if(pplayer->base.xm > 0)
+                pplayer->base.xm = 0;
+            }
+        }
     }
 
   /* Jump/jumping? */
 
-  if ( pplayer->input.up == DOWN)
+  if ( pplayer->input.up == DOWN || (pplayer->input.up == UP && pplayer->jumping == YES))
     {
       player_handle_vertical_input(pplayer);
     }
-  else
-    timer_stop(&pplayer->jump_timer);
 
   /* Shoot! */
 
@@ -721,39 +535,61 @@ void player_input(player_type *pplayer)
 
   if (pplayer->input.down == DOWN)
     {
-      if (pplayer->size == BIG)
-        pplayer->duck = YES;
+      if (pplayer->size == BIG && pplayer->duck != YES)
+        {
+          pplayer->duck = YES;
+          pplayer->base.height = 32;
+          pplayer->base.y += 32;
+        }
     }
   else
     {
       if (pplayer->size == BIG && pplayer->duck == YES)
         {
           /* Make sure we're not standing back up into a solid! */
+          pplayer->base.height = 64;
+          pplayer->base.y -= 32;
 
-          if (!issolid(pplayer->base.x, pplayer->base.y - 32))
-            pplayer->duck = NO;
+          if (!collision_object_map(&pplayer->base) /*issolid(pplayer->base.x + 16, pplayer->base.y - 16)*/)
+            {
+              pplayer->duck = NO;
+              pplayer->base.height = 64;
+              pplayer->old_base.y -= 32;
+              pplayer->old_base.height = 64;
+            }
+          else
+            {
+              pplayer->base.height = 32;
+              pplayer->base.y += 32;
+            }
         }
       else
-        pplayer->duck = NO;
+        {
+          pplayer->duck = NO;
+        }
     }
 
   /* (Tux): */
 
-  if (pplayer->input.right == UP && pplayer->input.left == UP)
+  if(!timer_check(&pplayer->frame_timer))
     {
-      pplayer->frame_main = 1;
-      pplayer->frame = 1;
-    }
-  else
-    {
-      if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
-          (frame % 4) == 0)
-        pplayer->frame_main = (pplayer->frame_main + 1) % 4;
+      timer_start(&pplayer->frame_timer,25);
+      if (pplayer->input.right == UP && pplayer->input.left == UP)
+        {
+          pplayer->frame_main = 1;
+          pplayer->frame = 1;
+        }
+      else
+        {
+          if ((pplayer->input.fire == DOWN && (frame % 2) == 0) ||
+              (frame % 4) == 0)
+            pplayer->frame_main = (pplayer->frame_main + 1) % 4;
 
-      pplayer->frame = pplayer->frame_main;
+          pplayer->frame = pplayer->frame_main;
 
-      if (pplayer->frame == 3)
-        pplayer->frame = 1;
+          if (pplayer->frame == 3)
+            pplayer->frame = 1;
+        }
     }
 
 }
@@ -766,11 +602,15 @@ void player_grabdistros(player_type *pplayer)
       trygrabdistro(pplayer->base.x, pplayer->base.y, NO_BOUNCE);
       trygrabdistro(pplayer->base.x+ 31, pplayer->base.y, NO_BOUNCE);
 
-      if (pplayer->size == BIG && !pplayer->duck)
+      trygrabdistro(pplayer->base.x, pplayer->base.y + pplayer->base.height, NO_BOUNCE);
+      trygrabdistro(pplayer->base.x+ 31, pplayer->base.y + pplayer->base.height, NO_BOUNCE);
+
+      if(pplayer->size == BIG)
         {
-          trygrabdistro(pplayer->base.x, pplayer->base.y - 32, NO_BOUNCE);
-          trygrabdistro(pplayer->base.x+ 31, pplayer->base.y - 32, NO_BOUNCE);
+          trygrabdistro(pplayer->base.x, pplayer->base.y + pplayer->base.height / 2, NO_BOUNCE);
+          trygrabdistro(pplayer->base.x+ 31, pplayer->base.y + pplayer->base.height / 2, NO_BOUNCE);
         }
+
     }
 
 
@@ -845,13 +685,13 @@ void player_draw(player_type* pplayer)
               if (pplayer->dir == RIGHT)
                 {
                   texture_draw(&bigcape_right[frame % 2],
-                               pplayer->base.x- scroll_x, pplayer->base.y,
+                               pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                NO_UPDATE);
                 }
               else
                 {
                   texture_draw(&bigcape_left[frame % 2],
-                               pplayer->base.x-scroll_x, pplayer->base.y,
+                               pplayer->base.x-scroll_x - 8, pplayer->base.y,
                                NO_UPDATE);
                 }
             }
@@ -867,13 +707,13 @@ void player_draw(player_type* pplayer)
                           if (pplayer->dir == RIGHT)
                             {
                               texture_draw(&bigtux_right[pplayer->frame],
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                           else
                             {
                               texture_draw(&bigtux_left[pplayer->frame],
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                         }
@@ -882,13 +722,13 @@ void player_draw(player_type* pplayer)
                           if (pplayer->dir == RIGHT)
                             {
                               texture_draw(&bigtux_right_jump,
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                           else
                             {
                               texture_draw(&bigtux_left_jump,
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                         }
@@ -898,13 +738,13 @@ void player_draw(player_type* pplayer)
                       if (pplayer->dir == RIGHT)
                         {
                           texture_draw(&skidtux_right,
-                                       pplayer->base.x- scroll_x, pplayer->base.y,
+                                       pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                        NO_UPDATE);
                         }
                       else
                         {
                           texture_draw(&skidtux_left,
-                                       pplayer->base.x- scroll_x, pplayer->base.y,
+                                       pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                        NO_UPDATE);
                         }
                     }
@@ -913,12 +753,12 @@ void player_draw(player_type* pplayer)
                 {
                   if (pplayer->dir == RIGHT)
                     {
-                      texture_draw(&ducktux_right, pplayer->base.x- scroll_x, pplayer->base.y,
+                      texture_draw(&ducktux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
                                    NO_UPDATE);
                     }
                   else
                     {
-                      texture_draw(&ducktux_left, pplayer->base.x- scroll_x, pplayer->base.y,
+                      texture_draw(&ducktux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
                                    NO_UPDATE);
                     }
                 }
@@ -936,13 +776,13 @@ void player_draw(player_type* pplayer)
                           if (pplayer->dir == RIGHT)
                             {
                               texture_draw(&bigfiretux_right[pplayer->frame],
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                           else
                             {
                               texture_draw(&bigfiretux_left[pplayer->frame],
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                         }
@@ -951,13 +791,13 @@ void player_draw(player_type* pplayer)
                           if (pplayer->dir == RIGHT)
                             {
                               texture_draw(&bigfiretux_right_jump,
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                           else
                             {
                               texture_draw(&bigfiretux_left_jump,
-                                           pplayer->base.x- scroll_x, pplayer->base.y,
+                                           pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                            NO_UPDATE);
                             }
                         }
@@ -967,13 +807,13 @@ void player_draw(player_type* pplayer)
                       if (pplayer->dir == RIGHT)
                         {
                           texture_draw(&skidfiretux_right,
-                                       pplayer->base.x- scroll_x, pplayer->base.y,
+                                       pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                        NO_UPDATE);
                         }
                       else
                         {
                           texture_draw(&skidfiretux_left,
-                                       pplayer->base.x- scroll_x, pplayer->base.y,
+                                       pplayer->base.x- scroll_x - 8, pplayer->base.y,
                                        NO_UPDATE);
                         }
                     }
@@ -982,12 +822,12 @@ void player_draw(player_type* pplayer)
                 {
                   if (pplayer->dir == RIGHT)
                     {
-                      texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x, pplayer->base.y,
+                      texture_draw(&duckfiretux_right, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
                                    NO_UPDATE);
                     }
                   else
                     {
-                      texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x, pplayer->base.y,
+                      texture_draw(&duckfiretux_left, pplayer->base.x- scroll_x - 8, pplayer->base.y - 16,
                                    NO_UPDATE);
                     }
                 }
@@ -1025,7 +865,7 @@ void player_collision(player_type* pplayer, void* p_c_object, int c_object)
               else
                 {
                   pbad_c->dir = LEFT;
-                  pbad_c->base.x = pbad_c->base.x - 16;
+                  pbad_c->base.x = pbad_c->base.x - 32;
                 }
 
               timer_start(&pbad_c->timer,5000);
@@ -1059,8 +899,10 @@ void player_collision(player_type* pplayer, void* p_c_object, int c_object)
                       else
                         {
                           pbad_c->dying = FALLING;
-                          pbad_c->base.ym = -8;
                           play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
+                          add_score(pbad_c->base.x - scroll_x,
+                                    pbad_c->base.y,
+                                    25 * score_multiplier);
                         }
                     }
                 }
@@ -1074,8 +916,10 @@ void player_collision(player_type* pplayer, void* p_c_object, int c_object)
               else
                 {
                   pbad_c->dying = FALLING;
-                  pbad_c->base.ym = -8;
                   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
+                  add_score(pbad_c->base.x - scroll_x,
+                            pbad_c->base.y,
+                            25 * score_multiplier);
                 }
             }
           score_multiplier++;
@@ -1118,7 +962,7 @@ void player_kill(player_type* pplayer, int mode)
 
 void player_dying(player_type *pplayer)
 {
-  pplayer->base.ym = pplayer->base.ym + GRAVITY;
+  pplayer->base.ym = pplayer->base.ym + gravity;
 
   /* He died :^( */
 
@@ -1173,9 +1017,7 @@ void player_keep_in_bounds(player_type* pplayer)
 
   /* Keep in-bounds, vertically: */
 
-  if (pplayer->base.y < 0)
-    pplayer->base.y = 0;
-  else if (pplayer->base.y > screen->h)
+  if (pplayer->base.y > screen->h)
     {
       player_kill(&tux,KILL);
     }