#include <mriceblock.hpp>
Inherits WalkingBadguy, and Portable.
Public Member Functions | |
MrIceBlock (const Reader &reader) | |
MrIceBlock (const Vector &pos, Direction d) | |
void | initialize () |
called immediately before the first call to initialize | |
HitResponse | collision (GameObject &object, const CollisionHit &hit) |
Called when a collision with another object occurred. | |
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. | |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
void | grab (MovingObject &object, const Vector &pos, Direction dir) |
called each frame when the object has been grabbed. | |
void | ungrab (MovingObject &object, Direction dir) |
bool | is_portable () const |
bool | can_break () |
True if this badguy can break bricks or open bonusblocks in his current form. | |
Protected Types | |
enum | IceState { ICESTATE_NORMAL, ICESTATE_FLAT, ICESTATE_GRABBED, ICESTATE_KICKED } |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
void | set_state (IceState state, bool up=false) |
Private Attributes | |
IceState | ice_state |
Timer | nokick_timer |
Timer | flat_timer |
int | squishcount |
Definition at line 23 of file mriceblock.hpp.
enum MrIceBlock::IceState [protected] |
Definition at line 45 of file mriceblock.hpp.
00045 { 00046 ICESTATE_NORMAL, 00047 ICESTATE_FLAT, 00048 ICESTATE_GRABBED, 00049 ICESTATE_KICKED 00050 };
MrIceBlock::MrIceBlock | ( | const Reader & | reader | ) |
Definition at line 32 of file mriceblock.cpp.
References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, and WalkingBadguy::walk_speed.
00032 : 00033 WalkingBadguy(reader, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), 00034 ice_state(ICESTATE_NORMAL), 00035 nokick_timer(), 00036 flat_timer(), 00037 squishcount(0) 00038 { 00039 walk_speed = 80; 00040 max_drop_height = 600; 00041 sound_manager->preload("sounds/iceblock_bump.wav"); 00042 sound_manager->preload("sounds/stomp.wav"); 00043 sound_manager->preload("sounds/kick.wav"); 00044 }
Definition at line 46 of file mriceblock.cpp.
References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, and WalkingBadguy::walk_speed.
00046 : 00047 WalkingBadguy(pos, d, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), 00048 ice_state(ICESTATE_NORMAL), 00049 nokick_timer(), 00050 flat_timer(), 00051 squishcount(0) 00052 { 00053 walk_speed = 80; 00054 max_drop_height = 600; 00055 sound_manager->preload("sounds/iceblock_bump.wav"); 00056 sound_manager->preload("sounds/stomp.wav"); 00057 sound_manager->preload("sounds/kick.wav"); 00058 }
void MrIceBlock::initialize | ( | ) | [virtual] |
called immediately before the first call to initialize
Reimplemented from WalkingBadguy.
Definition at line 61 of file mriceblock.cpp.
References ICESTATE_NORMAL, WalkingBadguy::initialize(), and set_state().
00062 { 00063 WalkingBadguy::initialize(); 00064 set_state(ICESTATE_NORMAL); 00065 }
HitResponse MrIceBlock::collision | ( | GameObject & | object, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when a collision with another object occurred.
The default implementation calls collision_player, collision_solid, collision_badguy and collision_squished
Reimplemented from BadGuy.
Definition at line 125 of file mriceblock.cpp.
References BadGuy::collision(), FORCE_MOVE, ice_state, and ICESTATE_GRABBED.
00126 { 00127 if(ice_state == ICESTATE_GRABBED) 00128 return FORCE_MOVE; 00129 00130 return BadGuy::collision(object, hit); 00131 }
void MrIceBlock::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
Called when the badguy collided with solid ground.
Reimplemented from WalkingBadguy.
Definition at line 92 of file mriceblock.cpp.
References CollisionHit::bottom, WalkingBadguy::collision_solid(), BadGuy::dir, MovingObject::get_pos(), Physic::get_velocity_x(), ice_state, ICESTATE_FLAT, ICESTATE_GRABBED, ICESTATE_KICKED, ICESTATE_NORMAL, LEFT, BadGuy::physic, SoundManager::play(), RIGHT, MovingSprite::set_action(), set_state(), Physic::set_velocity_x(), Physic::set_velocity_y(), sound_manager, CollisionHit::top, BadGuy::update_on_ground_flag(), and WalkingBadguy::walk_speed.
00093 { 00094 update_on_ground_flag(hit); 00095 00096 if(hit.top || hit.bottom) { // floor or roof 00097 physic.set_velocity_y(0); 00098 } 00099 00100 // hit left or right 00101 switch(ice_state) { 00102 case ICESTATE_NORMAL: 00103 WalkingBadguy::collision_solid(hit); 00104 break; 00105 case ICESTATE_KICKED: { 00106 if((hit.right && dir == RIGHT) || (hit.left && dir == LEFT)) { 00107 dir = (dir == LEFT) ? RIGHT : LEFT; 00108 sound_manager->play("sounds/iceblock_bump.wav", get_pos()); 00109 physic.set_velocity_x(-physic.get_velocity_x()*.975); 00110 } 00111 this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1); 00112 if(fabsf(physic.get_velocity_x()) < walk_speed*1.5) 00113 set_state(ICESTATE_NORMAL); 00114 break; 00115 } 00116 case ICESTATE_FLAT: 00117 physic.set_velocity_x(0); 00118 break; 00119 case ICESTATE_GRABBED: 00120 break; 00121 } 00122 }
HitResponse MrIceBlock::collision_badguy | ( | BadGuy & | badguy, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with another badguy.
Reimplemented from WalkingBadguy.
Definition at line 155 of file mriceblock.cpp.
References ABORT_MOVE, WalkingBadguy::collision_badguy(), FORCE_MOVE, ice_state, ICESTATE_FLAT, ICESTATE_KICKED, and ICESTATE_NORMAL.
00156 { 00157 switch(ice_state) { 00158 case ICESTATE_NORMAL: 00159 return WalkingBadguy::collision_badguy(badguy, hit); 00160 case ICESTATE_FLAT: 00161 return FORCE_MOVE; 00162 case ICESTATE_KICKED: 00163 badguy.kill_fall(); 00164 return FORCE_MOVE; 00165 default: 00166 assert(false); 00167 } 00168 00169 return ABORT_MOVE; 00170 }
HitResponse MrIceBlock::collision_player | ( | Player & | player, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with a player.
Reimplemented from BadGuy.
Definition at line 134 of file mriceblock.cpp.
References BadGuy::collision_player(), BadGuy::dir, FORCE_MOVE, BadGuy::get_state(), ice_state, ICESTATE_FLAT, ICESTATE_KICKED, Player::kick(), LEFT, CollisionHit::left, CollisionHit::right, RIGHT, set_state(), and BadGuy::STATE_ACTIVE.
00135 { 00136 // handle kicks from left or right side 00137 if(ice_state == ICESTATE_FLAT && get_state() == STATE_ACTIVE) { 00138 if(hit.left) { 00139 dir = RIGHT; 00140 player.kick(); 00141 set_state(ICESTATE_KICKED); 00142 return FORCE_MOVE; 00143 } else if(hit.right) { 00144 dir = LEFT; 00145 player.kick(); 00146 set_state(ICESTATE_KICKED); 00147 return FORCE_MOVE; 00148 } 00149 } 00150 00151 return BadGuy::collision_player(player, hit); 00152 }
void MrIceBlock::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from WalkingBadguy.
Definition at line 68 of file mriceblock.cpp.
References BadGuy::active_update(), WalkingBadguy::active_update(), Timer::check(), flat_timer, ice_state, ICESTATE_FLAT, ICESTATE_GRABBED, ICESTATE_NORMAL, and set_state().
00069 { 00070 if(ice_state == ICESTATE_GRABBED) 00071 return; 00072 00073 if(ice_state == ICESTATE_FLAT && flat_timer.check()) { 00074 set_state(ICESTATE_NORMAL); 00075 } 00076 00077 if (ice_state == ICESTATE_NORMAL) 00078 { 00079 WalkingBadguy::active_update(elapsed_time); 00080 return; 00081 } 00082 00083 BadGuy::active_update(elapsed_time); 00084 }
void MrIceBlock::grab | ( | MovingObject & | object, | |
const Vector & | pos, | |||
Direction | dir | |||
) | [virtual] |
called each frame when the object has been grabbed.
Implements Portable.
Definition at line 264 of file mriceblock.cpp.
References COLGROUP_DISABLED, MovingObject::get_pos(), ICESTATE_GRABBED, LEFT, MovingObject::movement, MovingSprite::set_action(), BadGuy::set_colgroup_active(), and set_state().
00265 { 00266 movement = pos - get_pos(); 00267 this->dir = dir; 00268 this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1); 00269 set_state(ICESTATE_GRABBED); 00270 set_colgroup_active(COLGROUP_DISABLED); 00271 }
void MrIceBlock::ungrab | ( | MovingObject & | object, | |
Direction | dir | |||
) | [virtual] |
Reimplemented from Portable.
Definition at line 274 of file mriceblock.cpp.
References COLGROUP_MOVING, ICESTATE_FLAT, ICESTATE_KICKED, BadGuy::set_colgroup_active(), set_state(), and UP.
00275 { 00276 if(dir == UP) { 00277 set_state(ICESTATE_FLAT, true); 00278 } else { 00279 this->dir = dir; 00280 set_state(ICESTATE_KICKED); 00281 } 00282 set_colgroup_active(COLGROUP_MOVING); 00283 }
bool MrIceBlock::is_portable | ( | ) | const [virtual] |
Reimplemented from Portable.
Definition at line 286 of file mriceblock.cpp.
References ice_state, and ICESTATE_FLAT.
00287 { 00288 return ice_state == ICESTATE_FLAT; 00289 }
bool MrIceBlock::can_break | ( | ) | [virtual] |
True if this badguy can break bricks or open bonusblocks in his current form.
Reimplemented from BadGuy.
Definition at line 87 of file mriceblock.cpp.
References ice_state, and ICESTATE_KICKED.
00087 { 00088 return ice_state == ICESTATE_KICKED; 00089 }
bool MrIceBlock::collision_squished | ( | GameObject & | object | ) | [protected, virtual] |
Called when the player hit the badguy from above.
You should return true if the badguy was squished, false if squishing wasn't possible
Reimplemented from BadGuy.
Definition at line 173 of file mriceblock.cpp.
References Player::bounce(), Timer::check(), BadGuy::dir, Player::does_buttjump, MovingObject::get_pos(), ice_state, ICESTATE_FLAT, ICESTATE_GRABBED, ICESTATE_KICKED, ICESTATE_NORMAL, Player::is_invincible(), BadGuy::kill_fall(), LEFT, MAXSQUISHES, NOKICK_TIME, nokick_timer, RIGHT, set_state(), squishcount, Timer::start(), and Vector::x.
00174 { 00175 Player* player = dynamic_cast<Player*>(&object); 00176 if(player && (player->does_buttjump || player->is_invincible())) { 00177 player->bounce(*this); 00178 kill_fall(); 00179 return true; 00180 } 00181 00182 switch(ice_state) { 00183 case ICESTATE_KICKED: 00184 { 00185 BadGuy* badguy = dynamic_cast<BadGuy*>(&object); 00186 if (badguy) { 00187 badguy->kill_fall(); 00188 break; 00189 } 00190 } 00191 00192 // fall through 00193 case ICESTATE_NORMAL: 00194 { 00195 squishcount++; 00196 if (squishcount >= MAXSQUISHES) { 00197 kill_fall(); 00198 return true; 00199 } 00200 } 00201 00202 set_state(ICESTATE_FLAT); 00203 nokick_timer.start(NOKICK_TIME); 00204 break; 00205 case ICESTATE_FLAT: 00206 { 00207 MovingObject* movingobject = dynamic_cast<MovingObject*>(&object); 00208 if (movingobject && (movingobject->get_pos().x < get_pos().x)) { 00209 dir = RIGHT; 00210 } else { 00211 dir = LEFT; 00212 } 00213 } 00214 if (nokick_timer.check()) set_state(ICESTATE_KICKED); 00215 break; 00216 case ICESTATE_GRABBED: 00217 assert(false); 00218 break; 00219 } 00220 00221 if (player) player->bounce(*this); 00222 return true; 00223 }
void MrIceBlock::set_state | ( | IceState | state, | |
bool | up = false | |||
) | [protected] |
Definition at line 226 of file mriceblock.cpp.
References MovingObject::bbox, BadGuy::dir, flat_timer, MovingObject::get_pos(), ice_state, ICESTATE_FLAT, ICESTATE_GRABBED, ICESTATE_KICKED, ICESTATE_NORMAL, WalkingBadguy::initialize(), KICKSPEED, LEFT, BadGuy::physic, SoundManager::play(), MovingSprite::set_action(), Rectf::set_size(), Physic::set_velocity_x(), Physic::set_velocity_y(), sound_manager, Timer::start(), and Timer::stop().
Referenced by active_update(), collision_player(), collision_solid(), collision_squished(), grab(), initialize(), and ungrab().
00227 { 00228 if(ice_state == state) 00229 return; 00230 00231 switch(state) { 00232 case ICESTATE_NORMAL: 00233 WalkingBadguy::initialize(); 00234 break; 00235 case ICESTATE_FLAT: 00236 if(up) { 00237 physic.set_velocity_y(-KICKSPEED); 00238 } else { 00239 sound_manager->play("sounds/stomp.wav", get_pos()); 00240 physic.set_velocity_x(0); 00241 physic.set_velocity_y(0); 00242 } 00243 this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1); 00244 flat_timer.start(4); 00245 break; 00246 case ICESTATE_KICKED: 00247 sound_manager->play("sounds/kick.wav", get_pos()); 00248 00249 physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); 00250 this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1); 00251 // we should slide above 1 block holes now... 00252 bbox.set_size(34, 31.8f); 00253 break; 00254 case ICESTATE_GRABBED: 00255 flat_timer.stop(); 00256 break; 00257 default: 00258 assert(false); 00259 } 00260 ice_state = state; 00261 }
IceState MrIceBlock::ice_state [private] |
Definition at line 57 of file mriceblock.hpp.
Referenced by active_update(), can_break(), collision(), collision_badguy(), collision_player(), collision_solid(), collision_squished(), is_portable(), and set_state().
Timer MrIceBlock::nokick_timer [private] |
Timer MrIceBlock::flat_timer [private] |
int MrIceBlock::squishcount [private] |