From: Christoph Sommer Date: Thu, 4 May 2006 19:26:47 +0000 (+0000) Subject: Badguys are now responsible for killing themselves when hit by a bullet X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=25ed951bc477e74992cbb0bd86103f8732e25a38;p=supertux.git Badguys are now responsible for killing themselves when hit by a bullet SVN-Revision: 3491 --- diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index fb2fff941..0870ead41 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -27,6 +27,7 @@ #include "game_session.hpp" #include "log.hpp" #include "level.hpp" +#include "object/bullet.hpp" static const float SQUISH_TIME = 2; static const float X_OFFSCREEN_DISTANCE = 1600; @@ -145,6 +146,10 @@ BadGuy::collision(GameObject& other, const CollisionHit& hit) if(player) return collision_player(*player, hit); + Bullet* bullet = dynamic_cast (&other); + if(bullet) + return collision_bullet(*bullet, hit); + return FORCE_MOVE; } case STATE_SQUISHED: @@ -203,6 +208,13 @@ BadGuy::collision_squished(Player& ) return false; } +HitResponse +BadGuy::collision_bullet(Bullet& , const CollisionHit& ) +{ + kill_fall(); + return ABORT_MOVE; +} + void BadGuy::kill_squished(Player& player) { diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 8cbfb183a..182ab6e0a 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -111,6 +111,10 @@ protected: */ virtual bool collision_squished(Player& player); + /** Called when the badguy collided with a bullet */ + virtual HitResponse collision_bullet(Bullet& bullet, + const CollisionHit& hit); + /** called each frame when the badguy is activated. */ virtual void active_update(float elapsed_time); /** called each frame when the badguy is not activated. */ diff --git a/src/object/bullet.cpp b/src/object/bullet.cpp index e878660b0..40d9a5e4c 100644 --- a/src/object/bullet.cpp +++ b/src/object/bullet.cpp @@ -105,9 +105,9 @@ Bullet::collision(GameObject& other, const CollisionHit& hit) return CONTINUE; } + // hit a Badguy BadGuy* badguy = dynamic_cast (&other); if(badguy) { - badguy->kill_fall(); remove_me(); return FORCE_MOVE; }