pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,1.19,1.20 indexed_c


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,1.19,1.20 indexed_canvas.cxx,1.2,1.3 pingu_action.cxx,1.9,1.10 pingu_action.hxx,1.19,1.20 pingus.hxx,1.4,1.5 usb_mouse_controller.cxx,1.2,1.3
Date: 20 Oct 2002 18:28:51 -0000

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

Modified Files:
        action_button.cxx indexed_canvas.cxx pingu_action.cxx 
        pingu_action.hxx pingus.hxx usb_mouse_controller.cxx 
Log Message:
applied several patches


Index: action_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_button.cxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- action_button.cxx   17 Oct 2002 00:10:46 -0000      1.19
+++ action_button.cxx   20 Oct 2002 18:28:48 -0000      1.20
@@ -249,7 +249,8 @@
       pressed = true;
     }
     
-  if(x); if(y);
+  UNUSED_ARG(x);
+  UNUSED_ARG(y);
 }
 
 ForwardButton::ForwardButton (TrueServer* s, int x, int y) 
@@ -297,7 +298,8 @@
 {
   server->set_fast_forward(!server->get_fast_forward());
   
-  if(x); if(y);
+  UNUSED_ARG(x);
+  UNUSED_ARG(y);
 }
 
 PauseButton::PauseButton (TrueServer* s, int x, int y) 

Index: indexed_canvas.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/indexed_canvas.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- indexed_canvas.cxx  16 Oct 2002 10:27:31 -0000      1.2
+++ indexed_canvas.cxx  20 Oct 2002 18:28:48 -0000      1.3
@@ -18,6 +18,7 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "indexed_canvas.hxx"
+#include <assert.h>
 
 IndexedCanvas::IndexedCanvas(int w, int h)
   : width(w),

Index: pingu_action.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_action.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- pingu_action.cxx    13 Oct 2002 16:39:58 -0000      1.9
+++ pingu_action.cxx    20 Oct 2002 18:28:49 -0000      1.10
@@ -18,7 +18,9 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <assert.h>
+#include <math.h>
 #include "col_map.hxx"
+#include "force_vector.hxx"
 #include "world.hxx"
 #include "pingu.hxx"
 #include "pingu_action.hxx"
@@ -75,6 +77,117 @@
     return true;
 
   return false;
+}
+
+void
+PinguAction::move_with_forces (float x_to_add, float y_to_add)
+{
+  Vector force_to_apply = pingu->get_velocity();
+
+  // Add any additional forces that are required
+  force_to_apply.x += x_to_add;
+  force_to_apply.y += y_to_add;
+
+  // Put the force together with any existing forces, including gravity
+  pingu->set_velocity( ForcesHolder::apply_forces(pingu->get_pos(),
+                                                 force_to_apply) );
+
+  Vector resultant_force = pingu->get_velocity();
+
+  // Strictly speaking x_numerator should be initialised with
+  // (resultant_force.y / 2) and y_numerator with (resultant_force.x / 2).
+  // This would make the algorithm essentially match the Mid-Point Line
+  // Algorithm.  However, zero should do and is more comprehendable.
+  int x_numerator = 0;
+  int y_numerator = 0;
+  int denominator = 0;
+  int x_inc = 0;
+  int y_inc = 0;
+
+  if (fabs(resultant_force.x) > fabs(resultant_force.y))
+    {
+      // Initialise so that we move in whole pixels in x direction and
+      // 'fractions' of a pixel in y direction.
+      denominator = static_cast<int>(fabs(resultant_force.x));
+      x_inc = denominator;
+      y_inc = static_cast<int>(fabs(resultant_force.y));
+    }
+  else
+    {
+      // Initialise so that we move in whole pixels in y direction and
+      // 'fractions' of a pixel in x direction.
+      denominator = static_cast<int>(fabs(resultant_force.y));
+      x_inc = static_cast<int>(fabs(resultant_force.x));
+      y_inc = denominator;
+    }
+
+  // Keep moving the Pingu until there is only a fraction left
+  while (resultant_force.x <= -1 || resultant_force.x >= 1
+         || resultant_force.y <= -1 || resultant_force.y >= 1)
+    {
+      x_numerator += x_inc;
+
+      // Is it now not a fraction?
+      if (x_numerator >= denominator)
+       {
+         // Revert back to being a fraction
+         x_numerator -= denominator;
+
+         // Move the Pingu depending on what the direction of the force is
+         if (resultant_force.x >= 1)
+           {
+             // Check what is to the right of the Pingu
+             if (rel_getpixel(pingu->direction, 0) != Groundtype::GP_NOTHING
+                   || head_collision_on_walk(pingu->direction, 0))
+               {
+                 break;
+               }
+
+             pingu->set_x(pingu->get_x() + 1);
+             resultant_force.x--;
+           }
+         else if (resultant_force.x <= -1)
+           {
+             // Check what is to the left of the Pingu
+             if (rel_getpixel(-(pingu->direction), 0) != Groundtype::GP_NOTHING
+                   || head_collision_on_walk(-(pingu->direction), 0) )
+               {
+                 break;
+               }
+
+             pingu->set_x(pingu->get_x() - 1);
+             resultant_force.x++;
+           }
+       }
+
+      y_numerator += y_inc;
+
+      // Is it now not a fraction?
+      if (y_numerator >= denominator)
+       {
+         // Revert back to being a fraction
+         y_numerator -= denominator;
+
+         // Move the Pingu depending on what the direction of the force is
+         if (resultant_force.y >= 1)
+           {
+             if (rel_getpixel(0, -1) != Groundtype::GP_NOTHING)
+               break;
+
+             pingu->set_y(pingu->get_y() + 1);
+             resultant_force.y--;
+           }
+         else if (resultant_force.y <= -1)
+           {
+             if (head_collision_on_walk(0, 1))
+               break;
+
+             pingu->set_y(pingu->get_y() - 1);
+             resultant_force.y++;
+           }
+       }
+    }
+
 }
 
 /* EOF */

Index: pingu_action.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_action.hxx,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- pingu_action.hxx    13 Oct 2002 16:39:58 -0000      1.19
+++ pingu_action.hxx    20 Oct 2002 18:28:49 -0000      1.20
@@ -103,6 +103,9 @@
   /// True if Pingu in specified position would bang its head if it were 
walking
   bool head_collision_on_walk (int x, int y);
 
+  void move_with_forces (float x_to_add, float y_to_add);
+
+  
   /** Called if the action was successfully applied via request_set_action */
   virtual void on_successfull_apply () { }
 

Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingus.hxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pingus.hxx  14 Oct 2002 11:15:15 -0000      1.4
+++ pingus.hxx  20 Oct 2002 18:28:49 -0000      1.5
@@ -37,6 +37,8 @@
    //sadly this does not actually work on 6.0, but it does in .NET
 
 #  pragma warning(disable:4355) //this used in constructor base
+
+#  pragma warning(disable:4800) //'int' : forcing value to bool 'true' or 
'false' (performance warning)
 #endif
 
 #define UNUSED_ARG(a) do {/* null */} while (&a == 0)

Index: usb_mouse_controller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/usb_mouse_controller.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- usb_mouse_controller.cxx    28 Sep 2002 11:52:22 -0000      1.2
+++ usb_mouse_controller.cxx    20 Oct 2002 18:28:49 -0000      1.3
@@ -17,6 +17,8 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#ifndef WIN32
+
 #include <ClanLib/Display/Display/display.h>
 #include "pingus_error.hxx"
 #include "usb_mouse_controller.hxx"
@@ -97,6 +99,8 @@
       else if (mouse.y > CL_Display::get_height () - 1) mouse.y = 
CL_Display::get_height () - 1;
     }
 }
+
+#endif //WIN32
 
 /* EOF */
 





reply via email to

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