From 3510a03c0e807c7a0ddde3cdf07ba91bda9393c4 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 29 Nov 2004 00:12:25 +0000 Subject: [PATCH] make badguys bounce of each other again, make bombs and kicked mriceblocks kill other enemies, make kicked mriceblock open bonusblocks and destroy bricks SVN-Revision: 2218 --- TODO | 2 -- src/badguy/badguy.cpp | 2 +- src/badguy/bomb.cpp | 7 +++++++ src/badguy/bomb.h | 1 + src/badguy/bouncing_snowball.cpp | 14 ++++++++++++++ src/badguy/bouncing_snowball.h | 1 + src/badguy/jumpy.cpp | 19 +++++++++++++++---- src/badguy/jumpy.h | 9 ++++++--- src/badguy/mrbomb.cpp | 11 +++++++++++ src/badguy/mrbomb.h | 1 + src/badguy/mriceblock.cpp | 38 ++++++++++++++++++++++++++++++++++++-- src/badguy/mriceblock.h | 3 ++- src/badguy/snowball.cpp | 12 ++++++++++++ src/badguy/snowball.h | 1 + src/badguy/spiky.cpp | 12 ++++++++++++ src/badguy/spiky.h | 1 + src/object/block.cpp | 23 ++++++++++++++++++++--- src/object/block.h | 4 ++++ 18 files changed, 145 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index d26e62463..49cd9f6fc 100644 --- a/TODO +++ b/TODO @@ -45,8 +45,6 @@ L: low priority - implement wingling - implement tree (really?) - bring back stay on platform flag - - make enemies bounce of upon each other again - - make enemies fall again - ok ** implement ability to cary mriceblock (and other objects) around - delayed for after big commit... * smoke clouds are too fast diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 25825a4c3..f95f2015e 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -97,7 +97,7 @@ BadGuy::collision(GameObject& other, const CollisionHit& hit) return collision_solid(other, hit); BadGuy* badguy = dynamic_cast (&other); - if(badguy) + if(badguy && badguy->state == STATE_ACTIVE) return collision_badguy(*badguy, hit); Player* player = dynamic_cast (&other); diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 2897e687a..c7445a278 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -41,6 +41,13 @@ Bomb::collision_player(Player& player, const CollisionHit& ) return ABORT_MOVE; } +HitResponse +Bomb::collision_badguy(BadGuy& badguy, const CollisionHit& ) +{ + badguy.kill_fall(); + return ABORT_MOVE; +} + void Bomb::active_action(float ) { diff --git a/src/badguy/bomb.h b/src/badguy/bomb.h index fc3beec95..3813776ed 100644 --- a/src/badguy/bomb.h +++ b/src/badguy/bomb.h @@ -11,6 +11,7 @@ public: void write(lisp::Writer& writer); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); HitResponse collision_player(Player& player, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); void active_action(float elapsed_time); void kill_fall(); diff --git a/src/badguy/bouncing_snowball.cpp b/src/badguy/bouncing_snowball.cpp index 431cac254..06d70f8f0 100644 --- a/src/badguy/bouncing_snowball.cpp +++ b/src/badguy/bouncing_snowball.cpp @@ -67,3 +67,17 @@ BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } +HitResponse +BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.x) > .8) { // left/right? + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } else if(hit.normal.y < -.8) { // grounf + physic.set_velocity_y(JUMPSPEED); + } + + return CONTINUE; +} + diff --git a/src/badguy/bouncing_snowball.h b/src/badguy/bouncing_snowball.h index d53badf12..63afe0545 100644 --- a/src/badguy/bouncing_snowball.h +++ b/src/badguy/bouncing_snowball.h @@ -12,6 +12,7 @@ public: void activate(); void write(lisp::Writer& writer); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); protected: bool collision_squished(Player& player); diff --git a/src/badguy/jumpy.cpp b/src/badguy/jumpy.cpp index bc8dffef4..abc48ab6c 100644 --- a/src/badguy/jumpy.cpp +++ b/src/badguy/jumpy.cpp @@ -24,15 +24,26 @@ Jumpy::write(lisp::Writer& writer) } HitResponse -Jumpy::collision_solid(GameObject& , const CollisionHit& hit) +Jumpy::collision_solid(GameObject& , const CollisionHit& chit) +{ + return hit(chit); +} + +HitResponse +Jumpy::collision_badguy(BadGuy& , const CollisionHit& chit) +{ + return hit(chit); +} + +HitResponse +Jumpy::hit(const CollisionHit& chit) { // hit floor? - if(hit.normal.y < -.5) { + if(chit.normal.y < -.5) { physic.set_velocity_y(JUMPSPEED); - } else if(hit.normal.y < .5) { // bumped on roof + } else if(chit.normal.y < .5) { // bumped on roof physic.set_velocity_y(0); } return CONTINUE; } - diff --git a/src/badguy/jumpy.h b/src/badguy/jumpy.h index e33f6eb62..eaeafa652 100644 --- a/src/badguy/jumpy.h +++ b/src/badguy/jumpy.h @@ -8,10 +8,13 @@ class Jumpy : public BadGuy public: Jumpy(const lisp::Lisp& reader); - virtual HitResponse collision_solid(GameObject& other, - const CollisionHit& hit); + HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit); - virtual void write(lisp::Writer& writer); + void write(lisp::Writer& writer); + +private: + HitResponse hit(const CollisionHit& hit); }; #endif diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 76222d28f..bc9903d78 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -66,3 +66,14 @@ MrBomb::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } +HitResponse +MrBomb::collision_badguy(BadGuy& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.x) > .8) { // left or right + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } + + return CONTINUE; +} diff --git a/src/badguy/mrbomb.h b/src/badguy/mrbomb.h index fda40fb8b..4e7943cd7 100644 --- a/src/badguy/mrbomb.h +++ b/src/badguy/mrbomb.h @@ -12,6 +12,7 @@ public: void activate(); void write(lisp::Writer& writer); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); protected: bool collision_squished(Player& player); diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index e0bdbf66b..9c5ad78e2 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -1,6 +1,7 @@ #include #include "mriceblock.h" +#include "object/block.h" static const float WALKSPEED = 80; static const float KICKSPEED = 500; @@ -59,7 +60,7 @@ MrIceBlock::active_action(float elapsed_time) } HitResponse -MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit) +MrIceBlock::collision_solid(GameObject& object, const CollisionHit& hit) { if(fabsf(hit.normal.y) > .5) { // floor or roof physic.set_velocity_y(0); @@ -72,13 +73,23 @@ MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit) sprite->set_action(dir == LEFT ? "left" : "right"); physic.set_velocity_x(-physic.get_velocity_x()); break; - case ICESTATE_KICKED: + case ICESTATE_KICKED: { + BonusBlock* bonusblock = dynamic_cast (&object); + if(bonusblock) { + bonusblock->try_open(); + } + Brick* brick = dynamic_cast (&object); + if(brick) { + brick->try_break(); + } + dir = dir == LEFT ? RIGHT : LEFT; sprite->set_action(dir == LEFT ? "flat-left" : "flat-right"); physic.set_velocity_x(-physic.get_velocity_x()); SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(), Sector::current()->player->get_pos()); break; + } case ICESTATE_FLAT: physic.set_velocity_x(0); break; @@ -87,6 +98,29 @@ MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } +HitResponse +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; + case ICESTATE_FLAT: + return FORCE_MOVE; + case ICESTATE_KICKED: + badguy.kill_fall(); + return FORCE_MOVE; + default: + assert(false); + } + + return ABORT_MOVE; +} + bool MrIceBlock::collision_squished(Player& player) { diff --git a/src/badguy/mriceblock.h b/src/badguy/mriceblock.h index 3a6d2a63d..54ec05d3f 100644 --- a/src/badguy/mriceblock.h +++ b/src/badguy/mriceblock.h @@ -11,7 +11,8 @@ public: void activate(); void write(lisp::Writer& writer); - HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_solid(GameObject& object, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); void active_action(float elapsed_time); diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index 4442d02a9..4efd93874 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -64,3 +64,15 @@ SnowBall::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } +HitResponse +SnowBall::collision_badguy(BadGuy& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.x) > .8) { // left or right hit + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } + + return CONTINUE; +} + diff --git a/src/badguy/snowball.h b/src/badguy/snowball.h index 47acaf0aa..172aac9ab 100644 --- a/src/badguy/snowball.h +++ b/src/badguy/snowball.h @@ -12,6 +12,7 @@ public: void activate(); void write(lisp::Writer& writer); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit); protected: bool collision_squished(Player& player); diff --git a/src/badguy/spiky.cpp b/src/badguy/spiky.cpp index 255bb9e18..b419740df 100644 --- a/src/badguy/spiky.cpp +++ b/src/badguy/spiky.cpp @@ -44,3 +44,15 @@ Spiky::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } +HitResponse +Spiky::collision_badguy(BadGuy& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.x) > .8) { // left or right + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } + + return CONTINUE; +} + diff --git a/src/badguy/spiky.h b/src/badguy/spiky.h index 2c48e2973..fb24749f6 100644 --- a/src/badguy/spiky.h +++ b/src/badguy/spiky.h @@ -11,6 +11,7 @@ public: void activate(); void write(lisp::Writer& writer); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); }; #endif diff --git a/src/object/block.cpp b/src/object/block.cpp index 0dcc549fd..ccede815c 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -101,7 +101,13 @@ BonusBlock::BonusBlock(const Vector& pos, int newdata) } void -BonusBlock::hit(Player& player) +BonusBlock::hit(Player& ) +{ + try_open(); +} + +void +BonusBlock::try_open() { if(sprite->get_action_name() == "empty") { SoundManager::get()->play_sound(IDToSound(SND_BRICK)); @@ -109,6 +115,7 @@ BonusBlock::hit(Player& player) } Sector* sector = Sector::current(); + Player& player = *(sector->player); switch(data) { case 1: // coin Sector::current()->add_object(new BouncyCoin(get_pos())); @@ -170,13 +177,23 @@ Brick::Brick(const Vector& pos, int data) } void -Brick::hit(Player& player) +Brick::hit(Player& ) +{ + if(sprite->get_action_name() == "empty") + return; + + try_break(true); +} + +void +Brick::try_break(bool playerhit) { if(sprite->get_action_name() == "empty") return; SoundManager::get()->play_sound(IDToSound(SND_BRICK)); Sector* sector = Sector::current(); + Player& player = *(sector->player); if(coin_counter > 0) { sector->add_object(new BouncyCoin(get_pos())); coin_counter--; @@ -185,7 +202,7 @@ Brick::hit(Player& player) sprite->set_action("empty"); start_bounce(); } else if(breakable) { - if(player.size == SMALL) { + if(playerhit && player.size == SMALL) { start_bounce(); return; } diff --git a/src/object/block.h b/src/object/block.h index 3f97f7f9e..ae11d2281 100644 --- a/src/object/block.h +++ b/src/object/block.h @@ -36,6 +36,8 @@ class BonusBlock : public Block public: BonusBlock(const Vector& pos, int data); + void try_open(); + protected: virtual void hit(Player& player); @@ -48,6 +50,8 @@ class Brick : public Block public: Brick(const Vector& pos, int data); + void try_break(bool playerhit = false); + protected: virtual void hit(Player& player); -- 2.11.0