Index: ./Games/Pingus/src/actions/faller.cxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/faller.cxx,v retrieving revision 1.37 diff -u -r1.37 faller.cxx --- ./Games/Pingus/src/actions/faller.cxx 9 Mar 2003 20:41:30 -0000 1.37 +++ ./Games/Pingus/src/actions/faller.cxx 18 Mar 2003 02:06:50 -0000 @@ -76,7 +76,7 @@ do { // Move the Pingu as far is it can go - mover.update(move, Colliders::PinguCollider(velocity, pingu_height)); + mover.update(move, Colliders::PinguCollider(pingu_height)); pingu->set_pos(mover.get_pos()); Index: ./Games/Pingus/src/actions/bomber.cxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/bomber.cxx,v retrieving revision 1.31 diff -u -r1.31 bomber.cxx --- ./Games/Pingus/src/actions/bomber.cxx 9 Mar 2003 20:41:30 -0000 1.31 +++ ./Games/Pingus/src/actions/bomber.cxx 18 Mar 2003 02:06:51 -0000 @@ -87,7 +87,7 @@ Vector velocity = pingu->get_velocity(); // Move the Pingu - mover.update(velocity, Colliders::PinguCollider(velocity, pingu_height)); + mover.update(velocity, Colliders::PinguCollider(pingu_height)); pingu->set_pos(mover.get_pos()); Index: ./Games/Pingus/src/collider.cxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/collider.cxx,v retrieving revision 1.2 diff -u -r1.2 collider.cxx --- ./Games/Pingus/src/collider.cxx 9 Mar 2003 20:41:30 -0000 1.2 +++ ./Games/Pingus/src/collider.cxx 18 Mar 2003 02:06:51 -0000 @@ -30,10 +30,13 @@ { } -bool Collider::operator() (World* const world, Vector pos) const +bool Collider::operator() (World* const world, Vector current_pos, + const Vector& step_vector) const { UNUSED_ARG(world); - UNUSED_ARG(pos); + UNUSED_ARG(current_pos); + UNUSED_ARG(step_vector); + return false; } Index: ./Games/Pingus/src/collider.hxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/collider.hxx,v retrieving revision 1.2 diff -u -r1.2 collider.hxx --- ./Games/Pingus/src/collider.hxx 9 Mar 2003 20:41:30 -0000 1.2 +++ ./Games/Pingus/src/collider.hxx 18 Mar 2003 02:06:52 -0000 @@ -32,9 +32,9 @@ /** Destructor for abstract class */ virtual ~Collider() = 0; - /** Find out if a Pingu at the specified position is colliding with - something */ - virtual bool operator() (World* const world, Vector pos) const = 0; + /** Find out if object will collide with something */ + virtual bool operator() (World* const world, Vector current_pos, + const Vector& step_vector) const = 0; protected: /** Get the Collision Map pixel at the specified position in the specified Index: ./Games/Pingus/src/colliders/pingu_collider.cxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/colliders/pingu_collider.cxx,v retrieving revision 1.2 diff -u -r1.2 pingu_collider.cxx --- ./Games/Pingus/src/colliders/pingu_collider.cxx 9 Mar 2003 20:41:30 -0000 1.2 +++ ./Games/Pingus/src/colliders/pingu_collider.cxx 18 Mar 2003 02:06:52 -0000 @@ -24,9 +24,7 @@ namespace Colliders { -PinguCollider::PinguCollider(const Vector& direction, const int height_arg) - : falling(direction.y > 0.0f), - height(height_arg) +PinguCollider::PinguCollider(const int height_arg) : height(height_arg) { } @@ -34,25 +32,52 @@ { } -bool PinguCollider::operator() (World* const world, Vector pos) const +bool PinguCollider::operator() (World* const world, Vector current_pos, + const Vector& step_vector) const { + Vector new_pos = current_pos + step_vector; int pixel; + bool falling = false; bool collided = false; - float top_of_pingu = pos.y - height; - for (; pos.y >= top_of_pingu; --pos.y) + 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)) { - pixel = getpixel(world, pos); + float top_of_pingu = new_pos.y - height; - // 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) + for (; new_pos.y >= top_of_pingu; --new_pos.y) + { + pixel = getpixel(world, new_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) + { + collided = true; + break; + } + } + } + // If the Pingu is not falling... + else if (!falling) + { + pixel = getpixel(world, Vector(new_pos.x, new_pos.y - height)); + + // If the top of the Pingu has hit something except a bridge... + if (pixel != Groundtype::GP_NOTHING && pixel != Groundtype::GP_BRIDGE) { collided = true; - break; } + } + // If the Pingu's "feet" has hit something... + else if (getpixel(world, new_pos) != Groundtype::GP_NOTHING) + { + collided = true; } return collided; Index: ./Games/Pingus/src/colliders/pingu_collider.hxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/colliders/pingu_collider.hxx,v retrieving revision 1.2 diff -u -r1.2 pingu_collider.hxx --- ./Games/Pingus/src/colliders/pingu_collider.hxx 9 Mar 2003 20:41:30 -0000 1.2 +++ ./Games/Pingus/src/colliders/pingu_collider.hxx 18 Mar 2003 02:06:52 -0000 @@ -28,20 +28,18 @@ { public: /** Constructor */ - PinguCollider(const Vector& direction, const int height_arg); + PinguCollider(const int height_arg); /** Destructor */ ~PinguCollider(); /** Find out if a Pingu at the specified position is colliding with something */ - bool operator() (World* const world, Vector pos) const; + bool operator() (World* const world, Vector current_pos, + const Vector& step_vector) const; private: - /** Indicates whether a Pingu is falling or not */ - bool falling; - - /** Pingu could by on its belly. Therefore, this is the current height of + /** Pingu could be on its belly. Therefore, this is the current height of the Pingu. */ int height; }; Index: ./Games/Pingus/src/movers/linear_mover.cxx =================================================================== RCS file: /usr/local/cvsroot/Games/Pingus/src/movers/linear_mover.cxx,v retrieving revision 1.1 diff -u -r1.1 linear_mover.cxx --- ./Games/Pingus/src/movers/linear_mover.cxx 12 Feb 2003 22:43:38 -0000 1.1 +++ ./Games/Pingus/src/movers/linear_mover.cxx 18 Mar 2003 02:06:53 -0000 @@ -31,23 +31,25 @@ { } -void LinearMover::update(const Vector& move, const Collider& collision_at) +void LinearMover::update(const Vector& move, const Collider& collision_check) { - float move_length = move.length(); Vector target_pos = pos + move; Vector step_vector = move; + // Static cast to stop warning + int move_length = static_cast(move.length()); + // Make the step vector (i.e. change to a unit vector) step_vector.normalize(); collision = false; // Move to the destination one unit vector at a time - for (float i = 0; i < move_length && !collision; ++i) + for (int i = 0; i < move_length && !collision; ++i) { - pos += step_vector; + collision = collision_check(world, pos, step_vector); - collision = collision_at(world, pos); + pos += step_vector; } // If on a collision pixel, back away from it.