From: Ricardo Cruz Date: Fri, 4 Jun 2004 14:03:06 +0000 (+0000) Subject: Now the growings animation looks pretty cool :) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=47a5722771f28336020c4995b4bba7051e43bd89;p=supertux.git Now the growings animation looks pretty cool :) 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 --- diff --git a/src/player.cpp b/src/player.cpp index 32c70bb81..b3ecd98cf 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -42,13 +42,15 @@ // 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) { diff --git a/src/player.h b/src/player.h index 78c22d9da..e23c2063b 100644 --- a/src/player.h +++ b/src/player.h @@ -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 { diff --git a/src/resources.cpp b/src/resources.cpp index 921e4d50a..d9a229d86 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -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]);