1 // SuperTux - "Will-O-Wisp" Badguy
2 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/root.hpp"
18 #include "sprite/sprite.hpp"
19 #include "sprite/sprite_manager.hpp"
21 static const float SPEED_GROW = 256;
22 static const float SPEED_SHRINK = 128;
23 static const float HATCH_TIME = 0.75;
25 Root::Root(const Vector& pos) :
26 BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
27 mystate(STATE_APPEARING),
32 base_sprite = 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);
36 set_colgroup_active(COLGROUP_TOUCHABLE);
51 Root::active_update(float elapsed_time)
53 if (mystate == STATE_APPEARING) {
54 if (base_sprite->animation_done()) {
55 hatch_timer.start(HATCH_TIME);
56 mystate = STATE_HATCHING;
59 if (mystate == STATE_HATCHING) {
60 if (!hatch_timer.started()) mystate = STATE_GROWING;
62 else if (mystate == STATE_GROWING) {
63 offset_y -= elapsed_time * SPEED_GROW;
64 if (offset_y < -sprite->get_height()) {
65 offset_y = -sprite->get_height();
66 mystate = STATE_SHRINKING;
68 set_pos(start_position + Vector(0, offset_y));
70 else if (mystate == STATE_SHRINKING) {
71 offset_y += elapsed_time * SPEED_SHRINK;
74 mystate = STATE_VANISHING;
75 base_sprite->set_action("vanishing", 2);
76 base_sprite->set_animation_loops(2); // TODO: doesn't seem to work for loops=1
78 set_pos(start_position + Vector(0, offset_y));
80 else if (mystate == STATE_VANISHING) {
81 if (base_sprite->animation_done()) remove_me();
83 BadGuy::active_update(elapsed_time);
87 Root::draw(DrawingContext& context)
89 base_sprite->draw(context, start_position, LAYER_TILES+1);
90 if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context);