AngryStone Class Reference

#include <angrystone.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 AngryStone (const Reader &reader)
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 kill_fall ()
 Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).

Protected Types

enum  AngryStoneState { IDLE, CHARGING, ATTACKING, RECOVERING }

Private Attributes

Vector attackDirection
 1-normalized vector of current attack direction
Vector oldWallDirection
 if wall was hit during last attack: 1-normalized vector of last attack direction, (0,0) otherwise
Timer timer
AngryStoneState state


Detailed Description

Definition at line 22 of file angrystone.hpp.


Member Enumeration Documentation

enum AngryStone::AngryStoneState [protected]

Enumerator:
IDLE 
CHARGING 
ATTACKING 
RECOVERING 

Definition at line 33 of file angrystone.hpp.

00033                        {
00034     IDLE,
00035     CHARGING,
00036     ATTACKING,
00037     RECOVERING
00038   };


Constructor & Destructor Documentation

AngryStone::AngryStone ( const Reader reader  ) 

Definition at line 29 of file angrystone.cpp.

References Physic::enable_gravity(), BadGuy::physic, Physic::set_velocity_x(), Physic::set_velocity_y(), and MovingSprite::sprite.

00029                                            :
00030   BadGuy(reader, "images/creatures/angrystone/angrystone.sprite"), 
00031   attackDirection(),
00032   oldWallDirection(),
00033   timer(),
00034   state(IDLE)
00035 {
00036   physic.set_velocity_x(0);
00037   physic.set_velocity_y(0);
00038   physic.enable_gravity(true);
00039   sprite->set_action("idle");
00040 }


Member Function Documentation

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 43 of file angrystone.cpp.

References attackDirection, ATTACKING, Physic::enable_gravity(), IDLE, oldWallDirection, BadGuy::physic, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, state, Vector::x, and Vector::y.

00044 {
00045   // TODO
00046   (void) hit;
00047 #if 0
00048   if ((state == ATTACKING) &&
00049       (hit.normal.x == -attackDirection.x) && (hit.normal.y == attackDirection.y)) {
00050     state = IDLE;
00051     sprite->set_action("idle");
00052     physic.set_velocity_x(0);
00053     physic.set_velocity_y(0);
00054     physic.enable_gravity(true);
00055     oldWallDirection.x = attackDirection.x;
00056     oldWallDirection.y = attackDirection.y;
00057   }
00058 #endif
00059 }

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

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 68 of file angrystone.cpp.

References ATTACKING, FORCE_MOVE, BadGuy::kill_fall(), and state.

00069 {
00070   if (state == ATTACKING) {
00071     badguy.kill_fall();
00072     return FORCE_MOVE;
00073   }
00074 
00075   return FORCE_MOVE;
00076 }

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

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 79 of file angrystone.cpp.

References BadGuy::active_update(), ATTACK_TIME, attackDirection, ATTACKING, CHARGE_SPEED, CHARGE_TIME, CHARGING, Timer::check(), Physic::enable_gravity(), MovingObject::get_bbox(), BadGuy::get_nearest_player(), MovingObject::get_pos(), IDLE, oldWallDirection, Rectf::p1, Rectf::p2, BadGuy::physic, RECOVER_TIME, RECOVERING, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, Timer::start(), state, timer, Vector::x, and Vector::y.

00079                                             {
00080   BadGuy::active_update(elapsed_time);
00081 
00082   if (state == IDLE) {
00083     MovingObject* player = this->get_nearest_player();
00084     if(player) {
00085       MovingObject* badguy = this;
00086       const Vector playerPos = player->get_pos();
00087       const Vector badguyPos = badguy->get_pos();
00088       float dx = (playerPos.x - badguyPos.x);
00089       float dy = (playerPos.y - badguyPos.y);
00090 
00091       float playerHeight = player->get_bbox().p2.y - player->get_bbox().p1.y;
00092       float badguyHeight = badguy->get_bbox().p2.y - badguy->get_bbox().p1.y;
00093 
00094       float playerWidth = player->get_bbox().p2.x - player->get_bbox().p1.x;
00095       float badguyWidth = badguy->get_bbox().p2.x - badguy->get_bbox().p1.x;
00096 
00097       if ((dx > -playerWidth) && (dx < badguyWidth)) {
00098         if (dy > 0) {
00099           attackDirection.x = 0;
00100           attackDirection.y = 1;
00101         } else {
00102           attackDirection.x = 0;
00103           attackDirection.y = -1;
00104         }
00105         if ((attackDirection.x != oldWallDirection.x) || (attackDirection.y != oldWallDirection.y)) {
00106           sprite->set_action("charging");
00107           timer.start(CHARGE_TIME);
00108           state = CHARGING;
00109         }
00110       } else
00111         if ((dy > -playerHeight) && (dy < badguyHeight)) {
00112           if (dx > 0) {
00113             attackDirection.x = 1;
00114             attackDirection.y = 0;
00115           } else {
00116             attackDirection.x = -1;
00117             attackDirection.y = 0;
00118           }
00119           if ((attackDirection.x != oldWallDirection.x) || (attackDirection.y != oldWallDirection.y)) {
00120             sprite->set_action("charging");
00121             timer.start(CHARGE_TIME);
00122             state = CHARGING;
00123           }
00124         }
00125 
00126     }
00127   }
00128 
00129   if (state == CHARGING) {
00130     if (timer.check()) {
00131       sprite->set_action("attacking");
00132       timer.start(ATTACK_TIME);
00133       state = ATTACKING;
00134       physic.enable_gravity(false);
00135       physic.set_velocity_x(CHARGE_SPEED * attackDirection.x);
00136       physic.set_velocity_y(CHARGE_SPEED * attackDirection.y);
00137       oldWallDirection.x = 0;
00138       oldWallDirection.y = 0;
00139     }
00140   }
00141 
00142   if (state == ATTACKING) {
00143     if (timer.check()) {
00144       timer.start(RECOVER_TIME);
00145       state = RECOVERING;
00146       sprite->set_action("idle");
00147       physic.enable_gravity(true);
00148       physic.set_velocity_x(0);
00149       physic.set_velocity_y(0);
00150     }
00151   }
00152 
00153   if (state == RECOVERING) {
00154     if (timer.check()) {
00155       state = IDLE;
00156       sprite->set_action("idle");
00157       physic.enable_gravity(true);
00158       physic.set_velocity_x(0);
00159       physic.set_velocity_y(0);
00160     }
00161   }
00162 
00163 }

void AngryStone::kill_fall (  )  [virtual]

Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).

Reimplemented from BadGuy.

Definition at line 62 of file angrystone.cpp.

00063 {
00064   //prevents AngryStone from getting killed by other enemies or the player
00065 }


Member Data Documentation

Vector AngryStone::attackDirection [private]

1-normalized vector of current attack direction

Definition at line 41 of file angrystone.hpp.

Referenced by active_update(), and collision_solid().

Vector AngryStone::oldWallDirection [private]

if wall was hit during last attack: 1-normalized vector of last attack direction, (0,0) otherwise

Definition at line 42 of file angrystone.hpp.

Referenced by active_update(), and collision_solid().

Timer AngryStone::timer [private]

Definition at line 43 of file angrystone.hpp.

Referenced by active_update().

AngryStoneState AngryStone::state [private]

Reimplemented from BadGuy.

Definition at line 44 of file angrystone.hpp.

Referenced by active_update(), collision_badguy(), and collision_solid().


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