Kugelblitz Class Reference

#include <kugelblitz.hpp>

Inherits BadGuy.

List of all members.

Public Member Functions

 Kugelblitz (const Reader &reader)
void initialize ()
 called immediately before the first call to initialize
HitResponse collision_badguy (BadGuy &other, const CollisionHit &hit)
 Called when the badguy collided with another badguy.
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.
void active_update (float)
 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 ()

Private Member Functions

void try_activate ()
HitResponse hit (const CollisionHit &hit)

Private Attributes

Vector pos_groundhit
bool groundhit_pos_set
bool dying
Timer movement_timer
Timer lifetime
int direction
State state


Detailed Description

Definition at line 22 of file kugelblitz.hpp.


Constructor & Destructor Documentation

Kugelblitz::Kugelblitz ( const Reader reader  ) 

Definition at line 34 of file kugelblitz.cpp.

References BadGuy::countMe, Physic::enable_gravity(), lisp::Lisp::get(), BadGuy::physic, MovingSprite::sprite, BadGuy::start_position, and Vector::x.

00034                                            :
00035   BadGuy(reader, "images/creatures/kugelblitz/kugelblitz.sprite"), 
00036   pos_groundhit(),
00037   groundhit_pos_set(false),
00038   dying(),
00039   movement_timer(),
00040   lifetime(),
00041   direction(),
00042   state()
00043 {
00044   reader.get("x", start_position.x);
00045   sprite->set_action("falling");
00046   physic.enable_gravity(false);
00047   countMe = false;
00048 }


Member Function Documentation

void Kugelblitz::initialize (  )  [virtual]

called immediately before the first call to initialize

Reimplemented from BadGuy.

Definition at line 51 of file kugelblitz.cpp.

References direction, dying, BadGuy::physic, Physic::set_velocity_x(), and Physic::set_velocity_y().

Referenced by try_activate().

00052 {
00053   physic.set_velocity_y(300);
00054   physic.set_velocity_x(-20); //fall a little to the left
00055   direction = 1;
00056   dying = false;
00057 }

HitResponse Kugelblitz::collision_badguy ( BadGuy other,
const CollisionHit hit 
) [virtual]

Called when the badguy collided with another badguy.

Reimplemented from BadGuy.

Definition at line 87 of file kugelblitz.cpp.

References hit(), and BadGuy::kill_fall().

00088 {
00089   //Let the Kugelblitz explode, too? The problem with that is that
00090   //two Kugelblitzes would cancel each other out on contact...
00091   other.kill_fall();
00092   return hit(chit);
00093 }

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

Called when the badguy collided with solid ground.

Reimplemented from BadGuy.

Definition at line 60 of file kugelblitz.cpp.

References hit().

00061 {
00062   hit(chit);
00063 }

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

Called when the badguy collided with a player.

Reimplemented from BadGuy.

Definition at line 66 of file kugelblitz.cpp.

References ABORT_MOVE, BadGuy::collision_squished(), explode(), FORCE_MOVE, MovingObject::get_bbox(), MovingObject::get_movement(), Player::is_invincible(), Player::kill(), Rectf::p1, Rectf::p2, and Vector::y.

00067 {
00068   if(player.is_invincible()) {
00069     explode();
00070     return ABORT_MOVE;
00071   }
00072   // hit from above?
00073   if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y <
00074      (get_bbox().p1.y + get_bbox().p2.y) / 2) {
00075     // if it's not is it possible to squish us, then this will hurt
00076     if(!collision_squished(player))
00077       player.kill(false);
00078     explode();
00079     return FORCE_MOVE;
00080   }
00081   player.kill(false);
00082   explode();
00083   return FORCE_MOVE;
00084 }

void Kugelblitz::active_update ( float   )  [virtual]

called each frame when the badguy is activated.

Reimplemented from BadGuy.

Definition at line 122 of file kugelblitz.cpp.

References BadGuy::active_update(), BASE_SPEED, Timer::check(), direction, explode(), gameRandom, groundhit_pos_set, lifetime, movement_timer, MOVETIME, BadGuy::physic, RandomGenerator::rand(), RAND_SPEED, Physic::set_velocity_x(), and Timer::start().

00123 {
00124   if (lifetime.check()) {
00125     explode();
00126   }
00127   else {
00128     if (groundhit_pos_set) {
00129       if (movement_timer.check()) {
00130         if (direction == 1) direction = -1; else direction = 1;
00131         int speed = (BASE_SPEED + (gameRandom.rand(RAND_SPEED))) * direction;
00132         physic.set_velocity_x(speed);
00133         movement_timer.start(MOVETIME);
00134       }
00135     }
00136     /*
00137       if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) {
00138       //HIT WATER
00139       Sector::current()->add_object(new Electrifier(75,1421,1.5));
00140       Sector::current()->add_object(new Electrifier(76,1422,1.5));
00141       explode();
00142       }
00143       if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 48) {
00144       //HIT ELECTRIFIED WATER
00145       explode();
00146       }
00147     */
00148   }
00149   BadGuy::active_update(elapsed_time);
00150 }

void Kugelblitz::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 153 of file kugelblitz.cpp.

00154 {
00155 }

void Kugelblitz::explode (  ) 

Definition at line 158 of file kugelblitz.cpp.

References dying, lifetime, GameObject::remove_me(), MovingSprite::sprite, and Timer::start().

Referenced by active_update(), and collision_player().

00159 {
00160   if (!dying) {
00161     sprite->set_action("pop");
00162     lifetime.start(0.2f);
00163     dying = true;
00164   }
00165   else remove_me();
00166 }

void Kugelblitz::try_activate (  )  [private]

Reimplemented from BadGuy.

Definition at line 169 of file kugelblitz.cpp.

References BadGuy::activate(), AUTO, BadGuy::dir, MovingObject::get_bbox(), Rectf::get_middle(), BadGuy::get_nearest_player(), initialize(), BadGuy::is_initialized, LEFT, Rectf::p1, Rectf::p2, RIGHT, BadGuy::set_state(), BadGuy::start_dir, BadGuy::STATE_ACTIVE, Vector::x, X_OFFSCREEN_DISTANCE, Vector::y, and Y_OFFSCREEN_DISTANCE.

00170 {
00171   // Much smaller offscreen distances to pop out of nowhere and surprise Tux
00172   float X_OFFSCREEN_DISTANCE = 400;
00173   float Y_OFFSCREEN_DISTANCE = 600;
00174 
00175   Player* player = get_nearest_player();
00176   if (!player) return;
00177   Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle();
00178   if ((fabsf(dist.x) <= X_OFFSCREEN_DISTANCE) && (fabsf(dist.y) <= Y_OFFSCREEN_DISTANCE)) {
00179     set_state(STATE_ACTIVE);
00180     if (!is_initialized) {
00181 
00182       // if starting direction was set to AUTO, this is our chance to re-orient the badguy
00183       if (start_dir == AUTO) {
00184         Player* player = get_nearest_player();
00185         if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
00186           dir = RIGHT;
00187         } else {
00188           dir = LEFT;
00189         }
00190       }
00191 
00192       initialize();
00193       is_initialized = true;
00194     }
00195     activate();
00196   }
00197 }

HitResponse Kugelblitz::hit ( const CollisionHit hit  )  [private]

Definition at line 96 of file kugelblitz.cpp.

References BASE_SPEED, CONTINUE, direction, gameRandom, MovingObject::get_pos(), groundhit_pos_set, LIFETIME, lifetime, movement_timer, MOVETIME, BadGuy::physic, pos_groundhit, RandomGenerator::rand(), RAND_SPEED, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, and Timer::start().

Referenced by collision_badguy(), and collision_solid().

00097 {
00098   // hit floor?
00099   if(hit.bottom) {
00100     if (!groundhit_pos_set)
00101     {
00102       pos_groundhit = get_pos();
00103       groundhit_pos_set = true;
00104     }
00105     sprite->set_action("flying");
00106     physic.set_velocity_y(0);
00107     //Set random initial speed and direction
00108     direction = gameRandom.rand(2)? 1: -1;
00109     int speed = (BASE_SPEED + (gameRandom.rand(RAND_SPEED))) * direction;
00110     physic.set_velocity_x(speed);
00111     movement_timer.start(MOVETIME);
00112     lifetime.start(LIFETIME);
00113 
00114   } else if(hit.top) { // bumped on roof
00115     physic.set_velocity_y(0);
00116   }
00117 
00118   return CONTINUE;
00119 }


Member Data Documentation

Vector Kugelblitz::pos_groundhit [private]

Definition at line 41 of file kugelblitz.hpp.

Referenced by hit().

bool Kugelblitz::groundhit_pos_set [private]

Definition at line 42 of file kugelblitz.hpp.

Referenced by active_update(), and hit().

bool Kugelblitz::dying [private]

Definition at line 43 of file kugelblitz.hpp.

Referenced by explode(), and initialize().

Timer Kugelblitz::movement_timer [private]

Definition at line 44 of file kugelblitz.hpp.

Referenced by active_update(), and hit().

Timer Kugelblitz::lifetime [private]

Definition at line 45 of file kugelblitz.hpp.

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

int Kugelblitz::direction [private]

Definition at line 46 of file kugelblitz.hpp.

Referenced by active_update(), hit(), and initialize().

State Kugelblitz::state [private]

Reimplemented from BadGuy.

Definition at line 47 of file kugelblitz.hpp.


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