Now the growings animation looks pretty cool :)
authorRicardo Cruz <rick2@aeiou.pt>
Fri, 4 Jun 2004 14:03:06 +0000 (14:03 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Fri, 4 Jun 2004 14:03:06 +0000 (14:03 +0000)
You can tweak its speed in the GROWING_TIME define on player.h (in ms).

It's strange, but I have to pass 'false' for the use_alpha parameter in Surface. Else, it wouldn't use alpha... Something is definitively wrong.

SVN-Revision: 1412

src/player.cpp
src/player.h
src/resources.cpp

index 32c70bb..b3ecd98 100644 (file)
 // 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;
@@ -116,7 +118,7 @@ Player::init()
 
   frame_main = 0;
   frame_ = 0;
-  
+
   player_input_init(&input);
 
   invincible_timer.init(true);
@@ -633,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;
 }
@@ -701,9 +703,9 @@ Player::draw(DrawingContext& context)
           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)
             {
index 78c22d9..e23c206 100644 (file)
@@ -85,8 +85,11 @@ extern Surface* tux_life;
 extern Sprite* smalltux_gameover;
 extern Sprite* smalltux_star;
 extern Sprite* largetux_star;
-extern Sprite* growingtux_left;
-extern Sprite* growingtux_right;
+
+#define GROWING_TIME 1000
+#define GROWING_FRAMES 7
+extern Surface* growingtux_left[GROWING_FRAMES];
+extern Surface* growingtux_right[GROWING_FRAMES];
 
 struct PlayerSprite
 {
index 921e4d5..d9a229d 100644 (file)
@@ -56,8 +56,15 @@ 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");
+  char img_name[1024];
+  for (int i = 0; i < GROWING_FRAMES; i++)
+  {
+    sprintf(img_name, "%s/images/shared/tux-grow-left-%i.png", datadir.c_str(), i+1);
+    growingtux_left[i] = new Surface(img_name, false);
+
+    sprintf(img_name, "%s/images/shared/tux-grow-right-%i.png", datadir.c_str(), i+1);
+    growingtux_right[i] = new Surface(img_name, false);
+  }
 
   smalltux.stand_left  = sprite_manager->load("smalltux-stand-left");
   smalltux.stand_right = sprite_manager->load("smalltux-stand-right");
@@ -247,6 +254,12 @@ void unloadshared(void)
 
   delete tux_life;
 
+  for (int i = 0; i < GROWING_FRAMES; i++)
+  {
+    delete growingtux_left[i];
+    delete growingtux_right[i];
+  }
+
   for (i = 0; i < NUM_SOUNDS; i++)
     free_chunk(sounds[i]);