Bomb Class Reference

#include <bomb.hpp>

Inherits BadGuy, and Portable.

List of all members.

Public Member Functions

 Bomb (const Vector &pos, Direction dir, std::string custom_sprite="images/creatures/mr_bomb/bomb.sprite")
void collision_solid (const CollisionHit &hit)
 Called when the badguy collided with solid ground.
HitResponse collision_player (Player &player, const CollisionHit &hit)
 Called when the badguy collided with a player.
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).
void explode ()
void grab (MovingObject &object, const Vector &pos, Direction dir)
 called each frame when the object has been grabbed.
void ungrab (MovingObject &object, Direction dir)

Private Types

enum  State { STATE_TICKING }

Private Member Functions

 Bomb (const Bomb &)
Bomboperator= (const Bomb &)

Private Attributes

State state
bool grabbed
MovingObjectgrabber
std::auto_ptr< SoundSourceticking


Detailed Description

Definition at line 24 of file bomb.hpp.


Member Enumeration Documentation

enum Bomb::State [private]

Enumerator:
STATE_TICKING 

Reimplemented from BadGuy.

Definition at line 40 of file bomb.hpp.

00040              {
00041     STATE_TICKING
00042   };


Constructor & Destructor Documentation

Bomb::Bomb ( const Vector pos,
Direction  dir,
std::string  custom_sprite = "images/creatures/mr_bomb/bomb.sprite" 
)

Definition at line 24 of file bomb.cpp.

References BadGuy::countMe, SoundManager::create_sound_source(), MovingObject::get_pos(), LEFT, MovingSprite::set_action(), sound_manager, state, STATE_TICKING, and ticking.

00024                                                                                                                      :
00025   BadGuy( pos, dir, custom_sprite ), 
00026   state(),
00027   grabbed(false), 
00028   grabber(NULL),
00029   ticking()
00030 {
00031   state = STATE_TICKING;
00032   set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1);
00033   countMe = false;
00034 
00035   ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav"));
00036   ticking->set_position(get_pos());
00037   ticking->set_looping(true);
00038   ticking->set_gain(2.0);
00039   ticking->set_reference_distance(32);
00040   ticking->play();
00041 }

Bomb::Bomb ( const Bomb  )  [private]


Member Function Documentation

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 44 of file bomb.cpp.

References CollisionHit::bottom, BadGuy::physic, Physic::set_velocity_y(), and BadGuy::update_on_ground_flag().

00045 {
00046   if(hit.bottom)
00047     physic.set_velocity_y(0);
00048 
00049   update_on_ground_flag(hit);
00050 }

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

Called when the badguy collided with a player.

Reimplemented from BadGuy.

Definition at line 53 of file bomb.cpp.

References ABORT_MOVE.

00054 {
00055   return ABORT_MOVE;
00056 }

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

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 59 of file bomb.cpp.

References ABORT_MOVE.

00060 {
00061   return ABORT_MOVE;
00062 }

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

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 65 of file bomb.cpp.

References explode(), Physic::get_movement(), MovingObject::get_pos(), grabbed, MovingObject::movement, BadGuy::physic, MovingSprite::sprite, and ticking.

00066 {
00067   ticking->set_position(get_pos());
00068   if(sprite->animation_done()) {
00069     explode();
00070   }
00071   else if (!grabbed) {
00072     movement = physic.get_movement(elapsed_time);
00073   }
00074 }

void Bomb::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 101 of file bomb.cpp.

References explode().

00102 {
00103   explode();
00104 }

void Bomb::explode (  ) 

Definition at line 77 of file bomb.cpp.

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

Referenced by active_update(), and kill_fall().

00078 {
00079   ticking->stop();
00080 
00081   // Make the player let go before we explode, otherwise the player is holding
00082   // an invalid object. There's probably a better way to do this than in the
00083   // Bomb class.
00084   if (grabber != NULL) {
00085     Player* player = dynamic_cast<Player*>(grabber);
00086     
00087     if (player)
00088       player->stop_grabbing();
00089   }
00090 
00091   if(is_valid()) {
00092     remove_me();
00093     Explosion* explosion = new Explosion(get_bbox().get_middle());
00094     Sector::current()->add_object(explosion);
00095   }
00096 
00097   run_dead_script();
00098 }

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

called each frame when the object has been grabbed.

Implements Portable.

Definition at line 107 of file bomb.cpp.

References COLGROUP_DISABLED, MovingObject::get_pos(), grabbed, grabber, LEFT, MovingObject::movement, BadGuy::set_colgroup_active(), and MovingSprite::sprite.

00108 {
00109   movement = pos - get_pos();
00110   this->dir = dir;
00111 
00112   // We actually face the opposite direction of Tux here to make the fuse more
00113   // visible instead of hiding it behind Tux
00114   sprite->set_action_continued(dir == LEFT ? "ticking-right" : "ticking-left");
00115   set_colgroup_active(COLGROUP_DISABLED);
00116   grabbed = true;
00117   grabber = &object;
00118 }

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

Reimplemented from Portable.

Definition at line 121 of file bomb.cpp.

References COLGROUP_MOVING, MovingObject::get_bbox(), MovingObject::get_pos(), grabbed, LEFT, BadGuy::set_colgroup_active(), and MovingObject::set_pos().

00122 {
00123   this->dir = dir;
00124   // portable objects are usually pushed away from Tux when dropped, but we
00125   // don't want that, so we set the position
00126   set_pos(object.get_pos() + Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32));
00127   set_colgroup_active(COLGROUP_MOVING);
00128   grabbed = false;
00129 }

Bomb& Bomb::operator= ( const Bomb  )  [private]


Member Data Documentation

State Bomb::state [private]

Reimplemented from BadGuy.

Definition at line 44 of file bomb.hpp.

Referenced by Bomb().

bool Bomb::grabbed [private]

Definition at line 45 of file bomb.hpp.

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

MovingObject* Bomb::grabber [private]

Definition at line 46 of file bomb.hpp.

Referenced by explode(), and grab().

std::auto_ptr<SoundSource> Bomb::ticking [private]

Definition at line 48 of file bomb.hpp.

Referenced by active_update(), Bomb(), and explode().


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 03:38:32 2014 for SuperTux by  doxygen 1.5.1