Root Class Reference

#include <root.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Root (const Vector &pos)
 ~Root ()
void deactivate ()
 called when the badguy has been deactivated
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
virtual void draw (DrawingContext &context)
 Called when the badguy is drawn.
virtual bool is_flammable () const
 Returns whether to call ignite() when a badguy gets hit by a fire bullet.
virtual bool is_freezable () const
virtual void kill_fall ()
 Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).

Protected Types

enum  MyState {
  STATE_APPEARING, STATE_HATCHING, STATE_GROWING, STATE_SHRINKING,
  STATE_VANISHING
}

Private Attributes

MyState mystate
SpritePtr base_sprite
float offset_y
Timer hatch_timer


Detailed Description

Definition at line 24 of file root.hpp.


Member Enumeration Documentation

enum Root::MyState [protected]

Enumerator:
STATE_APPEARING 
STATE_HATCHING 
STATE_GROWING 
STATE_SHRINKING 
STATE_VANISHING 

Definition at line 38 of file root.hpp.


Constructor & Destructor Documentation

Root::Root ( const Vector pos  ) 

Definition at line 25 of file root.cpp.

References base_sprite, COLGROUP_TOUCHABLE, SpriteManager::create(), Physic::enable_gravity(), BadGuy::physic, BadGuy::set_colgroup_active(), and sprite_manager.

00025                             :
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 }

Root::~Root (  ) 

Definition at line 39 of file root.cpp.

00040 {
00041 }


Member Function Documentation

void Root::deactivate (  )  [virtual]

called when the badguy has been deactivated

Reimplemented from BadGuy.

Definition at line 44 of file root.cpp.

References GameObject::remove_me().

00045 {
00046   remove_me();
00047   //no dead script
00048 }

void Root::active_update ( float  elapsed_time  )  [virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 51 of file root.cpp.

References BadGuy::active_update(), base_sprite, HATCH_TIME, hatch_timer, mystate, offset_y, GameObject::remove_me(), MovingObject::set_pos(), SPEED_GROW, SPEED_SHRINK, MovingSprite::sprite, Timer::start(), BadGuy::start_position, Timer::started(), STATE_APPEARING, STATE_GROWING, STATE_HATCHING, STATE_SHRINKING, and STATE_VANISHING.

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 }

void Root::draw ( DrawingContext context  )  [virtual]

Called when the badguy is drawn.

The default implementation simply draws the badguy sprite on screen

Reimplemented from BadGuy.

Definition at line 87 of file root.cpp.

References base_sprite, BadGuy::draw(), LAYER_TILES, mystate, BadGuy::start_position, STATE_APPEARING, and STATE_VANISHING.

00088 {
00089   base_sprite->draw(context, start_position, LAYER_TILES+1);
00090   if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context);
00091 }

virtual bool Root::is_flammable (  )  const [inline, virtual]

Returns whether to call ignite() when a badguy gets hit by a fire bullet.

Reimplemented from BadGuy.

Definition at line 33 of file root.hpp.

00033 { return false; }

virtual bool Root::is_freezable (  )  const [inline, virtual]

Reimplemented from BadGuy.

Definition at line 34 of file root.hpp.

00034 { return false; }

virtual void Root::kill_fall (  )  [inline, virtual]

Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).

Reimplemented from BadGuy.

Definition at line 35 of file root.hpp.

00035 { }


Member Data Documentation

MyState Root::mystate [private]

Definition at line 43 of file root.hpp.

Referenced by active_update(), and draw().

SpritePtr Root::base_sprite [private]

Definition at line 44 of file root.hpp.

Referenced by active_update(), draw(), and Root().

float Root::offset_y [private]

Definition at line 45 of file root.hpp.

Referenced by active_update().

Timer Root::hatch_timer [private]

Definition at line 46 of file root.hpp.

Referenced by active_update().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:34 2014 for SuperTux by  doxygen 1.5.1