SSpiky Class Reference

#include <sspiky.hpp>

Inherits WalkingBadguy.

List of all members.

Public Member Functions

 SSpiky (const Reader &reader)
void initialize ()
 called immediately before the first call to initialize
void collision_solid (const CollisionHit &hit)
 Called when the badguy collided with solid ground.
HitResponse collision_badguy (BadGuy &badguy, const CollisionHit &hit)
 Called when the badguy collided with another badguy.
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
void freeze ()
 Called when hit by an ice bullet, and is_freezable() returns true.
bool is_freezable () const

Protected Types

enum  SSpikyState { SSPIKY_SLEEPING, SSPIKY_WAKING, SSPIKY_WALKING }

Protected Attributes

SSpikyState state


Detailed Description

Definition at line 22 of file sspiky.hpp.


Member Enumeration Documentation

enum SSpiky::SSpikyState [protected]

Enumerator:
SSPIKY_SLEEPING 
SSPIKY_WAKING 
SSPIKY_WALKING 

Definition at line 36 of file sspiky.hpp.

00036                    {
00037     SSPIKY_SLEEPING,
00038     SSPIKY_WAKING,
00039     SSPIKY_WALKING
00040   };


Constructor & Destructor Documentation

SSpiky::SSpiky ( const Reader reader  ) 

Definition at line 25 of file sspiky.cpp.

References WalkingBadguy::max_drop_height, WalkingBadguy::walk_speed, and WALKSPEED.

00026   : WalkingBadguy(reader, "images/creatures/spiky/sleepingspiky.sprite", "left", "right"), state(SSPIKY_SLEEPING)
00027 {
00028   walk_speed = WALKSPEED;
00029   max_drop_height = -1;
00030 }


Member Function Documentation

void SSpiky::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from WalkingBadguy.

Definition at line 33 of file sspiky.cpp.

References BadGuy::dir, LEFT, BadGuy::physic, Physic::set_velocity_x(), MovingSprite::sprite, SSPIKY_SLEEPING, and state.

00034 {
00035   state = SSPIKY_SLEEPING;
00036   physic.set_velocity_x(0);
00037   sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right");
00038 }

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

Called when the badguy collided with solid ground.

Reimplemented from WalkingBadguy.

Definition at line 41 of file sspiky.cpp.

References WalkingBadguy::collision_solid(), BadGuy::collision_solid(), SSPIKY_WALKING, and state.

00042 {
00043   if(state != SSPIKY_WALKING) {
00044     BadGuy::collision_solid(hit);
00045     return;
00046   }
00047   WalkingBadguy::collision_solid(hit);
00048 }

HitResponse SSpiky::collision_badguy ( BadGuy badguy,
const CollisionHit hit 
) [virtual]

Called when the badguy collided with another badguy.

Reimplemented from WalkingBadguy.

Definition at line 51 of file sspiky.cpp.

References WalkingBadguy::collision_badguy(), BadGuy::collision_badguy(), SSPIKY_WALKING, and state.

00052 {
00053   if(state != SSPIKY_WALKING) {
00054     return BadGuy::collision_badguy(badguy, hit);
00055   }
00056   return WalkingBadguy::collision_badguy(badguy, hit);
00057 }

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

called each frame when the badguy is activated.

Reimplemented from WalkingBadguy.

Definition at line 60 of file sspiky.cpp.

References BadGuy::active_update(), WalkingBadguy::active_update(), BadGuy::dir, MovingObject::get_bbox(), BadGuy::get_nearest_player(), WalkingBadguy::initialize(), LEFT, Rectf::p1, Rectf::p2, RIGHT, MovingSprite::sprite, SSPIKY_SLEEPING, SSPIKY_WAKING, SSPIKY_WALKING, state, Vector::x, and Vector::y.

00060                                         {
00061 
00062   if(state == SSPIKY_WALKING) {
00063     WalkingBadguy::active_update(elapsed_time);
00064     return;
00065   }
00066 
00067   if(state == SSPIKY_SLEEPING) {
00068 
00069     Player* player = this->get_nearest_player();
00070     if (player) {
00071       Rectf mb = this->get_bbox();
00072       Rectf pb = player->get_bbox();
00073 
00074       bool inReach_left = (pb.p2.x >= mb.p2.x-((dir == LEFT) ? 256 : 0));
00075       bool inReach_right = (pb.p1.x <= mb.p1.x+((dir == RIGHT) ? 256 : 0));
00076       bool inReach_top = (pb.p2.y >= mb.p1.y);
00077       bool inReach_bottom = (pb.p1.y <= mb.p2.y);
00078 
00079       if (inReach_left && inReach_right && inReach_top && inReach_bottom) {
00080         // wake up
00081         sprite->set_action(dir == LEFT ? "waking-left" : "waking-right", 1);
00082         state = SSPIKY_WAKING;
00083       }
00084     }
00085 
00086     BadGuy::active_update(elapsed_time);
00087   }
00088 
00089   if(state == SSPIKY_WAKING) {
00090     if(sprite->animation_done()) {
00091       // start walking
00092       state = SSPIKY_WALKING;
00093       WalkingBadguy::initialize();
00094     }
00095 
00096     BadGuy::active_update(elapsed_time);
00097   }
00098 }

void SSpiky::freeze (  )  [virtual]

Called when hit by an ice bullet, and is_freezable() returns true.

Reimplemented from WalkingBadguy.

Definition at line 101 of file sspiky.cpp.

References BadGuy::dir, WalkingBadguy::freeze(), LEFT, MovingSprite::sprite, SSPIKY_WALKING, and state.

00102 {
00103   WalkingBadguy::freeze();
00104   sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
00105   state = SSPIKY_WALKING; // if we get hit while sleeping, wake up :)
00106 }

bool SSpiky::is_freezable (  )  const [virtual]

Reimplemented from BadGuy.

Definition at line 109 of file sspiky.cpp.

00110 {
00111   return true;
00112 }


Member Data Documentation

SSpikyState SSpiky::state [protected]

Reimplemented from BadGuy.

Definition at line 41 of file sspiky.hpp.

Referenced by active_update(), collision_badguy(), collision_solid(), freeze(), 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