00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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);
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
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);
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