Now the growings animation looks pretty cool :)
[supertux.git] / src / player.cpp
index f9a6032..b3ecd98 100644 (file)
@@ -31,6 +31,7 @@
 #include "tilemap.h"
 #include "camera.h"
 #include "gameobjs.h"
+#include "resources.h"
 #include "interactive_object.h"
 #include "screen/screen.h"
 
 // others stuff:
 #define AUTOSCROLL_DEAD_INTERVAL 300
 
+// growing animation
+Surface* growingtux_left[GROWING_FRAMES];
+Surface* growingtux_right[GROWING_FRAMES];
+
 Surface* tux_life;
 
 Sprite* smalltux_gameover;
 Sprite* smalltux_star;
 Sprite* largetux_star;
-Sprite* growingtux_left;
-Sprite* growingtux_right;
 
 PlayerSprite smalltux;
 PlayerSprite largetux;
@@ -115,7 +118,7 @@ Player::init()
 
   frame_main = 0;
   frame_ = 0;
-  
+
   player_input_init(&input);
 
   invincible_timer.init(true);
@@ -413,7 +416,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);
-          play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
+          sound_manager->play_sound(sounds[SND_SKID]);
           ax *= 2.5;
       } else {
           ax *= 2;
@@ -480,9 +483,9 @@ Player::handle_vertical_input()
       jumping = true;
       can_jump = false;
       if (size == SMALL)
-        play_sound(sounds[SND_JUMP], SOUND_CENTER_SPEAKER);
+        sound_manager->play_sound(sounds[SND_JUMP]);
       else
-        play_sound(sounds[SND_BIGJUMP], SOUND_CENTER_SPEAKER);
+        sound_manager->play_sound(sounds[SND_BIGJUMP]);
     }
   // Let go of jump key
   else if(input.up == UP && jumping && physic.get_velocity_y() > 0)
@@ -632,7 +635,7 @@ Player::grow(bool animate)
   base.y -= 32;
 
   if(animate)
-    growing_timer.start((int)((growingtux_left->get_frames() / growingtux_left->get_fps()) * 1000));
+    growing_timer.start(GROWING_TIME);
 
   old_base = previous_base = base;
 }
@@ -668,7 +671,7 @@ Player::grabdistros()
       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);
+      sound_manager->play_sound(sounds[SND_LIFEUP]);
     }
 }
 
@@ -693,16 +696,16 @@ Player::draw(DrawingContext& context)
     {
       if (dying == DYING_SQUISHED)
         {
-          smalltux_gameover->draw(context, pos, LAYER_OBJECTS);
+          smalltux_gameover->draw(context, pos, LAYER_OBJECTS+1);
         }
       else
         {
           if(growing_timer.check())
             {
               if (dir == RIGHT)
-                growingtux_right->draw(context, pos, layer);
+                context.draw_surface(growingtux_right[(growing_timer.get_gone() * GROWING_FRAMES) / GROWING_TIME], pos, layer);
               else 
-                growingtux_left->draw(context, pos, layer);
+                context.draw_surface(growingtux_left[(growing_timer.get_gone() * GROWING_FRAMES) / GROWING_TIME], pos, layer);
             }
           else if (duck && size != SMALL)
             {
@@ -906,7 +909,7 @@ Player::kill(HurtMode mode)
   if(dying)
     return;
   
-  play_sound(sounds[SND_HURT], SOUND_CENTER_SPEAKER);
+  sound_manager->play_sound(sounds[SND_HURT]);
 
   physic.set_velocity_x(0);