Haywire Class Reference

#include <haywire.hpp>

Inherits WalkingBadguy.

List of all members.

Public Member Functions

 Haywire (const Reader &reader)
 Haywire (const Vector &pos, Direction d)
void kill_fall ()
 Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).
HitResponse collision (GameObject &object, const CollisionHit &hit)
 Called when a collision with another object occurred.
HitResponse collision_player (Player &player, const CollisionHit &hit)
 Called when the badguy collided with a player.
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 Member Functions

bool collision_squished (GameObject &object)
 Called when the player hit the badguy from above.

Private Attributes

bool is_exploding
float time_until_explosion
bool is_stunned
float time_stunned


Detailed Description

Definition at line 23 of file haywire.hpp.


Constructor & Destructor Documentation

Haywire::Haywire ( const Reader reader  ) 

Definition at line 32 of file haywire.cpp.

References SpriteManager::create(), lisp::Lisp::get(), WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, MovingSprite::sprite, sprite_manager, MovingSprite::sprite_name, and WalkingBadguy::walk_speed.

00032                                      :
00033   WalkingBadguy(reader, "images/creatures/haywire/haywire.sprite", "left", "right"),
00034   is_exploding(false),
00035   time_until_explosion(0.0f),
00036   is_stunned(false),
00037   time_stunned(0.0f)
00038 {
00039   walk_speed = 80;
00040   max_drop_height = 16;
00041 
00042   //Prevent stutter when Tux jumps on Mr Bomb
00043   sound_manager->preload("sounds/explosion.wav");
00044 
00045   //Check if we need another sprite
00046   if( !reader.get( "sprite", sprite_name ) ){
00047     return;
00048   }
00049   if( sprite_name == "" ){
00050     sprite_name = "images/creatures/haywire/haywire.sprite";
00051     return;
00052   }
00053   //Replace sprite
00054   sprite = sprite_manager->create( sprite_name );
00055 }

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

Definition at line 58 of file haywire.cpp.

References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, and WalkingBadguy::walk_speed.

00058                                                :
00059   WalkingBadguy(pos, d, "images/creatures/haywire/haywire.sprite", "left", "right"),
00060   is_exploding(false),
00061   time_until_explosion(0.0f),
00062   is_stunned(false),
00063   time_stunned(0.0f)
00064 {
00065   walk_speed = 80;
00066   max_drop_height = 16;
00067   sound_manager->preload("sounds/explosion.wav");
00068 }


Member Function Documentation

void Haywire::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 162 of file haywire.cpp.

References Sector::add_object(), Sector::current(), MovingObject::get_bbox(), GameObject::is_valid(), GameObject::remove_me(), and BadGuy::run_dead_script().

Referenced by active_update(), and collision_squished().

00163 {
00164   if(is_valid()) {
00165     remove_me();
00166     Explosion* explosion = new Explosion(get_bbox().get_middle());
00167     Sector::current()->add_object(explosion);
00168   }
00169 
00170   run_dead_script();
00171 }

HitResponse Haywire::collision ( GameObject object,
const CollisionHit hit 
) [virtual]

Called when a collision with another object occurred.

The default implementation calls collision_player, collision_solid, collision_badguy and collision_squished

Reimplemented from BadGuy.

Definition at line 71 of file haywire.cpp.

References BadGuy::collision().

00072 {
00073   return WalkingBadguy::collision(object, hit);
00074 }

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

Called when the badguy collided with a player.

Reimplemented from BadGuy.

Definition at line 77 of file haywire.cpp.

References BadGuy::collision_player().

00078 {
00079   return WalkingBadguy::collision_player(player, hit);
00080 }

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

called each frame when the badguy is activated.

Reimplemented from WalkingBadguy.

Definition at line 119 of file haywire.cpp.

References WalkingBadguy::active_update(), BadGuy::get_nearest_player(), MovingObject::get_pos(), is_exploding, is_stunned, kill_fall(), time_stunned, time_until_explosion, WalkingBadguy::walk_speed, and Vector::x.

00120 {
00121   if (is_exploding) {
00122     if (elapsed_time >= time_until_explosion) {
00123       kill_fall ();
00124       return;
00125     }
00126     else
00127       time_until_explosion -= elapsed_time;
00128   }
00129 
00130   if (is_stunned) {
00131     if (time_stunned > elapsed_time) {
00132       time_stunned -= elapsed_time;
00133       return;
00134     }
00135     else { /* if (time_stunned <= elapsed_time) */
00136       elapsed_time -= time_stunned;
00137       time_stunned = 0.0;
00138       is_stunned = false;
00139     }
00140   }
00141 
00142   if (is_exploding) {
00143     Player *p = this->get_nearest_player ();
00144     float target_velocity = 0.0;
00145 
00146     if (p) {
00147       /* Player is on the right */
00148       if (p->get_pos ().x > this->get_pos ().x)
00149         target_velocity = walk_speed;
00150       else /* player in on the left */
00151         target_velocity = (-1.0) * walk_speed;
00152     } /* if (player) */
00153 
00154     WalkingBadguy::active_update(elapsed_time, target_velocity);
00155   }
00156   else {
00157     WalkingBadguy::active_update(elapsed_time);
00158   }
00159 }

void Haywire::freeze (  )  [virtual]

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

Reimplemented from WalkingBadguy.

Definition at line 174 of file haywire.cpp.

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

00175 {
00176   WalkingBadguy::freeze();
00177   sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
00178 }

bool Haywire::is_freezable (  )  const [virtual]

Reimplemented from BadGuy.

Definition at line 181 of file haywire.cpp.

00182 {
00183   return true;
00184 }

bool Haywire::collision_squished ( GameObject object  )  [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 83 of file haywire.cpp.

References Player::bounce(), BadGuy::dir, is_exploding, Player::is_invincible(), is_stunned, kill_fall(), LEFT, BadGuy::physic, Physic::set_acceleration_x(), MovingSprite::set_action(), Physic::set_velocity_x(), WalkingBadguy::set_walk_speed(), TIME_EXPLOSION, TIME_STUNNED, time_stunned, time_until_explosion, WalkingBadguy::walk_left_action, and WalkingBadguy::walk_right_action.

00084 {
00085   Player* player = dynamic_cast<Player*>(&object);
00086   if (player && player->is_invincible()) {
00087     player->bounce (*this);
00088     kill_fall();
00089     return true;
00090   }
00091 
00092   if (is_stunned) {
00093     if (player)
00094       player->bounce (*this);
00095     return true;
00096   }
00097 
00098   if (!is_exploding) {
00099     set_action ((dir == LEFT) ? "ticking-left" : "ticking-right", /* loops = */ -1);
00100     walk_left_action = "ticking-left";
00101     walk_right_action = "ticking-right";
00102     set_walk_speed (160);
00103     time_until_explosion = TIME_EXPLOSION;
00104     is_exploding = true;
00105   }
00106 
00107   time_stunned = TIME_STUNNED;
00108   is_stunned = true;
00109   physic.set_velocity_x (0.0);
00110   physic.set_acceleration_x (0.0);
00111 
00112   if (player)
00113     player->bounce (*this);
00114 
00115   return true;
00116 }


Member Data Documentation

bool Haywire::is_exploding [private]

Definition at line 42 of file haywire.hpp.

Referenced by active_update(), and collision_squished().

float Haywire::time_until_explosion [private]

Definition at line 43 of file haywire.hpp.

Referenced by active_update(), and collision_squished().

bool Haywire::is_stunned [private]

Definition at line 44 of file haywire.hpp.

Referenced by active_update(), and collision_squished().

float Haywire::time_stunned [private]

Definition at line 45 of file haywire.hpp.

Referenced by active_update(), and collision_squished().


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