SkullyHop Class Reference

Badguy "SkullyHop" - A Hopping Skull. More...

#include <skullyhop.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 SkullyHop (const Reader &reader)
 SkullyHop (const Vector &pos, Direction d)
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.
bool collision_squished (GameObject &object)
 Called when the player hit the badguy from above.
void active_update (float elapsed_time)
 called each frame when the badguy is activated.

Private Types

enum  SkullyHopState { STANDING, CHARGING, JUMPING }

Private Member Functions

void set_state (SkullyHopState newState)

Private Attributes

Timer recover_timer
SkullyHopState state


Detailed Description

Badguy "SkullyHop" - A Hopping Skull.

Definition at line 25 of file skullyhop.hpp.


Member Enumeration Documentation

enum SkullyHop::SkullyHopState [private]

Enumerator:
STANDING 
CHARGING 
JUMPING 

Definition at line 38 of file skullyhop.hpp.

00038                       {
00039     STANDING,
00040     CHARGING,
00041     JUMPING
00042   };


Constructor & Destructor Documentation

SkullyHop::SkullyHop ( const Reader reader  ) 

Definition at line 30 of file skullyhop.cpp.

References SoundManager::preload(), SKULLYHOP_SOUND, and sound_manager.

00030                                          :
00031   BadGuy(reader, "images/creatures/skullyhop/skullyhop.sprite"),
00032   recover_timer(),
00033   state()
00034 {
00035   sound_manager->preload( SKULLYHOP_SOUND );
00036 }

SkullyHop::SkullyHop ( const Vector pos,
Direction  d 
)

Definition at line 38 of file skullyhop.cpp.

References SoundManager::preload(), SKULLYHOP_SOUND, and sound_manager.

00038                                                    :
00039   BadGuy(pos, d, "images/creatures/skullyhop/skullyhop.sprite"),
00040   recover_timer(),
00041   state()
00042 {
00043   sound_manager->preload( SKULLYHOP_SOUND );
00044 }


Member Function Documentation

void SkullyHop::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from BadGuy.

Definition at line 47 of file skullyhop.cpp.

References BadGuy::dir, JUMPING, LEFT, MovingSprite::sprite, and state.

00048 {
00049   // initial state is JUMPING, because we might start airborne
00050   state = JUMPING;
00051   sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
00052 }

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 89 of file skullyhop.cpp.

References CollisionHit::bottom, BadGuy::collision_solid(), BadGuy::dir, BadGuy::get_state(), Physic::get_velocity_x(), Physic::get_velocity_y(), JUMPING, LEFT, CollisionHit::left, BadGuy::physic, RIGHT, CollisionHit::right, set_state(), Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, STANDING, state, BadGuy::STATE_SQUISHED, and CollisionHit::top.

Referenced by collision_badguy().

00090 {
00091   // just default behaviour (i.e. stop at floor/walls) when squished
00092   if (BadGuy::get_state() == STATE_SQUISHED) {
00093     BadGuy::collision_solid(hit);
00094   }
00095 
00096   // ignore collisions while standing still
00097   if(state != JUMPING)
00098     return;
00099 
00100   // check if we hit the floor while falling
00101   if(hit.bottom && physic.get_velocity_y() > 0 ) {
00102     set_state(STANDING);
00103   }
00104   // check if we hit the roof while climbing
00105   if(hit.top) {
00106     physic.set_velocity_y(0);
00107   }
00108 
00109   // check if we hit left or right while moving in either direction
00110   if(hit.left || hit.right) {
00111     dir = dir == LEFT ? RIGHT : LEFT;
00112     sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
00113     physic.set_velocity_x(-0.25*physic.get_velocity_x());
00114   }
00115 }

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

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 118 of file skullyhop.cpp.

References collision_solid(), and CONTINUE.

00119 {
00120   // behaviour for badguy collisions is the same as for collisions with solids
00121   collision_solid(hit);
00122 
00123   return CONTINUE;
00124 }

bool SkullyHop::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 81 of file skullyhop.cpp.

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

00082 {
00083   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
00084   kill_squished(object);
00085   return true;
00086 }

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

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 127 of file skullyhop.cpp.

References BadGuy::active_update(), CHARGING, Timer::check(), JUMPING, recover_timer, set_state(), MovingSprite::sprite, STANDING, and state.

00128 {
00129   BadGuy::active_update(elapsed_time);
00130 
00131   // charge when fully recovered
00132   if ((state == STANDING) && (recover_timer.check())) {
00133     set_state(CHARGING);
00134     return;
00135   }
00136 
00137   // jump as soon as charging animation completed
00138   if ((state == CHARGING) && (sprite->animation_done())) {
00139     set_state(JUMPING);
00140     return;
00141   }
00142 }

void SkullyHop::set_state ( SkullyHopState  newState  )  [private]

Definition at line 55 of file skullyhop.cpp.

References CHARGING, BadGuy::dir, gameRandom, MovingObject::get_pos(), HORIZONTAL_SPEED, JUMPING, LEFT, MAX_RECOVER_TIME, MIN_RECOVER_TIME, BadGuy::physic, SoundManager::play(), RandomGenerator::randf(), recover_timer, Physic::set_velocity_x(), Physic::set_velocity_y(), SKULLYHOP_SOUND, sound_manager, MovingSprite::sprite, STANDING, Timer::start(), state, and VERTICAL_SPEED.

Referenced by active_update(), and collision_solid().

00056 {
00057   if (newState == STANDING) {
00058     physic.set_velocity_x(0);
00059     physic.set_velocity_y(0);
00060     sprite->set_action(dir == LEFT ? "standing-left" : "standing-right");
00061 
00062     float recover_time = gameRandom.randf(MIN_RECOVER_TIME,MAX_RECOVER_TIME);
00063     recover_timer.start(recover_time);
00064   } else
00065     if (newState == CHARGING) {
00066       sprite->set_action(dir == LEFT ? "charging-left" : "charging-right", 1);
00067     } else
00068       if (newState == JUMPING) {
00069         sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
00070 const float HORIZONTAL_SPEED = 220; 
00071         physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
00072 const float VERTICAL_SPEED = -450;   
00073         physic.set_velocity_y(VERTICAL_SPEED);
00074         sound_manager->play( SKULLYHOP_SOUND, get_pos());
00075       }
00076 
00077   state = newState;
00078 }


Member Data Documentation

Timer SkullyHop::recover_timer [private]

Definition at line 48 of file skullyhop.hpp.

Referenced by active_update(), and set_state().

SkullyHopState SkullyHop::state [private]

Reimplemented from BadGuy.

Definition at line 49 of file skullyhop.hpp.

Referenced by active_update(), collision_solid(), initialize(), and set_state().


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