From 9598330d85ae6dae2ced6f7542b642288f094728 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sat, 26 May 2007 17:32:29 +0000 Subject: [PATCH] Added to ghosttree: roots growing from below SVN-Revision: 5033 --- data/images/creatures/ghosttree/root-base-0.png | Bin 0 -> 501 bytes data/images/creatures/ghosttree/root-base-1.png | Bin 0 -> 722 bytes data/images/creatures/ghosttree/root-base-2.png | Bin 0 -> 1028 bytes data/images/creatures/ghosttree/root-base-3.png | Bin 0 -> 1130 bytes data/images/creatures/ghosttree/root-base.sprite | 22 +++++++++ src/badguy/ghosttree.cpp | 2 +- src/badguy/root.cpp | 58 ++++++++++++++++++----- src/badguy/root.hpp | 16 +++++-- 8 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 data/images/creatures/ghosttree/root-base-0.png create mode 100644 data/images/creatures/ghosttree/root-base-1.png create mode 100644 data/images/creatures/ghosttree/root-base-2.png create mode 100644 data/images/creatures/ghosttree/root-base-3.png create mode 100644 data/images/creatures/ghosttree/root-base.sprite 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 0000000000000000000000000000000000000000..0d11710b95663b9be9df5b5a5b97c9de407a8c25 GIT binary patch literal 501 zcmeAS@N?(olHy`uVBq!ia0vp^3P2pr!3HE#W8Hg!6kC$Fy9>jA5L~c#`DCC7XMsm# zF#`j)FbFd;%$g$s6l5>)^mS#w&MGA!!E8MLiat!MP|ku_QG` zp**uBLm?z1Rl(iUH{gAWY90dvW2C2xV@Srmw>Nit9SIOP_A!1_QAAqo=NFFoZTKkpg?Ed<8kaSD;=6hk#JG3o2`PVWH<7fcnVEm?jAFY2 zN0Y(|F72;wn}YIHCU)ipXA8bQ%H#H-<+=^amn|K&4+QxuehPYTs#vEI**577XA@Av zqsV(U8f6^1`EQP2SuGN~QTs2ql9%WNH`S?ct6z#Osn=DWdZWtmgS}M1?plS5ztY{_ zF$H~@s;Y4Ea#NJF*q+C0UllKY%){a+5Rw#9e&x!pt8w;5g2@p_tojPOoA>PhlkN2_ zLCo6X$kb=8$7@%!)>WTaQF}Vc-p#Og;hWl~**3ZrM>jwFdr3yjU|whCAJY=~(%Y04w+m07*yfF`WCPyYq pAIp;5oyb4kLjQ0Z&{KUsS-ftjE?Bj(j2Rdk44$rjF6*2UngHZN$DsfK literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..1397890f4bc67d57a59b6ff650d758635b0f0317 GIT binary patch literal 722 zcmV;@0xkWCP)WFU8GbZ8({Xk{QrNlj4iWF>9@00K5iL_t(&-tE}EY7|iz z#_`{5Hh!TX5h0?{#zKo=AxTs$EGz^Q3%vmwiC9^Pcm)=s!PYC##zsX!3l#)Gj0vKs zl_E&AFo{u!k}r$A3(F!KA~UlIoIeaZJMS#>@P0h!?2t$#5{blWp?6>?>m3-%QYP}I ztx0SxcAx`)Fk6IxYLnOkeq$Ol4Y4fZg_1>vvN#fnL?V$WpPv4!#?kz7tWu;|gRg7LD(Xx&&r2E^Jh;N7oS1rCVnaNu~b&2?%I-&Cz zE?dAMbXj~I^Su=U_MDLpum-#1e7x@ZR*P@WvVX*KU5uWfJ&wI~ z*N@>K4o7nqR)Tx+IgdGUMVnDK9^w*u<9s$e z;XxT2k}r6K$M}SO@w++PFUyj*N9V7>SB&9Bh$++u>a$SA0er@5jN*OS+p9A%cBA+h z*%0L@ML;*EFcG8KflYW@)EG80iJ#GgoncNVaSrPvGllODGHeMmx{g<2O0zMd7jPEO z!$+h!zWJRLs<2A>>a-0E{+t{3zcQ~NN!V5qdgX> zt{B6~G6iI@3ijbB2C)mz%HFbH#=987X>2Q7z=?QpZQO3RLd3<`7t}<&EUN39G1y={ z6U!0NmVWFU8GbZ8({Xk{QrNlj4iWF>9@00U@AL_t(&-tC#&OH@%5 z#(!tV8O`#NLy(zWAV?`m3atprz^rvcB^pYAxBpTuXobjXN^b>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EU?=m z(4-U{XklC2={UeT^#W}Y{;l4R0c)(k8*@eARbUVB5-=Xx%gURKD*|hQcYv2wkc11; z5xuW*HBn|vrMh8@wZ0YFt5S6wJUJH{SZl4PLwjxNn$|_B zE6Phe_ad+#xUG(9P|b=r0*5uAn$UbGet3jD^6@=ciV!-_(gHvoR zSxy=79`LU9E|%c5+!c%geZZf+;GY#0mIV2 z@^-3c>``ra-uIO3GYzGtWrR(>3A`o2fxCUN8YDjEzcGF=J5Kv15gyx47DJ*e1_GC5 wn1Rr06)xv|YvPEa;!mv7@H#<)1PMyQzpg3zYYFs^;s5{u07*qoM6N<$g45aTUH||9 literal 0 HcmV?d00001 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 -- 2.11.0