pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/colliders pingu_collider.cxx,1.2,1.3


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/colliders pingu_collider.cxx,1.2,1.3 pingu_collider.hxx,1.2,1.3
Date: 18 Mar 2003 17:03:04 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/colliders
In directory dark:/tmp/cvs-serv15321/colliders

Modified Files:
        pingu_collider.cxx pingu_collider.hxx 
Log Message:
applied collison patch from Gervase


Index: pingu_collider.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/colliders/pingu_collider.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pingu_collider.cxx  9 Mar 2003 20:41:30 -0000       1.2
+++ pingu_collider.cxx  18 Mar 2003 17:03:02 -0000      1.3
@@ -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<int>(new_pos.x) != static_cast<int>(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: pingu_collider.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/colliders/pingu_collider.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pingu_collider.hxx  9 Mar 2003 20:41:30 -0000       1.2
+++ pingu_collider.hxx  18 Mar 2003 17:03:02 -0000      1.3
@@ -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;
 };





reply via email to

[Prev in Thread] Current Thread [Next in Thread]