Mole Class Reference

#include <mole.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Mole (const Reader &)
 Mole (const Vector &pos)
void kill_fall ()
 Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).
HitResponse collision_badguy (BadGuy &, const CollisionHit &)
 Called when the badguy collided with another badguy.
bool collision_squished (GameObject &object)
 Called when the player hit the badguy from above.
void activate ()
 called when the badguy has been activated.
void active_update (float)
 called each frame when the badguy is activated.

Private Types

enum  MoleState {
  PRE_THROWING, THROWING, POST_THROWING, PEEKING,
  DEAD
}

Private Member Functions

void set_state (MoleState new_state)
void throw_rock ()

Private Attributes

MoleState state
Timer timer
Timer throw_timer


Detailed Description

Definition at line 22 of file mole.hpp.


Member Enumeration Documentation

enum Mole::MoleState [private]

Enumerator:
PRE_THROWING 
THROWING 
POST_THROWING 
PEEKING 
DEAD 

Definition at line 36 of file mole.hpp.

00036                  {
00037     PRE_THROWING,
00038     THROWING,
00039     POST_THROWING,
00040     PEEKING,
00041     DEAD
00042   };


Constructor & Destructor Documentation

Mole::Mole ( const Reader  ) 

Definition at line 32 of file mole.cpp.

References Physic::enable_gravity(), BadGuy::physic, SoundManager::preload(), and sound_manager.

00032                                :
00033   BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), 
00034   state(PRE_THROWING),
00035   timer(),
00036   throw_timer()
00037 {
00038   physic.enable_gravity(false);
00039   sound_manager->preload("sounds/fall.wav");
00040   sound_manager->preload("sounds/squish.wav");
00041   sound_manager->preload("sounds/dartfire.wav");
00042 }

Mole::Mole ( const Vector pos  ) 

Definition at line 44 of file mole.cpp.

References Physic::enable_gravity(), BadGuy::physic, SoundManager::preload(), and sound_manager.

00044                             :
00045   BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), 
00046   state(PRE_THROWING),
00047   timer(),
00048   throw_timer()
00049 {
00050   physic.enable_gravity(false);
00051   sound_manager->preload("sounds/fall.wav");
00052   sound_manager->preload("sounds/squish.wav");
00053   sound_manager->preload("sounds/dartfire.wav");
00054 }


Member Function Documentation

void Mole::kill_fall (  )  [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 63 of file mole.cpp.

References DEAD, MovingObject::get_pos(), SoundManager::play(), BadGuy::run_dead_script(), set_state(), and sound_manager.

00064 {
00065   set_state(DEAD);
00066   sound_manager->play("sounds/fall.wav", get_pos());
00067   run_dead_script();
00068 }

HitResponse Mole::collision_badguy ( BadGuy ,
const CollisionHit  
) [virtual]

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 71 of file mole.cpp.

References FORCE_MOVE.

00072 {
00073   return FORCE_MOVE;
00074 }

bool Mole::collision_squished ( GameObject object  )  [virtual]

Called when the player hit the badguy from above.

You should return true if the badguy was squished, false if squishing wasn't possible

Reimplemented from BadGuy.

Definition at line 77 of file mole.cpp.

References DEAD, MovingObject::get_pos(), SoundManager::play(), BadGuy::run_dead_script(), set_state(), and sound_manager.

00078 {
00079   set_state(DEAD);
00080   sound_manager->play("sounds/squish.wav", get_pos());
00081   run_dead_script();
00082   return true;
00083 }

void Mole::activate (  )  [virtual]

called when the badguy has been activated.

(As a side effect the dir variable might have been changed so that it faces towards the player.

Reimplemented from BadGuy.

Definition at line 57 of file mole.cpp.

References DEAD, PRE_THROWING, set_state(), and state.

00058 {
00059   if (state != DEAD) set_state(PRE_THROWING);
00060 }

void Mole::active_update ( float   )  [virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 100 of file mole.cpp.

References BadGuy::active_update(), Timer::check(), DEAD, PEEKING, POST_THROWING, PRE_THROWING, set_state(), MovingSprite::sprite, Timer::start(), state, THROW_INTERVAL, throw_rock(), throw_timer, THROWING, and timer.

00101 {
00102   BadGuy::active_update(elapsed_time);
00103 
00104   switch (state) {
00105     case PRE_THROWING:
00106       if (timer.check()) {
00107         set_state(THROWING);
00108       }
00109       break;
00110     case THROWING:
00111       if (throw_timer.check()) {
00112         throw_rock();
00113         throw_timer.start(THROW_INTERVAL);
00114       }
00115       if (timer.check()) {
00116         set_state(POST_THROWING);
00117       }
00118       break;
00119     case POST_THROWING:
00120       if (timer.check()) {
00121         set_state(PEEKING);
00122       }
00123       break;
00124     case PEEKING:
00125       if (sprite->animation_done()) {
00126         set_state(PRE_THROWING);
00127       }
00128       break;
00129     case DEAD:
00130       break;
00131   }
00132 
00133 }

void Mole::set_state ( MoleState  new_state  )  [private]

Definition at line 136 of file mole.cpp.

References COLGROUP_DISABLED, COLGROUP_STATIC, DEAD, MOLE_WAIT_TIME, PEEKING, POST_THROWING, PRE_THROWING, BadGuy::set_colgroup_active(), MovingSprite::sprite, Timer::start(), state, THROW_INTERVAL, THROW_TIME, throw_timer, THROWING, and timer.

Referenced by activate(), active_update(), collision_squished(), and kill_fall().

00137 {
00138   switch (new_state) {
00139     case PRE_THROWING:
00140       sprite->set_action("idle");
00141       set_colgroup_active(COLGROUP_DISABLED);
00142       timer.start(MOLE_WAIT_TIME);
00143       break;
00144     case THROWING:
00145       sprite->set_action("idle");
00146       set_colgroup_active(COLGROUP_DISABLED);
00147       timer.start(THROW_TIME);
00148       throw_timer.start(THROW_INTERVAL);
00149       break;
00150     case POST_THROWING:
00151       sprite->set_action("idle");
00152       set_colgroup_active(COLGROUP_DISABLED);
00153       timer.start(MOLE_WAIT_TIME);
00154       break;
00155     case PEEKING:
00156       sprite->set_action("peeking", 1);
00157       set_colgroup_active(COLGROUP_STATIC);
00158       break;
00159     case DEAD:
00160       sprite->set_action("idle");
00161       set_colgroup_active(COLGROUP_DISABLED);
00162       break;
00163   }
00164 
00165   state = new_state;
00166 }

void Mole::throw_rock (  )  [private]

Definition at line 86 of file mole.cpp.

References Sector::add_object(), Sector::current(), gameRandom, MovingObject::get_bbox(), Rectf::get_middle(), MovingObject::get_pos(), SoundManager::play(), RandomGenerator::rand(), sound_manager, THROW_VELOCITY, Vector::x, and Vector::y.

Referenced by active_update().

00087 {
00088   float px = get_bbox().get_middle().x;
00089   float py = get_bbox().get_middle().y;
00090 
00091   float angle = gameRandom.rand(90 - 15, 90 + 15) * (M_PI / 180);
00092   float vx = cos(angle) * THROW_VELOCITY;
00093   float vy = -sin(angle) * THROW_VELOCITY;
00094 
00095   sound_manager->play("sounds/dartfire.wav", get_pos());
00096   Sector::current()->add_object(new MoleRock(Vector(px, py), Vector(vx, vy), this));
00097 }


Member Data Documentation

MoleState Mole::state [private]

Reimplemented from BadGuy.

Definition at line 49 of file mole.hpp.

Referenced by activate(), active_update(), and set_state().

Timer Mole::timer [private]

Definition at line 50 of file mole.hpp.

Referenced by active_update(), and set_state().

Timer Mole::throw_timer [private]

Definition at line 51 of file mole.hpp.

Referenced by active_update(), and set_state().


The documentation for this class was generated from the following files:
Generated on Mon Apr 21 03:38:26 2014 for SuperTux by  doxygen 1.5.1