Jumpy Class Reference

#include <jumpy.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Jumpy (const Reader &reader)
void collision_solid (const CollisionHit &hit)
 Called when the badguy collided with solid ground.
HitResponse collision_badguy (BadGuy &other, const CollisionHit &hit)
 Called when the badguy collided with another badguy.
void active_update (float)
 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

Private Member Functions

HitResponse hit (const CollisionHit &hit)

Private Attributes

Vector pos_groundhit
bool groundhit_pos_set


Detailed Description

Definition at line 22 of file jumpy.hpp.


Constructor & Destructor Documentation

Jumpy::Jumpy ( const Reader reader  ) 

Definition at line 27 of file jumpy.cpp.

00027                                  :
00028   BadGuy(reader, "images/creatures/snowjumpy/snowjumpy.sprite"), 
00029   pos_groundhit(),
00030   groundhit_pos_set(false)
00031 {
00032   // TODO create a nice sound for this...
00033   //sound_manager->preload("sounds/skid.wav");
00034 }


Member Function Documentation

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 37 of file jumpy.cpp.

References hit().

00038 {
00039   hit(chit);
00040 }

HitResponse Jumpy::collision_badguy ( BadGuy other,
const CollisionHit hit 
) [virtual]

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 43 of file jumpy.cpp.

References hit().

00044 {
00045   return hit(chit);
00046 }

void Jumpy::active_update ( float   )  [virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 69 of file jumpy.cpp.

References BadGuy::active_update(), BadGuy::dir, BadGuy::frozen, BadGuy::get_nearest_player(), MovingObject::get_pos(), groundhit_pos_set, JUMPY_LOW_TOLERANCE, JUMPY_MID_TOLERANCE, LEFT, pos_groundhit, RIGHT, MovingSprite::sprite, Vector::x, and Vector::y.

00070 {
00071   BadGuy::active_update(elapsed_time);
00072 
00073   if(frozen)
00074     return;
00075 
00076   Player* player = this->get_nearest_player();
00077   if (player)
00078   {
00079     dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
00080   }
00081 
00082   if (!groundhit_pos_set)
00083   {
00084     sprite->set_action(dir == LEFT ? "left-middle" : "right-middle");
00085     return;
00086   }
00087 
00088   if ( get_pos().y < (pos_groundhit.y - JUMPY_MID_TOLERANCE ) )
00089     sprite->set_action(dir == LEFT ? "left-up" : "right-up");
00090   else if ( get_pos().y >= (pos_groundhit.y - JUMPY_MID_TOLERANCE) &&
00091             get_pos().y < (pos_groundhit.y - JUMPY_LOW_TOLERANCE) )
00092     sprite->set_action(dir == LEFT ? "left-middle" : "right-middle");
00093   else
00094     sprite->set_action(dir == LEFT ? "left-down" : "right-down");
00095 }

void Jumpy::freeze (  )  [virtual]

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

Reimplemented from BadGuy.

Definition at line 98 of file jumpy.cpp.

References BadGuy::dir, BadGuy::freeze(), Physic::get_velocity_y(), LEFT, BadGuy::physic, Physic::set_velocity_y(), and MovingSprite::sprite.

00099 {
00100   BadGuy::freeze();
00101   physic.set_velocity_y(std::max(0.0f, physic.get_velocity_y()));
00102   sprite->set_action(dir == LEFT ? "left-iced" : "right-iced");
00103 }

bool Jumpy::is_freezable (  )  const [virtual]

Reimplemented from BadGuy.

Definition at line 106 of file jumpy.cpp.

00107 {
00108   return true;
00109 }

HitResponse Jumpy::hit ( const CollisionHit hit  )  [private]

Definition at line 49 of file jumpy.cpp.

References CollisionHit::bottom, CONTINUE, BadGuy::frozen, MovingObject::get_pos(), BadGuy::get_state(), groundhit_pos_set, JUMPYSPEED, BadGuy::physic, pos_groundhit, Physic::set_velocity_y(), BadGuy::STATE_FALLING, and CollisionHit::top.

Referenced by collision_badguy(), and collision_solid().

00050 {
00051   if(chit.bottom) {
00052     if (!groundhit_pos_set)
00053     {
00054       pos_groundhit = get_pos();
00055       groundhit_pos_set = true;
00056     }
00057 
00058     physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPYSPEED);
00059     // TODO create a nice sound for this...
00060     //sound_manager->play("sounds/skid.wav");
00061   } else if(chit.top) {
00062     physic.set_velocity_y(0);
00063   }
00064 
00065   return CONTINUE;
00066 }


Member Data Documentation

Vector Jumpy::pos_groundhit [private]

Definition at line 39 of file jumpy.hpp.

Referenced by active_update(), and hit().

bool Jumpy::groundhit_pos_set [private]

Definition at line 40 of file jumpy.hpp.

Referenced by active_update(), and hit().


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