Implemented Tux growing animation.
authorRicardo Cruz <rick2@aeiou.pt>
Thu, 27 May 2004 17:01:28 +0000 (17:01 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Thu, 27 May 2004 17:01:28 +0000 (17:01 +0000)
Bug: since the Sprite does not respect the frames order, it may not animate correctly. I think the best fix is to make Player object to take care of that using Surfaces.

SVN-Revision: 1341

src/gameloop.cpp
src/player.cpp
src/player.h
src/resources.cpp
src/special.cpp
src/sprite.h
src/world.cpp

index d42c205..c50f53b 100644 (file)
@@ -482,7 +482,7 @@ GameSession::check_end_conditions()
 void
 GameSession::action(double frame_ratio)
 {
-  if (exit_status == ES_NONE)
+  if (exit_status == ES_NONE && !world->get_tux()->growing_timer.check())
     {
       // Update Tux and the World
       world->action(frame_ratio);
index 04af10f..27d909e 100644 (file)
@@ -41,6 +41,8 @@ Surface* tux_life;
 Sprite* smalltux_gameover;
 Sprite* smalltux_star;
 Sprite* largetux_star;
+Sprite* growingtux_left;
+Sprite* growingtux_right;
 
 PlayerSprite smalltux;
 PlayerSprite largetux;
@@ -117,6 +119,7 @@ Player::init()
   frame_timer.init(true);
   kick_timer.init(true);
   shooting_timer.init(true);
+  growing_timer.init(true);
 
   physic.reset();
 }
@@ -171,6 +174,7 @@ Player::level_begin()
   skidding_timer.init(true);
   safe_timer.init(true);
   frame_timer.init(true);
+  growing_timer.init(true);
 
   physic.reset();
 }
@@ -569,7 +573,7 @@ Player::handle_input()
 }
 
 void
-Player::grow()
+Player::grow(bool animate)
 {
   if(size == BIG)
     return;
@@ -578,6 +582,9 @@ Player::grow()
   base.height = 64;
   base.y -= 32;
 
+  if(animate)
+    growing_timer.start((int)((growingtux_left->get_frames() / growingtux_left->get_fps()) * 1000));
+
   old_base = previous_base = base;
 }
 
@@ -659,7 +666,14 @@ Player::draw(Camera& viewport, int layer)
         }
       else
         {
-          if (duck && size != SMALL)
+          if(growing_timer.check())
+            {
+              if (dir == RIGHT)
+                growingtux_right->draw(pos);
+              else 
+                growingtux_left->draw(pos);
+            }
+          else if (duck && size != SMALL)
             {
               if (dir == RIGHT)
                 sprite->duck_right->draw(pos);
index d0a4cf0..21a00a2 100644 (file)
@@ -83,6 +83,8 @@ extern Surface* tux_life;
 extern Sprite* smalltux_gameover;
 extern Sprite* smalltux_star;
 extern Sprite* largetux_star;
+extern Sprite* growingtux_left;
+extern Sprite* growingtux_right;
 
 struct PlayerSprite
 {
@@ -142,6 +144,7 @@ public:
   Timer kick_timer;
   Timer shooting_timer;   // used to show the arm when Tux is shooting
   Timer dying_timer;
+  Timer growing_timer;
   Physic physic;
 
 public:
@@ -165,7 +168,7 @@ public:
   bool on_ground();
   bool under_solid();
   bool tiles_on_air(int tiles);
-  void grow();
+  void grow(bool animate);
   void move(const Vector& vector);
   bool is_dead() const
   { return dead; }
index 3d1c391..fcd4d62 100644 (file)
@@ -54,6 +54,9 @@ void loadshared()
   largetux_star = sprite_manager->load("largetux-star");
   smalltux_gameover = sprite_manager->load("smalltux-gameover");
 
+  growingtux_left = sprite_manager->load("tux-grow-left");
+  growingtux_right = sprite_manager->load("tux-grow-right");
+
   smalltux.stand_left  = sprite_manager->load("smalltux-stand-left");
   smalltux.stand_right = sprite_manager->load("smalltux-stand-right");
   smalltux.walk_left   = sprite_manager->load("smalltux-walk-left");
index 6bbbc7c..adfebe0 100644 (file)
@@ -343,24 +343,24 @@ Upgrade::collision(void* p_c_object, int c_object, CollisionType type)
       if (kind == UPGRADE_GROWUP)
         {
           play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
-          pplayer->grow();
+          pplayer->grow(true);
         }
       else if (kind == UPGRADE_FIREFLOWER)
         {
           play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
-          pplayer->grow();
+          pplayer->grow(true);
           pplayer->got_power = pplayer->FIRE_POWER;
         }
       else if (kind == UPGRADE_ICEFLOWER)
         {
           play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
-          pplayer->grow();
+          pplayer->grow(true);
           pplayer->got_power = pplayer->ICE_POWER;
         }
       else if (kind == UPGRADE_FIREFLOWER)
         {
           play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
-          pplayer->grow();
+          pplayer->grow(true);
           pplayer->got_power = pplayer->FIRE_POWER;
         }
       else if (kind == UPGRADE_HERRING)
index b85cedd..2a4acf3 100644 (file)
@@ -62,6 +62,9 @@ class Sprite
   void draw_part(float sx, float sy, float x, float y, float w, float h);
   int get_current_frame() const;
 
+  float get_fps() { return fps; } ;
+  int get_frames() { return surfaces.size(); } ;
+
   void draw(const Vector& pos, int special_drawing = SD_NONE)
   { draw(pos.x, pos.y, special_drawing); }
 
index fb85020..98b1ed5 100644 (file)
@@ -97,7 +97,7 @@ World::apply_bonuses()
       // fall through
                                                                                 
     case PlayerStatus::GROWUP_BONUS:
-      tux->grow();
+      tux->grow(false);
       break;
     }
 }