src/badguy/root.cpp

Go to the documentation of this file.
00001 //  SuperTux - "Will-O-Wisp" Badguy
00002 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "badguy/root.hpp"
00018 #include "sprite/sprite.hpp"
00019 #include "sprite/sprite_manager.hpp"
00020 
00021 static const float SPEED_GROW = 256;
00022 static const float SPEED_SHRINK = 128;
00023 static const float HATCH_TIME = 0.75;
00024 
00025 Root::Root(const Vector& pos) :
00026   BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
00027   mystate(STATE_APPEARING), 
00028   base_sprite(),
00029   offset_y(0),
00030   hatch_timer()
00031 {
00032   base_sprite = sprite_manager->create("images/creatures/ghosttree/root-base.sprite");
00033   base_sprite->set_action("appearing", 1);
00034   base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action
00035   physic.enable_gravity(false);
00036   set_colgroup_active(COLGROUP_TOUCHABLE);
00037 }
00038 
00039 Root::~Root()
00040 {
00041 }
00042 
00043 void
00044 Root::deactivate()
00045 {
00046   remove_me();
00047   //no dead script
00048 }
00049 
00050 void
00051 Root::active_update(float elapsed_time)
00052 {
00053   if (mystate == STATE_APPEARING) {  
00054     if (base_sprite->animation_done()) {
00055       hatch_timer.start(HATCH_TIME);
00056       mystate = STATE_HATCHING;
00057     }
00058   }
00059   if (mystate == STATE_HATCHING) {
00060     if (!hatch_timer.started()) mystate = STATE_GROWING;
00061   }
00062   else if (mystate == STATE_GROWING) {
00063     offset_y -= elapsed_time * SPEED_GROW;
00064     if (offset_y < -sprite->get_height()) {
00065       offset_y = -sprite->get_height();
00066       mystate = STATE_SHRINKING;
00067     }
00068     set_pos(start_position + Vector(0, offset_y));
00069   }
00070   else if (mystate == STATE_SHRINKING) {
00071     offset_y += elapsed_time * SPEED_SHRINK;
00072     if (offset_y > 0) {
00073       offset_y = 0;
00074       mystate = STATE_VANISHING;
00075       base_sprite->set_action("vanishing", 2);
00076       base_sprite->set_animation_loops(2); // TODO: doesn't seem to work for loops=1 
00077     }
00078     set_pos(start_position + Vector(0, offset_y));
00079   }
00080   else if (mystate == STATE_VANISHING) {
00081     if (base_sprite->animation_done()) remove_me();
00082   }
00083   BadGuy::active_update(elapsed_time);
00084 }
00085 
00086 void
00087 Root::draw(DrawingContext& context)
00088 {
00089   base_sprite->draw(context, start_position, LAYER_TILES+1);
00090   if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context);
00091 }
00092 
00093 /* EOF */

Generated on Mon Jun 9 03:38:17 2014 for SuperTux by  doxygen 1.5.1