X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fmriceblock.cpp;h=0b9b9cefbd4ed7e67c44f111c939118c5bab50f7;hb=198f758764fff064a47630b5d0f1e3d6aabe95a8;hp=8b3a995f4247a406d4c11289ea5e389098533ad6;hpb=ff59adfe9b44e1447ae02a2f9705d695a280059e;p=supertux.git diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 8b3a995f4..0b9b9cefb 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -25,13 +25,14 @@ namespace { const float KICKSPEED = 500; const int MAXSQUISHES = 10; + const float NOKICK_TIME = 0.1f; } MrIceBlock::MrIceBlock(const lisp::Lisp& reader) : WalkingBadguy(reader, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), ice_state(ICESTATE_NORMAL), squishcount(0) { walk_speed = 80; - max_drop_height = 600; + max_drop_height = 600; sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); @@ -40,8 +41,8 @@ MrIceBlock::MrIceBlock(const lisp::Lisp& reader) MrIceBlock::MrIceBlock(const Vector& pos, Direction d) : WalkingBadguy(pos, d, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), ice_state(ICESTATE_NORMAL), squishcount(0) { - walk_speed = 80; - max_drop_height = 600; + walk_speed = 80; + max_drop_height = 600; sound_manager->preload("sounds/iceblock_bump.wav"); sound_manager->preload("sounds/stomp.wav"); sound_manager->preload("sounds/kick.wav"); @@ -56,9 +57,9 @@ MrIceBlock::write(lisp::Writer& writer) } void -MrIceBlock::activate() +MrIceBlock::initialize() { - WalkingBadguy::activate(); + WalkingBadguy::initialize(); set_state(ICESTATE_NORMAL); } @@ -81,6 +82,11 @@ MrIceBlock::active_update(float elapsed_time) BadGuy::active_update(elapsed_time); } +bool +MrIceBlock::can_break(){ + return ice_state == ICESTATE_KICKED; +} + void MrIceBlock::collision_solid(const CollisionHit& hit) { @@ -97,17 +103,6 @@ MrIceBlock::collision_solid(const CollisionHit& hit) WalkingBadguy::collision_solid(hit); break; case ICESTATE_KICKED: { -#if 0 - // TODO move these into bonusblock class - BonusBlock* bonusblock = dynamic_cast (&object); - if(bonusblock) { - bonusblock->try_open(); - } - Brick* brick = dynamic_cast (&object); - if(brick) { - brick->try_break(); - } -#endif if(hit.right && dir == RIGHT) { dir = LEFT; sound_manager->play("sounds/iceblock_bump.wav", get_pos()); @@ -143,6 +138,10 @@ MrIceBlock::collision_player(Player& player, const CollisionHit& hit) if(ice_state == ICESTATE_GRABBED) return FORCE_MOVE; + if(dir == UP) { + return FORCE_MOVE; + } + // handle kicks from left or right side if(ice_state == ICESTATE_FLAT && get_state() == STATE_ACTIVE) { if(hit.left) { @@ -157,7 +156,7 @@ MrIceBlock::collision_player(Player& player, const CollisionHit& hit) return FORCE_MOVE; } } - + return BadGuy::collision_player(player, hit); } @@ -180,33 +179,50 @@ MrIceBlock::collision_badguy(BadGuy& badguy, const CollisionHit& hit) } bool -MrIceBlock::collision_squished(Player& player) +MrIceBlock::collision_squished(GameObject& object) { switch(ice_state) { case ICESTATE_KICKED: + { + BadGuy* badguy = dynamic_cast(&object); + if (badguy) { + badguy->kill_fall(); + break; + } + } + + // fall through case ICESTATE_NORMAL: - squishcount++; - if(squishcount >= MAXSQUISHES) { - kill_fall(); - return true; + { + Player* player = dynamic_cast(&object); + squishcount++; + if ((squishcount >= MAXSQUISHES) || (player && player->does_buttjump)) { + kill_fall(); + return true; + } } set_state(ICESTATE_FLAT); + nokick_timer.start(NOKICK_TIME); break; case ICESTATE_FLAT: - if(player.get_pos().x < get_pos().x) { - dir = RIGHT; - } else { - dir = LEFT; + { + MovingObject* movingobject = dynamic_cast(&object); + if (movingobject && (movingobject->get_pos().x < get_pos().x)) { + dir = RIGHT; + } else { + dir = LEFT; + } } - set_state(ICESTATE_KICKED); + if (nokick_timer.check()) set_state(ICESTATE_KICKED); break; case ICESTATE_GRABBED: assert(false); break; } - player.bounce(*this); + Player* player = dynamic_cast(&object); + if (player) player->bounce(*this); return true; } @@ -215,22 +231,22 @@ MrIceBlock::set_state(IceState state) { if(ice_state == state) return; - - if(state == ICESTATE_FLAT) - flags |= FLAG_PORTABLE; - else - flags &= ~FLAG_PORTABLE; switch(state) { case ICESTATE_NORMAL: - WalkingBadguy::activate(); + WalkingBadguy::initialize(); break; case ICESTATE_FLAT: - sound_manager->play("sounds/stomp.wav", get_pos()); - physic.set_velocity_x(0); - physic.set_velocity_y(0); - - sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); + if(dir == UP) { + physic.set_velocity_y(-KICKSPEED); + bbox.set_size(34, 31.8f); + } else { + sound_manager->play("sounds/stomp.wav", get_pos()); + physic.set_velocity_x(0); + physic.set_velocity_y(0); + + sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); + } flat_timer.start(4); break; case ICESTATE_KICKED: @@ -239,7 +255,7 @@ MrIceBlock::set_state(IceState state) physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED); sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); // we should slide above 1 block holes now... - bbox.set_size(34, 31.8); + bbox.set_size(34, 31.8f); break; case ICESTATE_GRABBED: flat_timer.stop(); @@ -257,15 +273,21 @@ MrIceBlock::grab(MovingObject&, const Vector& pos, Direction dir) this->dir = dir; sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); set_state(ICESTATE_GRABBED); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); } void MrIceBlock::ungrab(MovingObject& , Direction dir) { this->dir = dir; - set_state(ICESTATE_KICKED); - set_group(COLGROUP_MOVING); + set_state(dir == UP ? ICESTATE_FLAT : ICESTATE_KICKED); + set_colgroup_active(COLGROUP_MOVING); +} + +bool +MrIceBlock::is_portable() const +{ + return ice_state == ICESTATE_FLAT; } IMPLEMENT_FACTORY(MrIceBlock, "mriceblock")