DartTrap Class Reference

Badguy "DartTrap" - Shoots a Dart at regular intervals. More...

#include <darttrap.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 DartTrap (const Reader &reader)
void initialize ()
 called immediately before the first call to initialize
void activate ()
 called when the badguy has been activated.
void active_update (float elapsed_time)
 called each frame when the badguy is activated.
HitResponse collision_player (Player &player, const CollisionHit &hit)
 Called when the badguy collided with a player.

Protected Types

enum  State { IDLE, LOADING }

Protected Member Functions

void load ()
 load a shot
void fire ()
 fire a shot

Private Attributes

float initial_delay
 time to wait before firing first shot
float fire_delay
 reload time
int ammo
 ammo left (-1 means unlimited)
State state
 current state
Timer fire_timer
 time until new shot is fired


Detailed Description

Badguy "DartTrap" - Shoots a Dart at regular intervals.

Definition at line 23 of file darttrap.hpp.


Member Enumeration Documentation

enum DartTrap::State [protected]

Enumerator:
IDLE 
LOADING 

Reimplemented from BadGuy.

Definition at line 34 of file darttrap.hpp.

00034              {
00035     IDLE, LOADING
00036   };


Constructor & Destructor Documentation

DartTrap::DartTrap ( const Reader reader  ) 

Definition at line 30 of file darttrap.cpp.

References ammo, AUTO, COLGROUP_DISABLED, BadGuy::countMe, fire_delay, lisp::Lisp::get(), IDLE, initial_delay, log_warning, SoundManager::preload(), BadGuy::set_colgroup_active(), sound_manager, BadGuy::start_dir, and state.

00030                                        :
00031   BadGuy(reader, "images/creatures/darttrap/darttrap.sprite", LAYER_TILES-1),
00032   initial_delay(0), 
00033   fire_delay(2), 
00034   ammo(-1), 
00035   state(IDLE),
00036   fire_timer()
00037 {
00038   reader.get("initial-delay", initial_delay);
00039   reader.get("fire-delay", fire_delay);
00040   reader.get("ammo", ammo);
00041   countMe = false;
00042   sound_manager->preload("sounds/dartfire.wav");
00043   if (start_dir == AUTO) log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl;
00044   state = IDLE;
00045   set_colgroup_active(COLGROUP_DISABLED);
00046   if (initial_delay == 0) initial_delay = 0.1f;
00047 }


Member Function Documentation

void DartTrap::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from BadGuy.

Definition at line 50 of file darttrap.cpp.

References BadGuy::dir, LEFT, and MovingSprite::sprite.

00051 {
00052   sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
00053 }

void DartTrap::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 56 of file darttrap.cpp.

References fire_timer, initial_delay, and Timer::start().

00057 {
00058   fire_timer.start(initial_delay);
00059 }

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

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 68 of file darttrap.cpp.

References ammo, Timer::check(), fire(), fire_delay, fire_timer, IDLE, load(), LOADING, MovingSprite::sprite, Timer::start(), and state.

00069 {
00070   if (state == IDLE) {
00071     if ((ammo != 0) && (fire_timer.check())) {
00072       if (ammo > 0) ammo--;
00073       load();
00074       fire_timer.start(fire_delay);
00075     }
00076   }
00077   if (state == LOADING) {
00078     if (sprite->animation_done()) {
00079       fire();
00080     }
00081   }
00082 }

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

Called when the badguy collided with a player.

Reimplemented from BadGuy.

Definition at line 62 of file darttrap.cpp.

References ABORT_MOVE.

00063 {
00064   return ABORT_MOVE;
00065 }

void DartTrap::load (  )  [protected]

load a shot

Definition at line 85 of file darttrap.cpp.

References BadGuy::dir, LEFT, LOADING, MovingSprite::sprite, and state.

Referenced by active_update().

00086 {
00087   state = LOADING;
00088   sprite->set_action(dir == LEFT ? "loading-left" : "loading-right", 1);
00089 }

void DartTrap::fire (  )  [protected]

fire a shot

Definition at line 92 of file darttrap.cpp.

References Sector::add_object(), Sector::current(), BadGuy::dir, MovingObject::get_pos(), IDLE, LEFT, MUZZLE_Y, SoundManager::play(), RIGHT, sound_manager, MovingSprite::sprite, state, Vector::x, and Vector::y.

Referenced by active_update().

00093 {
00094   float px = get_pos().x;
00095   if (dir == RIGHT) px += 5;
00096   float py = get_pos().y;
00097   py += MUZZLE_Y;
00098 
00099   sound_manager->play("sounds/dartfire.wav", get_pos());
00100   Sector::current()->add_object(new Dart(Vector(px, py), dir, this));
00101   state = IDLE;
00102   sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
00103 }


Member Data Documentation

float DartTrap::initial_delay [private]

time to wait before firing first shot

Definition at line 42 of file darttrap.hpp.

Referenced by activate(), and DartTrap().

float DartTrap::fire_delay [private]

reload time

Definition at line 43 of file darttrap.hpp.

Referenced by active_update(), and DartTrap().

int DartTrap::ammo [private]

ammo left (-1 means unlimited)

Definition at line 44 of file darttrap.hpp.

Referenced by active_update(), and DartTrap().

State DartTrap::state [private]

current state

Reimplemented from BadGuy.

Definition at line 46 of file darttrap.hpp.

Referenced by active_update(), DartTrap(), fire(), and load().

Timer DartTrap::fire_timer [private]

time until new shot is fired

Definition at line 47 of file darttrap.hpp.

Referenced by activate(), and active_update().


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