pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/actions bomber.cxx,1.30,1.31 digger.c


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/actions bomber.cxx,1.30,1.31 digger.cxx,1.22,1.23 faller.cxx,1.36,1.37
Date: 9 Mar 2003 20:41:32 -0000

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

Modified Files:
        bomber.cxx digger.cxx faller.cxx 
Log Message:
Applied action patches from Gervase


Index: bomber.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/bomber.cxx,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- bomber.cxx  3 Mar 2003 20:32:18 -0000       1.30
+++ bomber.cxx  9 Mar 2003 20:41:30 -0000       1.31
@@ -24,6 +24,7 @@
 #include "../col_map.hxx"
 #include "../gui/graphic_context.hxx"
 #include "../pingu.hxx"
+#include "../pingu_enums.hxx"
 #include "../pingu_map.hxx"
 #include "../pingus_resource.hxx"
 #include "../string_converter.hxx"
@@ -85,13 +86,8 @@
 
   Vector velocity = pingu->get_velocity();
 
-  // Move the Pingu with different colliders depending on whether the Pingu is
-  // moving down (i.e. can't go through Bridges) or moving up (i.e. can go
-  // through Bridges)
-  if (velocity.y > 0.0f)
-    mover.update(velocity, Colliders::PinguCollider(true, pingu_height));
-  else
-    mover.update(velocity, Colliders::PinguCollider(false, pingu_height));
+  // Move the Pingu
+  mover.update(velocity, Colliders::PinguCollider(velocity, pingu_height));
 
   pingu->set_pos(mover.get_pos());
 
@@ -105,7 +101,7 @@
 
   // If the Bomber hasn't 'exploded' yet and it has hit the ground too quickly
   if (sprite.get_frame () <= 9 && rel_getpixel(0, -1) != Groundtype::GP_NOTHING
-      && velocity.y > 20.0f)
+      && velocity.y > deadly_velocity)
     {
       pingu->set_action(Actions::Splashed);
       return;

Index: digger.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/digger.cxx,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- digger.cxx  4 Mar 2003 13:59:44 -0000       1.22
+++ digger.cxx  9 Mar 2003 20:41:30 -0000       1.23
@@ -55,7 +55,14 @@
 Digger::update ()
 {
   sprite.update ();
-  
+
+  if (rel_getpixel(0, -1) ==  Groundtype::GP_WATER
+      || rel_getpixel(0, -1) ==  Groundtype::GP_LAVA)
+    {
+      pingu->set_action(Actions::Drown);
+      return;
+    }
+
   if (++digger_c >= 5)
     {
       digger_c = 0;

Index: faller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/faller.cxx,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- faller.cxx  19 Feb 2003 09:50:36 -0000      1.36
+++ faller.cxx  9 Mar 2003 20:41:30 -0000       1.37
@@ -19,11 +19,14 @@
 
 #include <math.h>
 #include "../col_map.hxx"
+#include "../colliders/pingu_collider.hxx"
 #include "../debug.hxx"
 #include "../globals.hxx"
 #include "../gui/graphic_context.hxx"
+#include "../movers/linear_mover.hxx"
 #include "../pingu.hxx"
 #include "../string_converter.hxx"
+#include "../worldobj.hxx"
 #include "faller.hxx"
 
 namespace Actions {
@@ -60,34 +63,82 @@
   if (pingu->get_velocity().y > 5.0 && pingu->request_fall_action())
     return;
 
-  // Move the Faller according to the forces that currently exist, which
-  // includes gravity.
-  move_with_forces ();
+  // Apply gravity
+  pingu->set_velocity(pingu->get_velocity() + Vector(0.0f, 1.0f));
 
-  // Now that the Pingu is moved, check if he hits the ground.
-  // FIXME: shouldn't this be done by move_with_forces
-  if (rel_getpixel(0, -1) != Groundtype::GP_NOTHING)
-    { // Ping is on ground/water/something
-      if (   rel_getpixel(0, -1) == Groundtype::GP_WATER
-         || rel_getpixel(0, -1) == Groundtype::GP_LAVA)
-       {
-         pingu->set_action(Actions::Drown);
-         return;
-       }
-      else
+  bool collided;
+
+  Vector velocity = pingu->get_velocity();
+  Vector move = velocity;
+
+  Movers::LinearMover mover(WorldObj::get_world(), pingu->get_pos());
+
+  do
+    {
+      // Move the Pingu as far is it can go
+      mover.update(move, Colliders::PinguCollider(velocity, pingu_height));
+
+      pingu->set_pos(mover.get_pos());
+
+      collided = mover.collided();
+
+      // If the Pingu collided with something...
+      if (collided)
        {
-         // Did we stop too fast?
-         if (fabs(pingu->get_velocity().y) > deadly_velocity) 
+         move = mover.remaining();
+
+         // If the Pingu collided into something while moving down...
+         if (velocity.y > 0.0f
+             && rel_getpixel(0, -1) != Groundtype::GP_NOTHING)
            {
-             pingu->set_action(Actions::Splashed);
-             return;
+             // Ping is on ground/water/something
+             if (   rel_getpixel(0, -1) == Groundtype::GP_WATER
+                 || rel_getpixel(0, -1) == Groundtype::GP_LAVA)
+               {
+                 pingu->set_action(Actions::Drown);
+               }
+             // Did we stop too fast?
+             else if (fabs(pingu->get_velocity().y) > deadly_velocity) 
+               {
+                 pingu->set_action(Actions::Splashed);
+               }
+             else if (fabs(pingu->get_velocity().x) > deadly_velocity)
+               {
+                 pout(PINGUS_DEBUG_ACTIONS) << "Pingu: x Smashed on ground, 
jumping" << std::endl;
+               }
+
+             break;
            }
-         else if (fabs(pingu->get_velocity().x) > deadly_velocity)
+         // If the Pingu collided into something while moving up...
+         // NB: +1 because Mover backs out of something it has collided with.
+         else if (velocity.y < 0.0f
+                   && rel_getpixel(0, pingu_height + 1) != 
Groundtype::GP_NOTHING)
            {
-             pout(PINGUS_DEBUG_ACTIONS) << "Pingu: x Smashed on ground, 
jumping" << std::endl;
+             // Don't make the Pingu go up any further.
+             move.y = 0.0f;
+             velocity.y = 0.0f;
+           }
+         else
+           {
+             // Make Pingu bounce off wall
+             move.x = -(move.x / 3.0f);
+             velocity.x = -(velocity.x / 3.0f);
+
+             // Make the Pingu face the correct direction.  NB: Pingu may
+             // previously have been facing in the opposite direction of its
+             // velocity because of an explosion.
+             if (velocity.x > 0.0f)
+               pingu->direction.right();
+             else
+               pingu->direction.left();
            }
        }
+
+      // Update the Pingu's velocity
+      pingu->set_velocity(velocity);
     }
+  // Loop if the Pingu still needs to be moved
+  while (collided);
 }
 
 void 





reply via email to

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