SkyDive Class Reference

#include <skydive.hpp>

Inherits BadGuy, and Portable.

List of all members.

Public Member Functions

 SkyDive (const Reader &reader)
 SkyDive (const Vector &pos, Direction d)
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 grab (MovingObject &object, const Vector &pos, Direction dir)
 called each frame when the object has been grabbed.
void ungrab (MovingObject &object, Direction dir)

Protected Member Functions

HitResponse collision_player (Player &player, const CollisionHit &hit)
 Called when the badguy collided with a player.
bool collision_squished (GameObject &obj)
 Called when the player hit the badguy from above.
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
void explode (void)

Private Attributes

bool is_grabbed


Detailed Description

Definition at line 23 of file skydive.hpp.


Constructor & Destructor Documentation

SkyDive::SkyDive ( const Reader reader  ) 

Definition at line 25 of file skydive.cpp.

00025                                      :
00026   BadGuy(reader, "images/creatures/skydive/skydive.sprite"),
00027   is_grabbed(false)
00028 {
00029 }

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

Definition at line 31 of file skydive.cpp.

00031                                                :
00032   BadGuy(pos, d, "images/creatures/skydive/skydive.sprite"),
00033   is_grabbed(false)
00034 {
00035 }


Member Function Documentation

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 38 of file skydive.cpp.

References CollisionHit::bottom, explode(), CollisionHit::left, BadGuy::physic, CollisionHit::right, and Physic::set_velocity_x().

00039 {
00040   if (hit.bottom) {
00041     explode ();
00042     return;
00043   }
00044 
00045   if (hit.left || hit.right)
00046     physic.set_velocity_x (0.0);
00047 } /* void collision_solid */

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

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 50 of file skydive.cpp.

References ABORT_MOVE, CollisionHit::bottom, explode(), and FORCE_MOVE.

00051 {
00052   if (hit.bottom) {
00053     explode ();
00054     return (ABORT_MOVE);
00055   }
00056 
00057   return (FORCE_MOVE);
00058 } /* HitResponse collision_badguy */

void SkyDive::grab ( MovingObject object,
const Vector pos,
Direction  dir 
) [virtual]

called each frame when the object has been grabbed.

Implements Portable.

Definition at line 61 of file skydive.cpp.

References COLGROUP_DISABLED, Physic::enable_gravity(), MovingObject::get_pos(), is_grabbed, LOGICAL_FPS, MovingObject::movement, BadGuy::physic, Physic::set_acceleration_y(), BadGuy::set_colgroup_active(), Physic::set_velocity_x(), Physic::set_velocity_y(), and Vector::x.

00062 {
00063   movement = pos - get_pos();
00064   this->dir = dir;
00065 
00066   is_grabbed = true;
00067 
00068   physic.set_velocity_x (movement.x * LOGICAL_FPS);
00069   physic.set_velocity_y (0.0);
00070   physic.set_acceleration_y (0.0);
00071   physic.enable_gravity (false);
00072   set_colgroup_active (COLGROUP_DISABLED);
00073 }

void SkyDive::ungrab ( MovingObject object,
Direction  dir 
) [virtual]

Reimplemented from Portable.

Definition at line 76 of file skydive.cpp.

References COLGROUP_MOVING, Physic::enable_gravity(), is_grabbed, BadGuy::physic, Physic::set_acceleration_y(), BadGuy::set_colgroup_active(), and Physic::set_velocity_y().

00077 {
00078   is_grabbed = false;
00079 
00080   physic.set_velocity_y (0);
00081   physic.set_acceleration_y (0);
00082   physic.enable_gravity (true);
00083   set_colgroup_active (COLGROUP_MOVING);
00084 }

HitResponse SkyDive::collision_player ( Player player,
const CollisionHit hit 
) [protected, virtual]

Called when the badguy collided with a player.

Reimplemented from BadGuy.

Definition at line 87 of file skydive.cpp.

References ABORT_MOVE, CollisionHit::bottom, explode(), and FORCE_MOVE.

00088 {
00089   if (hit.bottom) {
00090     explode ();
00091     return (ABORT_MOVE);
00092   }
00093 
00094   return FORCE_MOVE;
00095 } /* HitResponse collision_player */

bool SkyDive::collision_squished ( GameObject obj  )  [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 98 of file skydive.cpp.

References Player::bounce(), and explode().

00099 {
00100   Player *player = dynamic_cast<Player *> (&obj);
00101   if (player) {
00102     player->bounce (*this);
00103     return (false);
00104   }
00105 
00106   explode ();
00107   return (false);
00108 } /* bool collision_squished */

void SkyDive::active_update ( float  elapsed_time  )  [protected, virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 111 of file skydive.cpp.

References Physic::get_movement(), is_grabbed, MovingObject::movement, and BadGuy::physic.

00112 {
00113   if (!is_grabbed)
00114     movement = physic.get_movement(elapsed_time);
00115 } /* void active_update */

void SkyDive::explode ( void   )  [protected]

Definition at line 118 of file skydive.cpp.

References Sector::add_object(), ANCHOR_BOTTOM, MovingObject::bbox, Sector::current(), get_anchor_pos(), Explosion::hurts(), GameObject::is_valid(), Explosion::pushes(), and GameObject::remove_me().

Referenced by collision_badguy(), collision_player(), collision_solid(), and collision_squished().

00119 {
00120   if (!is_valid ())
00121     return;
00122 
00123   Explosion *explosion = new Explosion (get_anchor_pos (bbox, ANCHOR_BOTTOM));
00124 
00125   explosion->hurts (true);
00126   explosion->pushes (false);
00127   Sector::current()->add_object (explosion);
00128 
00129   remove_me ();
00130 } /* void explode */


Member Data Documentation

bool SkyDive::is_grabbed [private]

Definition at line 26 of file skydive.hpp.

Referenced by active_update(), grab(), and ungrab().


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