X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fmriceblock.cpp;h=8b3a995f4247a406d4c11289ea5e389098533ad6;hb=126aa9428c83eb1e17d4a75a55d15e3e6e0c6875;hp=7da4bf33d133dfa5489f0973b3784ace292c51b1;hpb=7ffe0f4a7fe4ee1d4041a684638d07557676624c;p=supertux.git diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 7da4bf33d..8b3a995f4 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,62 +12,54 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "mriceblock.hpp" #include "object/block.hpp" -static const float WALKSPEED = 80; -static const float KICKSPEED = 500; -static const int MAXSQUISHES = 10; +namespace { + const float KICKSPEED = 500; + const int MAXSQUISHES = 10; +} MrIceBlock::MrIceBlock(const lisp::Lisp& reader) - : ice_state(ICESTATE_NORMAL), squishcount(0) + : WalkingBadguy(reader, "images/creatures/mr_iceblock/mr_iceblock.sprite", "left", "right"), ice_state(ICESTATE_NORMAL), squishcount(0) { - reader.get("x", start_position.x); - reader.get("y", start_position.y); - bbox.set_size(31.8, 31.8); - sprite = sprite_manager->create("mriceblock"); - set_direction = false; + 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"); } -MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d) - : ice_state(ICESTATE_NORMAL), squishcount(0) +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) { - start_position.x = pos_x; - start_position.y = pos_y; - bbox.set_size(31.8, 31.8); - sprite = sprite_manager->create("mriceblock"); - set_direction = true; - initial_direction = d; + 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"); } void MrIceBlock::write(lisp::Writer& writer) { writer.start_list("mriceblock"); - - writer.write_float("x", start_position.x); - writer.write_float("y", start_position.y); - + WalkingBadguy::write(writer); writer.end_list("mriceblock"); } void MrIceBlock::activate() { - if (set_direction) { - dir = initial_direction; - } - - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); - sprite->set_action(dir == LEFT ? "left" : "right"); + WalkingBadguy::activate(); + set_state(ICESTATE_NORMAL); } void @@ -79,25 +71,34 @@ MrIceBlock::active_update(float elapsed_time) if(ice_state == ICESTATE_FLAT && flat_timer.check()) { set_state(ICESTATE_NORMAL); } - + + if (ice_state == ICESTATE_NORMAL) + { + WalkingBadguy::active_update(elapsed_time); + return; + } + BadGuy::active_update(elapsed_time); } -HitResponse -MrIceBlock::collision_solid(GameObject& object, const CollisionHit& hit) +void +MrIceBlock::collision_solid(const CollisionHit& hit) { - if(fabsf(hit.normal.y) > .5) { // floor or roof + update_on_ground_flag(hit); + + if(hit.top || hit.bottom) { // floor or roof physic.set_velocity_y(0); - return CONTINUE; + return; } + // hit left or right switch(ice_state) { case ICESTATE_NORMAL: - dir = dir == LEFT ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); + 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(); @@ -106,21 +107,25 @@ MrIceBlock::collision_solid(GameObject& object, const CollisionHit& hit) if(brick) { brick->try_break(); } - - dir = dir == LEFT ? RIGHT : LEFT; +#endif + if(hit.right && dir == RIGHT) { + dir = LEFT; + sound_manager->play("sounds/iceblock_bump.wav", get_pos()); + physic.set_velocity_x(-KICKSPEED); + } else if(hit.left && dir == LEFT) { + dir = RIGHT; + sound_manager->play("sounds/iceblock_bump.wav", get_pos()); + physic.set_velocity_x(KICKSPEED); + } sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); - physic.set_velocity_x(-physic.get_velocity_x()); - sound_manager->play("sounds/iceblock_bump.wav", get_pos()); break; } case ICESTATE_FLAT: physic.set_velocity_x(0); break; case ICESTATE_GRABBED: - return FORCE_MOVE; + break; } - - return CONTINUE; } HitResponse @@ -140,13 +145,12 @@ MrIceBlock::collision_player(Player& player, const CollisionHit& hit) // handle kicks from left or right side if(ice_state == ICESTATE_FLAT && get_state() == STATE_ACTIVE) { - // hit from left side - if(hit.normal.x > 0.7) { + if(hit.left) { dir = RIGHT; player.kick(); set_state(ICESTATE_KICKED); return FORCE_MOVE; - } else if(hit.normal.x < -0.7) { + } else if(hit.right) { dir = LEFT; player.kick(); set_state(ICESTATE_KICKED); @@ -162,12 +166,7 @@ MrIceBlock::collision_badguy(BadGuy& badguy, const CollisionHit& hit) { switch(ice_state) { case ICESTATE_NORMAL: - if(fabsf(hit.normal.x) > .8) { - dir = dir == LEFT ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); - } - return CONTINUE; + return WalkingBadguy::collision_badguy(badguy, hit); case ICESTATE_FLAT: return FORCE_MOVE; case ICESTATE_KICKED: @@ -222,14 +221,9 @@ MrIceBlock::set_state(IceState state) else flags &= ~FLAG_PORTABLE; - if(ice_state == ICESTATE_KICKED) { - bbox.set_size(31.8, 31.8); - } - switch(state) { case ICESTATE_NORMAL: - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); - sprite->set_action(dir == LEFT ? "left" : "right"); + WalkingBadguy::activate(); break; case ICESTATE_FLAT: sound_manager->play("sounds/stomp.wav", get_pos()); @@ -245,7 +239,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(32.5, 31.8); + bbox.set_size(34, 31.8); break; case ICESTATE_GRABBED: flat_timer.stop();