#include <stalactite.hpp>
Inherits BadGuy.
Inherited by YetiStalactite.
Public Member Functions | |
Stalactite (const Reader &reader) | |
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_player (Player &player, const CollisionHit &hit) |
Called when the badguy collided with a player. | |
HitResponse | collision_badguy (BadGuy &other, const CollisionHit &hit) |
Called when the badguy collided with another badguy. | |
void | kill_fall () |
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down). | |
void | draw (DrawingContext &context) |
Called when the badguy is drawn. | |
void | deactivate () |
called when the badguy has been deactivated | |
void | squish () |
Protected Types | |
enum | StalactiteState { STALACTITE_HANGING, STALACTITE_SHAKING, STALACTITE_FALLING, STALACTITE_SQUISHED } |
Protected Attributes | |
Timer | timer |
StalactiteState | state |
Vector | shake_delta |
Definition at line 22 of file stalactite.hpp.
enum Stalactite::StalactiteState [protected] |
Definition at line 39 of file stalactite.hpp.
00039 { 00040 STALACTITE_HANGING, 00041 STALACTITE_SHAKING, 00042 STALACTITE_FALLING, 00043 STALACTITE_SQUISHED 00044 };
Stalactite::Stalactite | ( | const Reader & | reader | ) |
Definition at line 28 of file stalactite.cpp.
References COLGROUP_TOUCHABLE, BadGuy::countMe, and BadGuy::set_colgroup_active().
00028 : 00029 BadGuy(lisp, "images/creatures/stalactite/stalactite.sprite", LAYER_TILES - 1), 00030 timer(), 00031 state(STALACTITE_HANGING), 00032 shake_delta() 00033 { 00034 countMe = false; 00035 set_colgroup_active(COLGROUP_TOUCHABLE); 00036 }
void Stalactite::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from BadGuy.
Reimplemented in YetiStalactite.
Definition at line 39 of file stalactite.cpp.
References MovingObject::bbox, Timer::check(), COLGROUP_MOVING, Physic::enable_gravity(), MovingObject::get_bbox(), Physic::get_movement(), BadGuy::get_nearest_player(), graphicsRandom, MovingObject::movement, Rectf::p1, Rectf::p2, BadGuy::physic, RandomGenerator::rand(), BadGuy::set_colgroup_active(), shake_delta, SHAKE_RANGE_X, SHAKE_RANGE_Y, SHAKE_TIME, STALACTITE_FALLING, STALACTITE_HANGING, STALACTITE_SHAKING, Timer::start(), state, timer, Vector::x, and Vector::y.
Referenced by YetiStalactite::active_update().
00040 { 00041 if(state == STALACTITE_HANGING) { 00042 Player* player = this->get_nearest_player(); 00043 if (player) { 00044 if(player->get_bbox().p2.x > bbox.p1.x - SHAKE_RANGE_X 00045 && player->get_bbox().p1.x < bbox.p2.x + SHAKE_RANGE_X 00046 && player->get_bbox().p2.y > bbox.p1.y 00047 && player->get_bbox().p1.y < bbox.p2.y + SHAKE_RANGE_Y) { 00048 timer.start(SHAKE_TIME); 00049 state = STALACTITE_SHAKING; 00050 } 00051 } 00052 } else if(state == STALACTITE_SHAKING) { 00053 shake_delta = Vector(graphicsRandom.rand(-3,3), 0); 00054 if(timer.check()) { 00055 state = STALACTITE_FALLING; 00056 physic.enable_gravity(true); 00057 set_colgroup_active(COLGROUP_MOVING); 00058 } 00059 } else if(state == STALACTITE_FALLING) { 00060 movement = physic.get_movement(elapsed_time); 00061 } 00062 }
void Stalactite::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
Called when the badguy collided with solid ground.
Reimplemented from BadGuy.
Definition at line 78 of file stalactite.cpp.
References CollisionHit::bottom, BadGuy::physic, Physic::set_velocity_y(), squish(), STALACTITE_FALLING, STALACTITE_SQUISHED, and state.
00079 { 00080 if(state == STALACTITE_FALLING) { 00081 if (hit.bottom) squish(); 00082 } 00083 if(state == STALACTITE_SQUISHED) { 00084 physic.set_velocity_y(0); 00085 } 00086 }
HitResponse Stalactite::collision_player | ( | Player & | player, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with a player.
Reimplemented from BadGuy.
Definition at line 89 of file stalactite.cpp.
References FORCE_MOVE, Player::kill(), STALACTITE_SQUISHED, and state.
00090 { 00091 if(state != STALACTITE_SQUISHED) { 00092 player.kill(false); 00093 } 00094 00095 return FORCE_MOVE; 00096 }
HitResponse Stalactite::collision_badguy | ( | BadGuy & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with another badguy.
Reimplemented from BadGuy.
Definition at line 99 of file stalactite.cpp.
References BadGuy::collision_badguy(), FORCE_MOVE, STALACTITE_FALLING, STALACTITE_SQUISHED, and state.
00100 { 00101 if (state == STALACTITE_SQUISHED) return FORCE_MOVE; 00102 00103 // ignore other Stalactites 00104 if (dynamic_cast<Stalactite*>(&other)) return FORCE_MOVE; 00105 00106 if (state != STALACTITE_FALLING) return BadGuy::collision_badguy(other, hit); 00107 00108 if (other.is_freezable()) { 00109 other.freeze(); 00110 } else { 00111 other.kill_fall(); 00112 } 00113 00114 return FORCE_MOVE; 00115 }
void Stalactite::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 118 of file stalactite.cpp.
void Stalactite::draw | ( | DrawingContext & | context | ) | [virtual] |
Called when the badguy is drawn.
The default implementation simply draws the badguy sprite on screen
Reimplemented from BadGuy.
Definition at line 123 of file stalactite.cpp.
References MovingObject::get_pos(), BadGuy::get_state(), MovingSprite::layer, LAYER_OBJECTS, shake_delta, MovingSprite::sprite, STALACTITE_SHAKING, STALACTITE_SQUISHED, state, BadGuy::STATE_INACTIVE, and BadGuy::STATE_INIT.
00124 { 00125 if(get_state() == STATE_INIT || get_state() == STATE_INACTIVE) 00126 return; 00127 00128 if(state == STALACTITE_SQUISHED) { 00129 sprite->draw(context, get_pos(), LAYER_OBJECTS); 00130 } else if(state == STALACTITE_SHAKING) { 00131 sprite->draw(context, get_pos() + shake_delta, layer); 00132 } else { 00133 sprite->draw(context, get_pos(), layer); 00134 } 00135 }
void Stalactite::deactivate | ( | ) | [virtual] |
called when the badguy has been deactivated
Reimplemented from BadGuy.
Definition at line 138 of file stalactite.cpp.
References GameObject::remove_me(), STALACTITE_HANGING, and state.
00139 { 00140 if(state != STALACTITE_HANGING) 00141 remove_me(); 00142 }
void Stalactite::squish | ( | ) |
Definition at line 65 of file stalactite.cpp.
References COLGROUP_MOVING_ONLY_STATIC, Physic::enable_gravity(), BadGuy::physic, BadGuy::run_dead_script(), MovingObject::set_group(), BadGuy::set_state(), Physic::set_velocity_x(), Physic::set_velocity_y(), MovingSprite::sprite, STALACTITE_SQUISHED, state, and BadGuy::STATE_SQUISHED.
Referenced by collision_solid().
00066 { 00067 state = STALACTITE_SQUISHED; 00068 physic.enable_gravity(true); 00069 physic.set_velocity_x(0); 00070 physic.set_velocity_y(0); 00071 set_state(STATE_SQUISHED); 00072 sprite->set_action("squished"); 00073 set_group(COLGROUP_MOVING_ONLY_STATIC); 00074 run_dead_script(); 00075 }
Timer Stalactite::timer [protected] |
Definition at line 47 of file stalactite.hpp.
Referenced by active_update(), and YetiStalactite::start_shaking().
StalactiteState Stalactite::state [protected] |
Reimplemented from BadGuy.
Definition at line 48 of file stalactite.hpp.
Referenced by YetiStalactite::active_update(), active_update(), collision_badguy(), collision_player(), collision_solid(), deactivate(), draw(), YetiStalactite::is_hanging(), squish(), YetiStalactite::start_shaking(), and YetiStalactite::update().
Vector Stalactite::shake_delta [protected] |