From: Ricardo Cruz Date: Thu, 27 May 2004 17:01:28 +0000 (+0000) Subject: Implemented Tux growing animation. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=73d5a49c30eea598c9d3c06b69dbbbcd0d315dd1;p=supertux.git Implemented Tux growing animation. 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 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index d42c20522..c50f53b46 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -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); diff --git a/src/player.cpp b/src/player.cpp index 04af10f05..27d909e66 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -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); diff --git a/src/player.h b/src/player.h index d0a4cf03d..21a00a2dc 100644 --- a/src/player.h +++ b/src/player.h @@ -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; } diff --git a/src/resources.cpp b/src/resources.cpp index 3d1c391d8..fcd4d6296 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -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"); diff --git a/src/special.cpp b/src/special.cpp index 6bbbc7c9e..adfebe0f6 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -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) diff --git a/src/sprite.h b/src/sprite.h index b85cedda8..2a4acf355 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -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); } diff --git a/src/world.cpp b/src/world.cpp index fb850205b..98b1ed57c 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -97,7 +97,7 @@ World::apply_bonuses() // fall through case PlayerStatus::GROWUP_BONUS: - tux->grow(); + tux->grow(false); break; } }