3 // SuperTux - "Will-O-Wisp" Badguy
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "sprite/sprite_manager.hpp"
25 #include "sprite/sprite.hpp"
27 static const float SPEED_GROW = 256;
28 static const float SPEED_SHRINK = 128;
29 static const float HATCH_TIME = 0.75;
31 Root::Root(const Vector& pos)
32 : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
33 mystate(STATE_APPEARING), offset_y(0)
35 base_sprite.reset(sprite_manager->create("images/creatures/ghosttree/root-base.sprite"));
36 base_sprite->set_action("appearing", 1);
37 base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action
38 physic.enable_gravity(false);
39 set_colgroup_active(COLGROUP_TOUCHABLE);
53 Root::active_update(float elapsed_time)
55 if (mystate == STATE_APPEARING) {
56 if (base_sprite->animation_done()) {
57 hatch_timer.start(HATCH_TIME);
58 mystate = STATE_HATCHING;
61 if (mystate == STATE_HATCHING) {
62 if (!hatch_timer.started()) mystate = STATE_GROWING;
64 else if (mystate == STATE_GROWING) {
65 offset_y -= elapsed_time * SPEED_GROW;
66 if (offset_y < -sprite->get_height()) {
67 offset_y = -sprite->get_height();
68 mystate = STATE_SHRINKING;
70 set_pos(start_position + Vector(0, offset_y));
72 else if (mystate == STATE_SHRINKING) {
73 offset_y += elapsed_time * SPEED_SHRINK;
76 mystate = STATE_VANISHING;
77 base_sprite->set_action("vanishing", 2);
78 base_sprite->set_animation_loops(2); // TODO: doesn't seem to work for loops=1
80 set_pos(start_position + Vector(0, offset_y));
82 else if (mystate == STATE_VANISHING) {
83 if (base_sprite->animation_done()) remove_me();
85 BadGuy::active_update(elapsed_time);
89 Root::draw(DrawingContext& context)
91 base_sprite->draw(context, start_position, LAYER_TILES+1);
92 if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context);