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.16,1.17 bridger


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/actions bridger.cxx,1.16,1.17 bridger.hxx,1.11,1.12
Date: 24 Sep 2002 17:03:31 -0000

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

Modified Files:
        bridger.cxx bridger.hxx 
Log Message:
Gervase's bridger patch

Index: bridger.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/bridger.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- bridger.cxx 16 Sep 2002 20:31:09 -0000      1.16
+++ bridger.cxx 24 Sep 2002 17:03:28 -0000      1.17
@@ -32,6 +32,9 @@
 
 namespace Actions {
 
+// Initialise class static
+const int Bridger::brick_length = 16;
+
 bool Bridger::static_surfaces_loaded = false;
 CL_Surface Bridger::brick_l;
 CL_Surface Bridger::brick_r;
@@ -61,8 +64,6 @@
                        "pingus", 15.0f, Sprite::NONE, Sprite::ONCE);
   build_sprite.set_align_center_bottom ();
   walk_sprite.set_align_center_bottom ();
-
-  last_pos = pingu->get_pos();
 }
 
 void
@@ -118,8 +119,6 @@
       update_walk (delta);
       break;
     }
-
-  last_pos = pingu->get_pos();
 }
 
 void
@@ -138,7 +137,6 @@
        {
          pingu->direction.change ();
          pingu->set_action (Actions::Walker);
-         pingu->set_pos(last_pos);
          return;
        }
     }
@@ -159,7 +157,14 @@
 
       if (bricks > 0)
        {
-         place_a_brick();
+         if (brick_placement_allowed())
+           place_a_brick();
+         else
+           {
+             pingu->direction.change ();
+             pingu->set_action (Actions::Walker);
+             return;
+           }
        }
       else // Out of bricks
        {
@@ -177,9 +182,27 @@
 bool
 Bridger::way_is_free()
 {
-  return (rel_getpixel(4,2) ==  Groundtype::GP_NOTHING)
-    && !head_collision_on_walk(4, 2)
-    && !head_collision_on_walk(8, 4);
+  return (rel_getpixel(4,2) ==  Groundtype::GP_NOTHING);
+}
+
+bool
+Bridger::brick_placement_allowed(void)
+{
+  bool brick_allowed = true;
+
+  // Don't allow a brick to be placed if a Pingu would have a head collision
+  // if it walked along the whole of the brick.  Otherwise the Pingu,
+  // especially a walker, could get stuck between the brick and the ceiling.
+  for (int x_inc = 1; x_inc <= brick_length; ++x_inc)
+    {
+      if (head_collision_on_walk(x_inc, 2))
+       {
+         brick_allowed = false;
+         break;
+       }
+    }
+
+  return brick_allowed;
 }
 
 void

Index: bridger.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/actions/bridger.hxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- bridger.hxx 10 Sep 2002 19:24:19 -0000      1.11
+++ bridger.hxx 24 Sep 2002 17:03:28 -0000      1.12
@@ -39,6 +39,8 @@
 
   GameCounter counter;
 
+  static const int brick_length;
+
   static bool static_surfaces_loaded;
   static CL_Surface static_surface;
   static CL_Surface brick_l;
@@ -49,8 +51,6 @@
   //int do_steps;
   bool block_build;
 
-  CL_Vector last_pos;
-
   std::string name;
 public:
   Bridger();
@@ -66,6 +66,7 @@
   void   draw (GraphicContext& gc);
     
   bool   way_is_free ();
+  bool   brick_placement_allowed (void);
   void   place_a_brick ();
   void   walk_one_step_up ();
   





reply via email to

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