From b2ec410974c747fa7916eddc0b67fdea641bdd5f Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Mon, 26 Apr 2004 12:41:50 +0000 Subject: [PATCH] - added automatic walking on worldmap SVN-Revision: 739 --- src/worldmap.cpp | 29 +++++++++++++++++++++++++++++ src/worldmap.h | 5 +++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 415e8a4ad..331572726 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -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)) diff --git a/src/worldmap.h b/src/worldmap.h index 2bfe8068a..4c875c8bb 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -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 -- 2.11.0