From: Wolfgang Becker Date: Wed, 12 Jul 2006 23:04:09 +0000 (+0000) Subject: Bonusblock and Bricks now break themself when hit by MrIceblock or Snail. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c8303cceed3279a3580829a28bbb2d7b8d89843b;p=supertux.git Bonusblock and Bricks now break themself when hit by MrIceblock or Snail. SVN-Revision: 3993 --- diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 44613e47f..51521397a 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -72,6 +72,14 @@ public: */ virtual void save(lisp::Writer& writer); + /** + * True if this badguy can break bricks or open bonusblocks in his current form. + */ + virtual bool can_break() + { + return false; + } + Vector get_start_position() const { return start_position; diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index 8b3a995f4..472aa1757 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -81,6 +81,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 +102,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()); diff --git a/src/badguy/mriceblock.hpp b/src/badguy/mriceblock.hpp index 4f95bd95d..98c4225d1 100644 --- a/src/badguy/mriceblock.hpp +++ b/src/badguy/mriceblock.hpp @@ -40,6 +40,7 @@ public: void grab(MovingObject& object, const Vector& pos, Direction dir); void ungrab(MovingObject& object, Direction dir); + bool can_break(); virtual MrIceBlock* clone() const { return new MrIceBlock(*this); } diff --git a/src/badguy/snail.cpp b/src/badguy/snail.cpp index f54573fd0..cb34a8f1f 100644 --- a/src/badguy/snail.cpp +++ b/src/badguy/snail.cpp @@ -99,6 +99,10 @@ Snail::be_kicked() kicked_delay_timer.start(0.05); } +bool +Snail::can_break(){ + return state == STATE_KICKED; +} void Snail::active_update(float elapsed_time) @@ -168,18 +172,6 @@ Snail::collision_solid(const CollisionHit& hit) if(hit.left || hit.right) { sound_manager->play("sounds/iceblock_bump.wav", get_pos()); -#if 0 - // TODO move this into BonusBlock code - // open bonusblocks, crash bricks - BonusBlock* bonusblock = dynamic_cast (&object); - if(bonusblock) { - bonusblock->try_open(); - } - Brick* brick = dynamic_cast (&object); - if(brick) { - brick->try_break(); - } -#endif if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){ dir = (dir == LEFT) ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); diff --git a/src/badguy/snail.hpp b/src/badguy/snail.hpp index 83f4a1060..7427f02cd 100644 --- a/src/badguy/snail.hpp +++ b/src/badguy/snail.hpp @@ -35,6 +35,7 @@ public: void write(lisp::Writer& writer); void collision_solid(const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); + bool can_break(); void active_update(float elapsed_time); diff --git a/src/object/block.cpp b/src/object/block.cpp index 95520d615..ce727af85 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -202,6 +202,18 @@ BonusBlock::hit(Player& ) try_open(); } +HitResponse +BonusBlock::collision(GameObject& other, const CollisionHit& hit){ + BadGuy* badguy = dynamic_cast (&other); + if(badguy) { + // if( badguy->can_break() && (hit.left||hit.right||hit.bottom) ){ //TODO: find out why hit contains no information and fix it + if( badguy->can_break() && ( badguy->get_pos().y > get_pos().y ) ){ + try_open(); + } + } + return Block::collision(other, hit); +} + void BonusBlock::try_open() { @@ -286,6 +298,18 @@ Brick::hit(Player& ) try_break(true); } +HitResponse +Brick::collision(GameObject& other, const CollisionHit& hit){ + BadGuy* badguy = dynamic_cast (&other); + if(badguy) { + // if( badguy->can_break() && (hit.left||hit.right||hit.bottom) ){ //TODO: find out why hit contains no information and fix it + if( badguy->can_break() && ( badguy->get_pos().y > get_pos().y ) ){ + try_break(false); + } + } + return Block::collision(other, hit); +} + void Brick::try_break(bool playerhit) { diff --git a/src/object/block.hpp b/src/object/block.hpp index 07b37cbb0..462e8ff63 100644 --- a/src/object/block.hpp +++ b/src/object/block.hpp @@ -56,6 +56,7 @@ public: BonusBlock(const Vector& pos, int data); BonusBlock(const lisp::Lisp& lisp); virtual ~BonusBlock(); + HitResponse collision(GameObject& other, const CollisionHit& hit); void try_open(); @@ -82,6 +83,7 @@ public: Brick(const Vector& pos, int data); void try_break(bool playerhit = false); + HitResponse collision(GameObject& other, const CollisionHit& hit); protected: virtual void hit(Player& player);