#include <icecrusher.hpp>
Inherits MovingSprite.
Public Member Functions | |
IceCrusher (const Reader &reader) | |
IceCrusher (const IceCrusher &icecrusher) | |
virtual HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
virtual void | collision_solid (const CollisionHit &hit) |
this function is called when the object collided with something solid | |
virtual void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
Protected Types | |
enum | IceCrusherState { IDLE, CRUSHING, RECOVERING } |
Protected Member Functions | |
Player * | get_nearest_player () |
bool | found_victim () |
void | set_state (IceCrusherState state, bool force=false) |
Protected Attributes | |
IceCrusherState | state |
Vector | start_position |
Physic | physic |
float | cooldown_timer |
Private Types | |
enum | IceCrusherSize { NORMAL, LARGE } |
Private Attributes | |
IceCrusherSize | ic_size |
Definition at line 28 of file icecrusher.hpp.
enum IceCrusher::IceCrusherState [protected] |
Definition at line 46 of file icecrusher.hpp.
00046 { 00047 IDLE, 00048 CRUSHING, 00049 RECOVERING 00050 };
enum IceCrusher::IceCrusherSize [private] |
IceCrusher::IceCrusher | ( | const Reader & | reader | ) |
Definition at line 37 of file icecrusher.cpp.
References MovingObject::get_bbox(), ic_size, LARGE, Rectf::p1, set_state(), MovingSprite::sprite, start_position, and state.
00037 : 00038 MovingSprite(reader, "images/creatures/icecrusher/icecrusher.sprite", LAYER_OBJECTS, COLGROUP_STATIC), 00039 state(IDLE), 00040 start_position(), 00041 physic(), 00042 cooldown_timer(0.0), 00043 ic_size(NORMAL) 00044 { 00045 start_position = get_bbox().p1; 00046 set_state(state, true); 00047 00048 float sprite_width = sprite->get_width (); 00049 if (sprite_width >= 128.0) 00050 ic_size = LARGE; 00051 }
IceCrusher::IceCrusher | ( | const IceCrusher & | icecrusher | ) |
HitResponse IceCrusher::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Definition at line 91 of file icecrusher.cpp.
References ABORT_MOVE, CollisionHit::bottom, CRUSHING, FORCE_MOVE, Player::is_invincible(), Player::kill(), BadGuy::kill_fall(), RECOVERING, set_state(), and state.
00092 { 00093 Player* player = dynamic_cast<Player*>(&other); 00094 00095 /* If the other object is the player, and the collision is at the bottom of 00096 * the ice crusher, hurt the player. */ 00097 if (player && hit.bottom) { 00098 if(player->is_invincible()) { 00099 if (state == CRUSHING) 00100 set_state(RECOVERING); 00101 return ABORT_MOVE; 00102 } 00103 player->kill(false); 00104 if (state == CRUSHING) 00105 set_state(RECOVERING); 00106 return FORCE_MOVE; 00107 } 00108 BadGuy* badguy = dynamic_cast<BadGuy*>(&other); 00109 if (badguy) { 00110 badguy->kill_fall(); 00111 } 00112 return FORCE_MOVE; 00113 }
void IceCrusher::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
this function is called when the object collided with something solid
Reimplemented from MovingObject.
Definition at line 116 of file icecrusher.cpp.
References CollisionHit::bottom, Sector::camera, cooldown_timer, CRUSHING, Sector::current(), ic_size, IDLE, LARGE, log_debug, PAUSE_TIME_LARGE, PAUSE_TIME_NORMAL, RECOVERING, set_state(), Camera::shake(), and state.
00117 { 00118 switch(state) { 00119 case IDLE: 00120 break; 00121 case CRUSHING: 00122 if (hit.bottom) { 00123 if (ic_size == LARGE) { 00124 cooldown_timer = PAUSE_TIME_LARGE; 00125 Sector::current()->camera->shake (/* frequency = */ .125f, /* x = */ 0.0, /* y = */ 16.0); 00126 } 00127 else { 00128 cooldown_timer = PAUSE_TIME_NORMAL; 00129 Sector::current()->camera->shake (/* frequency = */ .1f, /* x = */ 0.0, /* y = */ 8.0); 00130 } 00131 set_state(RECOVERING); 00132 } 00133 break; 00134 case RECOVERING: 00135 break; 00136 default: 00137 log_debug << "IceCrusher in invalid state" << std::endl; 00138 break; 00139 } 00140 }
void IceCrusher::update | ( | float | elapsed_time | ) | [virtual] |
This function is called once per frame and allows the object to update it's state.
The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)
Reimplemented from MovingSprite.
Definition at line 143 of file icecrusher.cpp.
References cooldown_timer, CRUSHING, found_victim(), MovingObject::get_bbox(), Physic::get_movement(), ic_size, IDLE, LARGE, log_debug, MAX_DROP_SPEED, MovingObject::movement, PAUSE_TIME_LARGE, PAUSE_TIME_NORMAL, physic, RECOVER_SPEED_LARGE, RECOVER_SPEED_NORMAL, RECOVERING, MovingObject::set_pos(), set_state(), start_position, state, and Vector::y.
00144 { 00145 if (cooldown_timer >= elapsed_time) 00146 { 00147 cooldown_timer -= elapsed_time; 00148 return; 00149 } 00150 else if (cooldown_timer != 0.0) 00151 { 00152 elapsed_time -= cooldown_timer; 00153 cooldown_timer = 0.0; 00154 } 00155 00156 switch(state) { 00157 case IDLE: 00158 movement = Vector (0, 0); 00159 if (found_victim()) 00160 set_state(CRUSHING); 00161 break; 00162 case CRUSHING: 00163 movement = physic.get_movement (elapsed_time); 00164 if (movement.y > MAX_DROP_SPEED) 00165 movement.y = MAX_DROP_SPEED; 00166 break; 00167 case RECOVERING: 00168 if (get_bbox().p1.y <= start_position.y+1) { 00169 set_pos(start_position); 00170 movement = Vector (0, 0); 00171 if (ic_size == LARGE) 00172 cooldown_timer = PAUSE_TIME_LARGE; 00173 else 00174 cooldown_timer = PAUSE_TIME_NORMAL; 00175 set_state(IDLE); 00176 } 00177 else { 00178 if (ic_size == LARGE) 00179 movement = Vector (0, RECOVER_SPEED_LARGE); 00180 else 00181 movement = Vector (0, RECOVER_SPEED_NORMAL); 00182 } 00183 break; 00184 default: 00185 log_debug << "IceCrusher in invalid state" << std::endl; 00186 break; 00187 } 00188 }
Player* IceCrusher::get_nearest_player | ( | ) | [protected] |
bool IceCrusher::found_victim | ( | ) | [protected] |
Definition at line 191 of file icecrusher.cpp.
References Sector::current(), DROP_ACTIVATION_DISTANCE, MovingObject::get_bbox(), Sector::get_nearest_player(), Rectf::p1, Rectf::p2, Vector::x, and Vector::y.
Referenced by update().
00192 { 00193 Player* player = Sector::current()->get_nearest_player (this->get_bbox ()); 00194 if (!player) return false; 00195 00196 const Rectf& player_bbox = player->get_bbox(); 00197 const Rectf& crusher_bbox = get_bbox(); 00198 if ((player_bbox.p1.y >= crusher_bbox.p2.y) /* player is below crusher */ 00199 && (player_bbox.p2.x > (crusher_bbox.p1.x - DROP_ACTIVATION_DISTANCE)) 00200 && (player_bbox.p1.x < (crusher_bbox.p2.x + DROP_ACTIVATION_DISTANCE))) 00201 return true; 00202 else 00203 return false; 00204 }
void IceCrusher::set_state | ( | IceCrusherState | state, | |
bool | force = false | |||
) | [protected] |
Definition at line 63 of file icecrusher.cpp.
References COLGROUP_MOVING_STATIC, COLGROUP_STATIC, CRUSHING, Physic::enable_gravity(), IDLE, log_debug, physic, RECOVERING, Physic::reset(), MovingObject::set_group(), and MovingSprite::sprite.
Referenced by collision(), collision_solid(), IceCrusher(), and update().
00064 { 00065 if ((this->state == state) && (!force)) return; 00066 switch(state) { 00067 case IDLE: 00068 set_group(COLGROUP_STATIC); 00069 physic.enable_gravity (false); 00070 sprite->set_action("idle"); 00071 break; 00072 case CRUSHING: 00073 set_group(COLGROUP_MOVING_STATIC); 00074 physic.reset (); 00075 physic.enable_gravity (true); 00076 sprite->set_action("crushing"); 00077 break; 00078 case RECOVERING: 00079 set_group(COLGROUP_MOVING_STATIC); 00080 physic.enable_gravity (false); 00081 sprite->set_action("recovering"); 00082 break; 00083 default: 00084 log_debug << "IceCrusher in invalid state" << std::endl; 00085 break; 00086 } 00087 this->state = state; 00088 }
IceCrusherState IceCrusher::state [protected] |
Definition at line 51 of file icecrusher.hpp.
Referenced by collision(), collision_solid(), IceCrusher(), and update().
Vector IceCrusher::start_position [protected] |
Physic IceCrusher::physic [protected] |
float IceCrusher::cooldown_timer [protected] |
IceCrusherSize IceCrusher::ic_size [private] |
Definition at line 65 of file icecrusher.hpp.
Referenced by collision_solid(), IceCrusher(), and update().