Index: Games/Pingus/src/colliders/pingu_collider.cxx =================================================================== RCS file: /var/lib/cvs/Games/Pingus/src/colliders/pingu_collider.cxx,v retrieving revision 1.3 diff -b -u -r1.3 pingu_collider.cxx --- Games/Pingus/src/colliders/pingu_collider.cxx 18 Mar 2003 17:03:02 -0000 1.3 +++ Games/Pingus/src/colliders/pingu_collider.cxx 3 May 2003 13:05:36 -0000 @@ -17,6 +17,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include "../mover.hxx" #include "../pingu_action.hxx" #include "../groundtype.hxx" #include "../vector.hxx" @@ -32,55 +33,57 @@ { } -bool PinguCollider::operator() (World* const world, Vector current_pos, +void PinguCollider::operator() (Mover& mover, World* const world, + const Vector& current_pos, const Vector& step_vector) const { - Vector new_pos = current_pos + step_vector; - int pixel; bool falling = false; - bool collided = false; if (step_vector.y > 0.0f) falling = true; - // If the Pingu is going to move sideways to the next pixel... - if (static_cast(new_pos.x) != static_cast(current_pos.x)) + Vector check_pos = current_pos + step_vector; + float final_check_pos_y = check_pos.y - height; + + // If the Pingu is not moving sideways when going to the next pixel... + if (static_cast(check_pos.x) == static_cast(current_pos.x)) { - float top_of_pingu = new_pos.y - height; + // ...make loop only check the top or bottom pixel of the Pingu + if (falling) + final_check_pos_y = check_pos.y; + else + check_pos.y = final_check_pos_y; + } - for (; new_pos.y >= top_of_pingu; --new_pos.y) + int colmap_pixel; + int collision_pixel; + bool collided = false; + + for (; check_pos.y >= final_check_pos_y; --check_pos.y) { - pixel = getpixel(world, new_pos); + colmap_pixel = getpixel(world, check_pos); - // If there is something in the way, then Pingu has collided with - // something. However, if not falling and colliding with a - // Bridge, allow Pingu to go through it. - if ((!falling || pixel != Groundtype::GP_BRIDGE) - && pixel != Groundtype::GP_NOTHING) + // If there is something in the way except a Bridge, the make the Pingu + // collide with it. However, if the Pingu is falling, it should collide + // with the Bridge. + if ((falling || colmap_pixel != Groundtype::GP_BRIDGE) + && colmap_pixel != Groundtype::GP_NOTHING) { collided = true; - break; - } - } - } - // If the Pingu is not falling... - else if (!falling) - { - pixel = getpixel(world, Vector(new_pos.x, new_pos.y - height)); + collision_pixel = colmap_pixel; - // If the top of the Pingu has hit something except a bridge... - if (pixel != Groundtype::GP_NOTHING && pixel != Groundtype::GP_BRIDGE) + // If a deadly pixel is found... + if (colmap_pixel == Groundtype::GP_WATER + || colmap_pixel == Groundtype::GP_LAVA) { - collided = true; + // ...get out of the loop. + break; } } - // If the Pingu's "feet" has hit something... - else if (getpixel(world, new_pos) != Groundtype::GP_NOTHING) - { - collided = true; } - return collided; + // Pass back information to the mover. + mover(collided, collision_pixel); } } // namespace Colliders