From 72fec61025ea98c4212a54edd2118af49825e8f2 Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Sun, 6 Jan 2008 02:43:17 +0000 Subject: [PATCH] Badguys that die will still trigger collisions during the current frame (closes issue 50) SVN-Revision: 5255 --- src/badguy/badguy.cpp | 72 +++++++++++++++++++++++++-------------------------- src/badguy/badguy.hpp | 6 +++++ 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 19e8d8b49..6932362f9 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -94,6 +94,7 @@ void BadGuy::update(float elapsed_time) { if(!Sector::current()->inside(bbox)) { + is_active_flag = false; remove_me(); return; } @@ -104,14 +105,17 @@ BadGuy::update(float elapsed_time) switch(state) { case STATE_ACTIVE: + is_active_flag = true; active_update(elapsed_time); break; case STATE_INIT: case STATE_INACTIVE: + is_active_flag = false; inactive_update(elapsed_time); try_activate(); break; case STATE_SQUISHED: + is_active_flag = false; if(state_timer.check()) { remove_me(); break; @@ -119,6 +123,7 @@ BadGuy::update(float elapsed_time) movement = physic.get_movement(elapsed_time); break; case STATE_FALLING: + is_active_flag = false; movement = physic.get_movement(elapsed_time); break; } @@ -187,50 +192,39 @@ BadGuy::collision_tile(uint32_t tile_attributes) HitResponse BadGuy::collision(GameObject& other, const CollisionHit& hit) { - switch(state) { - case STATE_INIT: - case STATE_INACTIVE: - return ABORT_MOVE; - case STATE_ACTIVE: { - BadGuy* badguy = dynamic_cast (&other); - if(badguy && badguy->state == STATE_ACTIVE && badguy->get_group() == COLGROUP_MOVING) { - - // hit from above? - if (badguy->get_bbox().p2.y < (bbox.p1.y + 16)) { - if(collision_squished(*badguy)) { - return ABORT_MOVE; - } - } - - return collision_badguy(*badguy, hit); - } - - Player* player = dynamic_cast (&other); - if(player) { + if (!is_active()) return ABORT_MOVE; - // hit from above? - if (player->get_bbox().p2.y < (bbox.p1.y + 16)) { - if(collision_squished(*player)) { - return ABORT_MOVE; - } - } + BadGuy* badguy = dynamic_cast (&other); + if(badguy && badguy->is_active() && badguy->get_group() == COLGROUP_MOVING) { - return collision_player(*player, hit); + // hit from above? + if (badguy->get_bbox().p2.y < (bbox.p1.y + 16)) { + if(collision_squished(*badguy)) { + return ABORT_MOVE; } + } - Bullet* bullet = dynamic_cast (&other); - if(bullet) - return collision_bullet(*bullet, hit); + return collision_badguy(*badguy, hit); + } - return FORCE_MOVE; + Player* player = dynamic_cast (&other); + if(player) { + + // hit from above? + if (player->get_bbox().p2.y < (bbox.p1.y + 16)) { + if(collision_squished(*player)) { + return ABORT_MOVE; + } } - case STATE_SQUISHED: - return FORCE_MOVE; - case STATE_FALLING: - return FORCE_MOVE; + + return collision_player(*player, hit); } - return ABORT_MOVE; + Bullet* bullet = dynamic_cast (&other); + if(bullet) + return collision_bullet(*bullet, hit); + + return FORCE_MOVE; } void @@ -524,6 +518,12 @@ BadGuy::on_ground() return on_ground_flag; } +bool +BadGuy::is_active() +{ + return is_active_flag; +} + Vector BadGuy::get_floor_normal() { diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index e446133a7..31a5a2dae 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -233,10 +233,16 @@ protected: std::string dead_script; /**< script to execute when badguy is killed */ + /** + * Returns true if we were in STATE_ACTIVE at the beginning of the last call to update() + */ + bool is_active(); + private: void try_activate(); State state; + bool is_active_flag; /**< true if state was STATE_ACTIVE at the beginning of the last call to update() */ Timer state_timer; bool on_ground_flag; /**< true if we touched something solid from above and update_on_ground_flag was called last frame */ Vector floor_normal; /**< floor normal stored the last time when update_on_ground_flag was called and we touched something solid from above */ -- 2.11.0