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 static const float SPEED_GROW = 256;
26 static const float SPEED_SHRINK = 128;
28 Root::Root(const Vector& pos)
29 : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
30 mystate(STATE_APPEARING), offset_y(0)
32 base_sprite.reset(sprite_manager->create("images/creatures/ghosttree/root-base.sprite"));
33 base_sprite->set_action("appearing", 1);
34 base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action
35 physic.enable_gravity(false);
45 set_group(COLGROUP_TOUCHABLE);
55 Root::active_update(float elapsed_time)
57 if (mystate == STATE_APPEARING) {
58 if (base_sprite->animation_done()) mystate = STATE_GROWING;
60 else if (mystate == STATE_GROWING) {
61 offset_y -= elapsed_time * SPEED_GROW;
62 if (offset_y < -sprite->get_height()) {
63 offset_y = -sprite->get_height();
64 mystate = STATE_SHRINKING;
66 set_pos(start_position + Vector(0, offset_y));
68 else if (mystate == STATE_SHRINKING) {
69 offset_y += elapsed_time * SPEED_SHRINK;
72 mystate = STATE_VANISHING;
73 base_sprite->set_action("vanishing", 2);
74 base_sprite->set_animation_loops(2); // TODO: doesn't seem to work for loops=1
76 set_pos(start_position + Vector(0, offset_y));
78 else if (mystate == STATE_VANISHING) {
79 if (base_sprite->animation_done()) remove_me();
81 BadGuy::active_update(elapsed_time);
85 Root::draw(DrawingContext& context)
87 base_sprite->draw(context, start_position, LAYER_TILES+1);
88 if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context);