SpiderMite Class Reference

#include <spidermite.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 SpiderMite (const Reader &reader)
 SpiderMite (const Vector &pos)
void initialize ()
 called immediately before the first call to initialize
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
void collision_solid (const CollisionHit &hit)
 Called when the badguy collided with solid ground.

Protected Types

enum  SpiderMiteMode { FLY_UP, FLY_DOWN }

Protected Member Functions

bool collision_squished (GameObject &object)
 Called when the player hit the badguy from above.

Private Attributes

SpiderMiteMode mode
Timer timer


Detailed Description

Definition at line 22 of file spidermite.hpp.


Member Enumeration Documentation

enum SpiderMite::SpiderMiteMode [protected]

Enumerator:
FLY_UP 
FLY_DOWN 

Definition at line 33 of file spidermite.hpp.

00033                       {
00034     FLY_UP,
00035     FLY_DOWN
00036   };


Constructor & Destructor Documentation

SpiderMite::SpiderMite ( const Reader reader  ) 

Definition at line 26 of file spidermite.cpp.

References Physic::enable_gravity(), and BadGuy::physic.

00026                                            :
00027   BadGuy(reader, "images/creatures/spidermite/spidermite.sprite"),
00028   mode(),
00029   timer()
00030 {
00031   physic.enable_gravity(false);
00032 }

SpiderMite::SpiderMite ( const Vector pos  ) 

Definition at line 34 of file spidermite.cpp.

References Physic::enable_gravity(), and BadGuy::physic.

00034                                         :
00035   BadGuy(pos, "images/creatures/spidermite/spidermite.sprite"), 
00036   mode(),
00037   timer()
00038 {
00039   physic.enable_gravity(false);
00040 }


Member Function Documentation

void SpiderMite::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from BadGuy.

Definition at line 43 of file spidermite.cpp.

References BadGuy::dir, FLY_UP, FLYTIME, LEFT, mode, MOVE_SPEED, BadGuy::physic, Physic::set_velocity_y(), MovingSprite::sprite, Timer::start(), and timer.

00044 {
00045   sprite->set_action(dir == LEFT ? "left" : "right");
00046   mode = FLY_UP;
00047   physic.set_velocity_y(MOVE_SPEED);
00048   timer.start(FLYTIME/2);
00049 }

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

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 68 of file spidermite.cpp.

References Timer::check(), BadGuy::dir, FLY_DOWN, FLY_UP, FLYTIME, Physic::get_movement(), BadGuy::get_nearest_player(), MovingObject::get_pos(), LEFT, mode, MOVE_SPEED, MovingObject::movement, BadGuy::physic, RIGHT, Physic::set_velocity_y(), MovingSprite::sprite, Timer::start(), timer, and Vector::x.

00069 {
00070   if(timer.check()) {
00071     if(mode == FLY_UP) {
00072       mode = FLY_DOWN;
00073       physic.set_velocity_y(-MOVE_SPEED);
00074     } else if(mode == FLY_DOWN) {
00075       mode = FLY_UP;
00076       physic.set_velocity_y(MOVE_SPEED);
00077     }
00078     timer.start(FLYTIME);
00079   }
00080   movement=physic.get_movement(elapsed_time);
00081 
00082   Player* player = this->get_nearest_player();
00083   if (player) {
00084     dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
00085     sprite->set_action(dir == LEFT ? "left" : "right");
00086   }
00087 }

void SpiderMite::collision_solid ( const CollisionHit hit  )  [virtual]

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 60 of file spidermite.cpp.

References CollisionHit::bottom, BadGuy::physic, Physic::set_velocity_y(), and CollisionHit::top.

00061 {
00062   if(hit.top || hit.bottom) { // hit floor or roof?
00063     physic.set_velocity_y(0);
00064   }
00065 }

bool SpiderMite::collision_squished ( GameObject object  )  [protected, 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 52 of file spidermite.cpp.

References BadGuy::dir, BadGuy::kill_squished(), LEFT, and MovingSprite::sprite.

00053 {
00054   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
00055   kill_squished(object);
00056   return true;
00057 }


Member Data Documentation

SpiderMiteMode SpiderMite::mode [private]

Definition at line 42 of file spidermite.hpp.

Referenced by active_update(), and initialize().

Timer SpiderMite::timer [private]

Definition at line 43 of file spidermite.hpp.

Referenced by active_update(), and initialize().


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