- added automatic walking on worldmap
authorIngo Ruhnke <grumbel@gmx.de>
Mon, 26 Apr 2004 12:41:50 +0000 (12:41 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Mon, 26 Apr 2004 12:41:50 +0000 (12:41 +0000)
SVN-Revision: 739

src/worldmap.cpp
src/worldmap.h

index 415e8a4..3315727 100644 (file)
@@ -110,6 +110,7 @@ TileManager::TileManager()
               tile->south = true;
               tile->west  = true;
               tile->stop  = true;
+              tile->auto_walk = false;
   
               LispReader reader(lisp_cdr(element));
               reader.read_int("id",  &id);
@@ -118,6 +119,7 @@ TileManager::TileManager()
               reader.read_bool("west",  &tile->west);
               reader.read_bool("east",  &tile->east);
               reader.read_bool("stop",  &tile->stop);
+              reader.read_bool("auto-walk",  &tile->auto_walk);
               reader.read_string("image",  &filename);
 
               tile->sprite = new Surface(
@@ -265,6 +267,33 @@ Tux::update(float delta)
             }
           else
             {
+              if (worldmap->at(tile_pos)->auto_walk)
+                { // Turn to a new direction
+                  Tile* tile = worldmap->at(tile_pos);
+                  Direction dir = NONE;
+                  
+                  if (tile->north && back_direction != NORTH)
+                    dir = NORTH;
+                  else if (tile->south && back_direction != SOUTH)
+                    dir = SOUTH;
+                  else if (tile->east && back_direction != EAST)
+                    dir = EAST;
+                  else if (tile->west && back_direction != WEST)
+                    dir = WEST;
+
+                  if (dir != NONE)
+                    {
+                      direction = dir;
+                      back_direction = reverse_dir(direction);
+                    }
+                  else
+                    {
+                      // Should never be reached if tiledata is good
+                      stop();
+                      return;
+                    }
+                }
+
               // Walk automatically to the next tile
               Point next_tile;
               if (worldmap->path_ok(direction, tile_pos, &next_tile))
index 2bfe806..4c875c8 100644 (file)
@@ -63,8 +63,9 @@ public:
   /** Stop on this tile or walk over it? */
   bool stop;
 
-  /** direction in which to automatically turn when walked on such a tile */
-  Direction auto_walk;
+  /** When set automatically turn directions when walked over such a
+      tile (ie. walk smoothly a curve) */
+  bool auto_walk;
 };
 
 class TileManager