From f342eab71dbf70aa5104df60d22a725924621289 Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Mon, 24 Apr 2006 17:50:42 +0000 Subject: [PATCH] Replaced may_fall_off_platform() with might_fall() SVN-Revision: 3415 --- src/badguy/badguy.cpp | 42 ------------------------------------------ src/badguy/badguy.hpp | 6 +++--- src/badguy/mrbomb.cpp | 2 +- src/badguy/mrtree.cpp | 2 +- src/badguy/totem.cpp | 2 +- 5 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index e623054af..22f79349f 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -319,48 +319,6 @@ BadGuy::try_activate() } bool -BadGuy::may_fall_off_platform() -{ - int tile_x, tile_y; - // First, let's say the badguy moves 32 units in the - // direction it's heading, so do some voodoo maths magic - // to determine its future position. - Vector pos; - if (dir == LEFT) - pos = Vector(bbox.p1.x - 32.f, bbox.p2.y); - else - pos = Vector(bbox.p2.x, bbox.p2.y); - - // Now, snap the badguy's X coordinate to the 32x32/cell grid. - if (dir == LEFT) // use the ceiling - tile_x = (int)ceilf(pos.x/32.0f); - else // use the floor - tile_x = (int)floorf(pos.x/32.0f); - - // We might be falling down, so use the ceiling to round upward and - // get the lower position. (Positive Y goes downward.) - tile_y = (int)ceilf(pos.y/32.0f); - -#if defined(DEBUG_STAY_ON_PLATFORM) - // Draw! - GameSession::current()->context->draw_filled_rect(Vector(tile_x*32.0f, tile_y*32.0f), Vector(32.f, 32.f), Color(1.f, 0.f, 0.f), 999); -#endif - - // Now, if the badguy intersects with a tile, he won't fall off. - // If he doesn't intersect, he probably will. - // Note that the tile's Y coordinate is offset by +1 from the object's Y. - if (Sector::current()->solids->get_tile(tile_x, tile_y)->getAttributes() - & Tile::SOLID) - { - // It's a solid tile. Good. - return false; - } - - // Watch out there buddy, you might take a sticky end! - return true; -} - -bool BadGuy::might_fall(int height) { // make sure we check for at least a 1-pixel fall diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 872d2acb0..eb0d0ccb1 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -146,10 +146,10 @@ protected: */ bool is_offscreen(); /** - * Checks if the badguy may fall off a platform if continuing a given movement. + * Returns true if we might soon fall at least @c height pixels. Minimum + * value for height is 1 pixel */ - bool may_fall_off_platform(); - bool might_fall(int height); /**< returns true if we might soon fall at least @c height pixels. Minimum value for height is 1 pixel */ + bool might_fall(int height = 1); Vector start_position; diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 586748080..67722369b 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -65,7 +65,7 @@ MrBomb::activate() void MrBomb::active_update(float elapsed_time) { - if (may_fall_off_platform()) + if (might_fall()) { dir = (dir == LEFT ? RIGHT : LEFT); sprite->set_action(dir == LEFT ? "left" : "right"); diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 3ad7ab40e..6eeb74613 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -74,7 +74,7 @@ MrTree::active_update(float elapsed_time) activate(); } - if (may_fall_off_platform()) + if (might_fall()) { dir = (dir == LEFT ? RIGHT : LEFT); activate(); diff --git a/src/badguy/totem.cpp b/src/badguy/totem.cpp index c61ab9aa5..9a6b23049 100644 --- a/src/badguy/totem.cpp +++ b/src/badguy/totem.cpp @@ -75,7 +75,7 @@ Totem::active_update(float elapsed_time) BadGuy::active_update(elapsed_time); if (!carried_by) { - if (may_fall_off_platform()) + if (might_fall()) { dir = (dir == LEFT ? RIGHT : LEFT); activate(); -- 2.11.0