- Cleanups
[supertux.git] / src / player.cpp
index b3ecd98..84d2f02 100644 (file)
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-#include <math.h>
+#include <cmath>
 #include <iostream>
 #include <cassert>
+
 #include "gameloop.h"
-#include "globals.h"
+#include "app/globals.h"
 #include "player.h"
 #include "defines.h"
 #include "scene.h"
 #include "tile.h"
-#include "sprite.h"
+#include "special/sprite.h"
 #include "sector.h"
 #include "tilemap.h"
 #include "camera.h"
 #include "gameobjs.h"
 #include "resources.h"
 #include "interactive_object.h"
-#include "screen/screen.h"
+#include "video/screen.h"
 
 // behavior definitions:
 #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 +117,8 @@ Player::init()
   jumping = false;
   can_jump = true;
   butt_jump = false;
-
+  
+  stomp_pos = Vector(0,0);
   frame_main = 0;
   frame_ = 0;
 
@@ -224,7 +227,7 @@ Player::action(float elapsed_time)
   if(dying == DYING_NOT)
     handle_input();
 
-  physic.apply(elapsed_time, base.x, base.y);
+  physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
 
   if(dying == DYING_NOT) 
     {
@@ -287,7 +290,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 +304,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));
 
@@ -416,7 +419,7 @@ Player::handle_horizontal_input()
   if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
       if(fabs(vx)>SKID_XM && !skidding_timer.check()) {
           skidding_timer.start(SKID_TIME);
-          sound_manager->play_sound(sounds[SND_SKID]);
+          SoundManager::get()->play_sound(IDToSound(SND_SKID));
           ax *= 2.5;
       } else {
           ax *= 2;
@@ -483,9 +486,9 @@ Player::handle_vertical_input()
       jumping = true;
       can_jump = false;
       if (size == SMALL)
-        sound_manager->play_sound(sounds[SND_JUMP]);
+        SoundManager::get()->play_sound(IDToSound(SND_JUMP));
       else
-        sound_manager->play_sound(sounds[SND_BIGJUMP]);
+        SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP));
     }
   // Let go of jump key
   else if(input.up == UP && jumping && physic.get_velocity_y() > 0)
@@ -496,7 +499,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 +510,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 +538,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 +659,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 +666,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);
@@ -671,7 +681,7 @@ Player::grabdistros()
       if(player_status.lives < MAX_LIVES)
         ++player_status.lives;
       /*We want to hear the sound even, if MAX_LIVES is reached*/
-      sound_manager->play_sound(sounds[SND_LIFEUP]);
+      SoundManager::get()->play_sound(IDToSound(SND_LIFEUP));
     }
 }
 
@@ -696,7 +706,7 @@ Player::draw(DrawingContext& context)
     {
       if (dying == DYING_SQUISHED)
         {
-          smalltux_gameover->draw(context, pos, LAYER_OBJECTS+1);
+          smalltux_gameover->draw(context, pos, LAYER_FOREGROUNDTILES+1);
         }
       else
         {
@@ -763,6 +773,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() &&
@@ -909,7 +923,7 @@ Player::kill(HurtMode mode)
   if(dying)
     return;
   
-  sound_manager->play_sound(sounds[SND_HURT]);
+  SoundManager::get()->play_sound(IDToSound(SND_HURT));
 
   physic.set_velocity_x(0);
 
@@ -992,3 +1006,18 @@ Player::check_bounds(Camera* camera)
   }
 }
 
+void
+Player::bounce(BadGuy* badguy)
+{
+  if (input.up)
+    physic.set_velocity_y(5.2);
+  else
+    physic.set_velocity_y(2);
+
+  // Move the player a little bit above the badguy to avoid collision
+  // between badguy and player directly after the bounce has happend
+  base.y = badguy->base.y - base.height - 2;
+}
+
+/* EOF */
+