| 1 | // SuperTux - "Will-O-Wisp" Badguy |
| 2 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
| 3 | // |
| 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. |
| 8 | // |
| 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. |
| 13 | // |
| 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/>. |
| 16 | |
| 17 | #include "badguy/root.hpp" |
| 18 | |
| 19 | #include "sprite/sprite.hpp" |
| 20 | #include "sprite/sprite_manager.hpp" |
| 21 | |
| 22 | static const float SPEED_GROW = 256; |
| 23 | static const float SPEED_SHRINK = 128; |
| 24 | static const float HATCH_TIME = 0.75; |
| 25 | |
| 26 | Root::Root(const Vector& pos) : |
| 27 | BadGuy(pos, "images/creatures/ghosttree/root.sprite" , LAYER_TILES-1), |
| 28 | mystate(STATE_APPEARING), |
| 29 | base_sprite(SpriteManager::current()->create("images/creatures/ghosttree/root-base.sprite" )), |
| 30 | offset_y(0), |
| 31 | hatch_timer() |
| 32 | { |
| 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 | m_physic.enable_gravity(false); |
| 36 | set_colgroup_active(COLGROUP_TOUCHABLE); |
| 37 | } |
| 38 | |
| 39 | Root::~Root() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | Root::deactivate() |
| 45 | { |
| 46 | remove_me(); |
| 47 | //no dead script |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | Root::active_update(float dt_sec) |
| 52 | { |
| 53 | if (mystate == STATE_APPEARING) { |
| 54 | if (base_sprite->animation_done()) { |
| 55 | hatch_timer.start(HATCH_TIME); |
| 56 | mystate = STATE_HATCHING; |
| 57 | } |
| 58 | } |
| 59 | if (mystate == STATE_HATCHING) { |
| 60 | if (!hatch_timer.started()) mystate = STATE_GROWING; |
| 61 | } |
| 62 | else if (mystate == STATE_GROWING) { |
| 63 | offset_y -= dt_sec * SPEED_GROW; |
| 64 | if (offset_y < static_cast<float>(-m_sprite->get_height())) { |
| 65 | offset_y = static_cast<float>(-m_sprite->get_height()); |
| 66 | mystate = STATE_SHRINKING; |
| 67 | } |
| 68 | set_pos(m_start_position + Vector(0, offset_y)); |
| 69 | } |
| 70 | else if (mystate == STATE_SHRINKING) { |
| 71 | offset_y += dt_sec * SPEED_SHRINK; |
| 72 | if (offset_y > 0) { |
| 73 | offset_y = 0; |
| 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 |
| 77 | } |
| 78 | set_pos(m_start_position + Vector(0, offset_y)); |
| 79 | } |
| 80 | else if (mystate == STATE_VANISHING) { |
| 81 | if (base_sprite->animation_done()) remove_me(); |
| 82 | } |
| 83 | BadGuy::active_update(dt_sec); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | Root::draw(DrawingContext& context) |
| 88 | { |
| 89 | base_sprite->draw(context.color(), m_start_position, LAYER_TILES+1); |
| 90 | if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context); |
| 91 | } |
| 92 | |
| 93 | /* EOF */ |
| 94 | |