Dart Class Reference

Badguy "Dart" - Your average poison dart. More...

#include <dart.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Dart (const Reader &reader)
 Dart (const Vector &pos, Direction d, const BadGuy *parent)
 ~Dart ()
void initialize ()
 called immediately before the first call to initialize
void activate ()
 called when the badguy has been activated.
void deactivate ()
 called when the badguy has been deactivated
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
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.
HitResponse collision_player (Player &player, const CollisionHit &hit)
 Called when the badguy collided with a player.
virtual bool updatePointers (const GameObject *from_object, GameObject *to_object)

Protected Attributes

const BadGuyparent
 collisions with this BadGuy will be ignored
std::auto_ptr< SoundSourcesound_source
 SoundSource for ambient sound.

Private Member Functions

 Dart (const Dart &)
Dartoperator= (const Dart &)


Detailed Description

Badguy "Dart" - Your average poison dart.

Definition at line 27 of file dart.hpp.


Constructor & Destructor Documentation

Dart::Dart ( const Reader reader  ) 

Definition at line 30 of file dart.cpp.

References BadGuy::countMe, DART_SOUND, Physic::enable_gravity(), BadGuy::physic, SoundManager::preload(), and sound_manager.

00030                                :
00031   BadGuy(reader, "images/creatures/dart/dart.sprite"), 
00032   parent(0),
00033   sound_source()
00034 {
00035   physic.enable_gravity(false);
00036   countMe = false;
00037   sound_manager->preload(DART_SOUND);
00038   sound_manager->preload("sounds/darthit.wav");
00039   sound_manager->preload("sounds/stomp.wav");
00040 }

Dart::Dart ( const Vector pos,
Direction  d,
const BadGuy parent 
)

Definition at line 42 of file dart.cpp.

References BadGuy::countMe, DART_SOUND, Physic::enable_gravity(), BadGuy::physic, SoundManager::preload(), and sound_manager.

00042                                                                    :
00043   BadGuy(pos, d, "images/creatures/dart/dart.sprite"), 
00044   parent(parent),
00045   sound_source()
00046 {
00047   physic.enable_gravity(false);
00048   countMe = false;
00049   sound_manager->preload(DART_SOUND);
00050   sound_manager->preload("sounds/darthit.wav");
00051   sound_manager->preload("sounds/stomp.wav");
00052 }

Dart::~Dart (  ) 

Definition at line 54 of file dart.cpp.

00055 {
00056 }

Dart::Dart ( const Dart  )  [private]


Member Function Documentation

void Dart::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from BadGuy.

Definition at line 69 of file dart.cpp.

References DART_SPEED, BadGuy::dir, LEFT, BadGuy::physic, Physic::set_velocity_x(), and MovingSprite::sprite.

00070 {
00071   physic.set_velocity_x(dir == LEFT ? -::DART_SPEED : ::DART_SPEED);
00072   sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
00073 }

void Dart::activate (  )  [virtual]

called when the badguy has been activated.

(As a side effect the dir variable might have been changed so that it faces towards the player.

Reimplemented from BadGuy.

Definition at line 76 of file dart.cpp.

References SoundManager::create_sound_source(), DART_SOUND, MovingObject::get_pos(), sound_manager, and sound_source.

00077 {
00078   sound_source.reset(sound_manager->create_sound_source(DART_SOUND));
00079   sound_source->set_position(get_pos());
00080   sound_source->set_looping(true);
00081   sound_source->set_gain(1.0);
00082   sound_source->set_reference_distance(32);
00083   sound_source->play();
00084 }

void Dart::deactivate (  )  [virtual]

called when the badguy has been deactivated

Reimplemented from BadGuy.

Definition at line 87 of file dart.cpp.

References GameObject::remove_me(), and sound_source.

00088 {
00089   sound_source.reset();
00090   remove_me();
00091 }

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

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 94 of file dart.cpp.

References BadGuy::active_update(), MovingObject::get_pos(), and sound_source.

00095 {
00096   BadGuy::active_update(elapsed_time);
00097   sound_source->set_position(get_pos());
00098 }

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 101 of file dart.cpp.

References MovingObject::get_pos(), SoundManager::play(), GameObject::remove_me(), and sound_manager.

00102 {
00103   sound_manager->play("sounds/darthit.wav", get_pos());
00104   remove_me();
00105 }

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

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 108 of file dart.cpp.

References ABORT_MOVE, FORCE_MOVE, MovingObject::get_pos(), BadGuy::kill_fall(), parent, SoundManager::play(), GameObject::remove_me(), and sound_manager.

00109 {
00110   // ignore collisions with parent
00111   if (&badguy == parent) {
00112     return FORCE_MOVE;
00113   }
00114   sound_manager->play("sounds/stomp.wav", get_pos());
00115   remove_me();
00116   badguy.kill_fall();
00117   return ABORT_MOVE;
00118 }

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

Called when the badguy collided with a player.

Reimplemented from BadGuy.

Definition at line 121 of file dart.cpp.

References BadGuy::collision_player(), MovingObject::get_pos(), SoundManager::play(), GameObject::remove_me(), and sound_manager.

00122 {
00123   sound_manager->play("sounds/stomp.wav", get_pos());
00124   remove_me();
00125   return BadGuy::collision_player(player, hit);
00126 }

bool Dart::updatePointers ( const GameObject from_object,
GameObject to_object 
) [virtual]

Definition at line 59 of file dart.cpp.

References parent.

00060 {
00061   if (from_object == parent) {
00062     parent = dynamic_cast<Dart*>(to_object);
00063     return true;
00064   }
00065   return false;
00066 }

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


Member Data Documentation

const BadGuy* Dart::parent [protected]

collisions with this BadGuy will be ignored

Definition at line 47 of file dart.hpp.

Referenced by collision_badguy(), and updatePointers().

std::auto_ptr<SoundSource> Dart::sound_source [protected]

SoundSource for ambient sound.

Definition at line 48 of file dart.hpp.

Referenced by activate(), active_update(), and deactivate().


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