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 bridger.cxx,1.2,1.3 bridger.h


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/actions bridger.cxx,1.2,1.3 bridger.hxx,1.2,1.3 walker.cxx,1.2,1.3
Date: 24 Jun 2002 09:41:01 -0000

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

Modified Files:
        bridger.cxx bridger.hxx walker.cxx 
Log Message:
- fixed a bug in the blitter code which caused some backgrounds to become 
completly transparent
- added background scaling support
- rewrote some parts of the walker code, should be less stucky now
- fixed the bridger so that it doesn't get stuck in walls and so that walkers 
can walk over a bridge which was stopped by a headbump

Index: bridger.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/bridger.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- bridger.cxx 19 Jun 2002 15:19:26 -0000      1.2
+++ bridger.cxx 24 Jun 2002 09:40:59 -0000      1.3
@@ -60,6 +60,8 @@
                        "pingus", 15.0f, Sprite::NONE, Sprite::ONCE);
   build_sprite.set_align_center_bottom ();
   walk_sprite.set_align_center_bottom ();
+
+  last_pos = pingu->pos;
 }
 
 void
@@ -102,6 +104,8 @@
       update_walk (delta);
       break;
     }
+
+  last_pos = pingu->pos;
 }
 
 void
@@ -118,8 +122,11 @@
         }
       else // We reached a wall...
         {
-           // Let Walker sort out change of direction
-          is_finished = true;
+           // Let Walker sort out change of direction (so that in case
+           // of a climber, we would start to climb instead of direction 
change)
+          pingu->set_action ("walker");
+          pingu->pos = last_pos;
+          return;
         }
     }
   else
@@ -157,29 +164,9 @@
 bool
 Bridger::way_is_free()
 {
-  bool ret_val;
-  
-  if (rel_getpixel(4,2) == ColMap::NOTHING)
-    {
-      ret_val = true;
-    }
-  else
-    {
-      //cout << "Touched a wall" << endl;
-      return false;
-    }
-
-  if (!head_collision_on_walk(4, 2))
-    {
-      ret_val = true;
-    }
-  else
-    {
-      //cout << "Ouch, my head" << endl;
-      return false;
-    }
-
-  return ret_val;
+  return (rel_getpixel(4,2) == ColMap::NOTHING)
+    && !head_collision_on_walk(4, 2)
+    && !head_collision_on_walk(8, 4);
 }
 
 void

Index: bridger.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/bridger.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- bridger.hxx 19 Jun 2002 15:19:26 -0000      1.2
+++ bridger.hxx 24 Jun 2002 09:40:59 -0000      1.3
@@ -20,6 +20,7 @@
 #ifndef BRIDGER_HH
 #define BRIDGER_HH
 
+#include <ClanLib/Core/Math/cl_vector.h>
 #include "../game_counter.hxx"
 #include "../pingu_action.hxx"
 #include "../sprite.hxx"
@@ -43,6 +44,8 @@
   //int step;
   //int do_steps;
   bool block_build;
+
+  CL_Vector last_pos;
 
   enum Mode { B_WALKING, B_BUILDING } mode;
 public:

Index: walker.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/walker.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- walker.cxx  23 Jun 2002 19:16:41 -0000      1.2
+++ walker.cxx  24 Jun 2002 09:40:59 -0000      1.3
@@ -27,7 +27,7 @@
 #include "../debug.hxx"
 #include "walker.hxx"
 
-const int Walker::max_steps=4;
+const int Walker::max_steps=5;
 
 void
 Walker::init(void)
@@ -39,42 +39,85 @@
 void
 Walker::update(float delta)
 {
-  int y_inc = 0;
+  // update the sprite
   walker.update (delta);
 
+  CL_Vector last_pos = pingu->pos;
+
+  /* How should this code work?
+     
+  1) Check that the Pingu stands still on ground, if not turn it into
+  a faller. The reason we do so, is that we catch situations where a
+  digger or a similar action removed the ground under the walker.
+  
+  2) If pingu is still on ground, we can preprare the next step
+
+  3) Check if up-hill or down-hill is required
+  
+
+  4)
+  
+  */
+
+  // FIXME: pingu environment needs to get reviewed
   pingu->environment = ENV_LAND;
 
-  if (rel_getpixel(1, 0) == ColMap::NOTHING) 
+  if (rel_getpixel(0, -1) == ColMap::NOTHING)
+    { 
+      // The Pingu stands no longer on ground, so its time to fall
+      pingu->set_action ("faller");
+      return;
+    }
+  /*  else if (rel_getpixel(1, 0) == ColMap::NOTHING)
     { // if infront is free
       pingu->pos.x += pingu->direction;
-    }
-  else if (rel_getpixel(1, 0)  & ColMap::BRIDGE)  // bridge
+    }*/
+  else if (rel_getpixel(1, 0) & ColMap::BRIDGE
+          && !head_collision_on_walk(1, 1))  // bridge
     {
+      // simple, stupid, but working bridge code
+      // FIXME: We don't check if we 'drift' into a solid ground block
       pingu->pos.x += pingu->direction;
-      pingu->pos.y -= 1;
+      pingu->pos.y -= 1; // pingus 'float' through bridges
     }
   else 
-    { // if infront is a pixel 
+    { 
+      // Non of the trivial moves worked, so we do up-hill or down-hill walking
+      // FIXME: currently the pingu takes multiple steps at once when
+      // FIXME: working uphill, this looks kind of ugly
+
+
+      // FIXME: rel_getpixel works on the current pos, so modifing pos
+      // FIXME: is evil, a backup copy might help
+
+      // if infront is a pixel 
       // Pingu is walking up the mountain 
-      if (pingu->rel_getpixel(1, max_steps + 1) == ColMap::NOTHING) 
-        { // we can continue walking up. search for the correct y_pos
-         for(y_inc=1; y_inc <= max_steps; y_inc++)
-            if (rel_getpixel(1, y_inc) == ColMap::NOTHING)
-               break; 
-         pingu->pos.y -= y_inc;
+      // we can continue walking up. search for the correct y_pos
+      int y_inc = 0;
+      bool found_next_step = false;
+      for(y_inc=-max_steps; y_inc <= max_steps; y_inc++) // up-hill
+       if (rel_getpixel(1, y_inc) == ColMap::NOTHING
+           && rel_getpixel(1, y_inc - 1) != ColMap::NOTHING)
+         {
+           found_next_step = true;
+           break;
+         }
+      
+      if (found_next_step)
+       {
          pingu->pos.x += pingu->direction;
+         pingu->pos.y -= y_inc; // pos.y has a reversed co-system to 
rel_getpixel()?
        }
       else
-       { // WALL
-         for (unsigned int i=0; i < pingu->persist.size(); ++i) 
+       {
+         if (rel_getpixel(1, 0) != ColMap::NOTHING)
            {
-             if (pingu->persist[i]->get_type() & (ActionType)WALL) 
+             // We reached a wall
+
+             // Check if there is a persistent action
+             for (unsigned int i=0; i < pingu->persist.size(); ++i) 
                {
-                 if (pingu->action && pingu->persist[i]->get_name() == 
pingu->action->get_name()) 
-                   {
-                     pout(PINGUS_DEBUG_ACTIONS) << "Pingu: Not using action, 
we already did." << std::endl;
-                   } 
-                 else 
+                 if (pingu->persist[i]->get_type() & (ActionType)WALL) 
                    {
                      pout(PINGUS_DEBUG_ACTIONS) << "Pingu: We are in front of 
a wall, setting persistant action" << std::endl;
                      // pingu->set_paction(pingu->persist[i]->get_name());
@@ -84,49 +127,54 @@
   
                      // Do we set  any other action here?
                      pingu->set_paction("climber");
+                     return;
                    }
-                 return;
                }
+             
+             // No persitent action found, so change the direction
+             pingu->direction.change();              
+           }
+         else
+           {
+             // We take the step, so that we are in the air
+             pingu->pos.x += pingu->direction;
+             // We reached a cliff
+             pingu->set_action ("faller");
+             return;
            }
-         pingu->direction.change();
        }
     }
-  
 
-  if (rel_getpixel(0, -1) == ColMap::NOTHING) // in front there is a step 
-    {
-      
-      for(y_inc=2; y_inc <= max_steps + 1; y_inc++) 
-       {
-         if (rel_getpixel(0, -y_inc) == ColMap::WATER) 
-          {
-            pingu->set_paction ("drown");
-            return;
-          } 
-         else if(rel_getpixel(0, -y_inc) != ColMap::NOTHING)
-          { // there is land
-            pingu->pos.y += y_inc - 1;
-           break;
-          }
-        }
-
-       if (rel_getpixel(0,-y_inc) == ColMap::NOTHING)
-        { // out of loop still not land. we should fall.
-          pingu->set_action("faller");
-          return;
-        }
-    }
 
   // This is moved here to fix the bug where pingu stuck turning both
   // sides indefinetely when a head collision occured. the fix needs the
   // above downhill walk being done before head collision check.
-  if (rel_getpixel(0, 26) != ColMap::NOTHING && !(rel_getpixel(0, 26) == 
ColMap::BRIDGE))
+  if (head_collision_on_walk(0, 0))
     {
       pout(PINGUS_DEBUG_ACTIONS) << "Pingu: Head collision" << std::endl;
+
+      //if the new position causes a head collision, we are already
+      //stuck in a wall, so lets go back to the old position
       pingu->direction.change();
+      pingu->pos = last_pos;
       return;
     }
-
+      
+  /*
+    for(int y_inc=1; y_inc <= max_steps; ++y_inc) 
+    {
+    if (rel_getpixel(1, -y_inc) == ColMap::WATER) 
+    {
+    pingu->set_paction ("drown");
+    return;
+    } 
+    else if(rel_getpixel(1, -y_inc) != ColMap::NOTHING)
+    { // there is land
+    pingu->pos.y += y_inc - 1;
+    break;
+    }
+    }
+  */
 }
 
 void  




reply via email to

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