From: Christoph Sommer Date: Sat, 26 May 2007 17:32:29 +0000 (+0000) Subject: Added to ghosttree: roots growing from below X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9598330d85ae6dae2ced6f7542b642288f094728;p=supertux.git Added to ghosttree: roots growing from below SVN-Revision: 5033 --- diff --git a/data/images/creatures/ghosttree/root-base-0.png b/data/images/creatures/ghosttree/root-base-0.png new file mode 100644 index 000000000..0d11710b9 Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-0.png differ diff --git a/data/images/creatures/ghosttree/root-base-1.png b/data/images/creatures/ghosttree/root-base-1.png new file mode 100644 index 000000000..1397890f4 Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-1.png differ diff --git a/data/images/creatures/ghosttree/root-base-2.png b/data/images/creatures/ghosttree/root-base-2.png new file mode 100644 index 000000000..6f99a5cf8 Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-2.png differ diff --git a/data/images/creatures/ghosttree/root-base-3.png b/data/images/creatures/ghosttree/root-base-3.png new file mode 100644 index 000000000..055ba09f1 Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-3.png differ diff --git a/data/images/creatures/ghosttree/root-base.sprite b/data/images/creatures/ghosttree/root-base.sprite new file mode 100644 index 000000000..edfa363a2 --- /dev/null +++ b/data/images/creatures/ghosttree/root-base.sprite @@ -0,0 +1,22 @@ +(supertux-sprite + (action + (name "appearing") + (fps 16) + (images + "root-base-0.png" + "root-base-1.png" + "root-base-2.png" + "root-base-3.png" + ) + ) + (action + (name "vanishing") + (fps 16) + (images + "root-base-3.png" + "root-base-2.png" + "root-base-1.png" + "root-base-0.png" + ) + ) +) diff --git a/src/badguy/ghosttree.cpp b/src/badguy/ghosttree.cpp index 250e05e4c..5fb5c492e 100644 --- a/src/badguy/ghosttree.cpp +++ b/src/badguy/ghosttree.cpp @@ -122,7 +122,7 @@ GhostTree::active_update(float elapsed_time) if(root_timer.check()) { /* TODO indicate root with an animation */ Player* player = get_nearest_player(); - Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom())); + Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()-64)); Sector::current()->add_object(root); } } diff --git a/src/badguy/root.cpp b/src/badguy/root.cpp index 4b94051fd..6fa949e20 100644 --- a/src/badguy/root.cpp +++ b/src/badguy/root.cpp @@ -20,14 +20,19 @@ #include #include "root.hpp" +#include "sprite/sprite_manager.hpp" -static const float SPEED = 5; +static const float SPEED_GROW = 256; +static const float SPEED_SHRINK = 128; Root::Root(const Vector& pos) - : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_OBJECTS+20), - ypos(0), speed(-SPEED) + : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1), + mystate(STATE_APPEARING), offset_y(0) { - //ypos = sprite->get_height(); + base_sprite.reset(sprite_manager->create("images/creatures/ghosttree/root-base.sprite")); + base_sprite->set_action("appearing", 1); + base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action + physic.enable_gravity(false); } Root::~Root() @@ -37,20 +42,49 @@ Root::~Root() void Root::activate() { - set_pos(start_position + Vector(0, ypos)); + set_group(COLGROUP_TOUCHABLE); +} + +void +Root::deactivate() +{ + remove_me(); } void Root::active_update(float elapsed_time) { - ypos += elapsed_time * speed; - if(ypos < 0) { - ypos = 0; - speed = -speed; + if (mystate == STATE_APPEARING) { + if (base_sprite->animation_done()) mystate = STATE_GROWING; + } + else if (mystate == STATE_GROWING) { + offset_y -= elapsed_time * SPEED_GROW; + if (offset_y < -sprite->get_height()) { + offset_y = -sprite->get_height(); + mystate = STATE_SHRINKING; + } + set_pos(start_position + Vector(0, offset_y)); } - if(speed > 0 && ypos > sprite->get_height()) { - remove_me(); + else if (mystate == STATE_SHRINKING) { + offset_y += elapsed_time * SPEED_SHRINK; + if (offset_y > 0) { + offset_y = 0; + mystate = STATE_VANISHING; + base_sprite->set_action("vanishing", 2); + base_sprite->set_animation_loops(2); // TODO: doesn't seem to work for loops=1 + } + set_pos(start_position + Vector(0, offset_y)); } - set_pos(start_position + Vector(0, ypos)); + else if (mystate == STATE_VANISHING) { + if (base_sprite->animation_done()) remove_me(); + } + BadGuy::active_update(elapsed_time); +} + +void +Root::draw(DrawingContext& context) +{ + base_sprite->draw(context, start_position, LAYER_TILES+1); + if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context); } diff --git a/src/badguy/root.hpp b/src/badguy/root.hpp index 93d641e4e..32ec2fa2e 100644 --- a/src/badguy/root.hpp +++ b/src/badguy/root.hpp @@ -19,6 +19,7 @@ #ifndef __ROOT_H__ #define __ROOT_H__ +#include #include "badguy.hpp" class Root : public BadGuy @@ -28,11 +29,20 @@ public: ~Root(); void activate(); + void deactivate(); void active_update(float elapsed_time); + virtual void draw(DrawingContext& context); + virtual bool is_flammable() const { return false; } + virtual bool is_freezable() const { return false; } + virtual void kill_fall() { } -private: - float ypos; - float speed; +protected: + enum MyState { + STATE_APPEARING, STATE_GROWING, STATE_SHRINKING, STATE_VANISHING + }; + MyState mystate; + std::auto_ptr base_sprite; + float offset_y; }; #endif