From 8c1b75e07ecb89a4bdd7554bcf58fd263e0f0c62 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sat, 20 Mar 2004 11:30:03 +0000 Subject: [PATCH] - added check to catch brocken worldmaps SVN-Revision: 274 --- src/worldmap.cpp | 106 ++++++++++++++++++++++++++++++++++++------------------- src/worldmap.h | 1 + 2 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 95cdbc9b3..c7bbc9bfe 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -233,6 +233,30 @@ WorldMap::get_input() input_direction = SOUTH; } +Point +WorldMap::get_next_tile(Point pos, Direction direction) +{ + // FIXME: Cleanup, seperate tux + switch(input_direction) + { + case WEST: + pos.x -= 1; + break; + case EAST: + pos.x += 1; + break; + case NORTH: + pos.y -= 1; + break; + case SOUTH: + pos.y += 1; + break; + case NONE: + break; + } + return pos; +} + void WorldMap::update() { @@ -248,57 +272,67 @@ WorldMap::update() std::cout << "Enter the current level: " << i->name << std::endl;; halt_music(); gameloop(const_cast((DATA_PREFIX "levels/default/" + i->name).c_str()), - 1, ST_GL_LOAD_LEVEL_FILE); + 1, ST_GL_LOAD_LEVEL_FILE); play_music(song, 1); break; } } - } else { if (!tux_moving) { - // FIXME: Cleanup, seperate tux - switch(input_direction) + Point next_tile = get_next_tile(tux_tile_pos, input_direction); + if (next_tile.x >= 0 && next_tile.x < width + && next_tile.y >= 0 && next_tile.y < height) { - case WEST: - if (at(tux_tile_pos)->west) - { - tux_tile_pos.x -= 1; - tux_moving = true; - tux_direction = input_direction; - } - break; - case EAST: - if (at(tux_tile_pos)->east) - { - tux_tile_pos.x += 1; - tux_moving = true; - tux_direction = input_direction; - } - break; - case NORTH: - if (at(tux_tile_pos)->north) - { - tux_tile_pos.y -= 1; - tux_moving = true; - tux_direction = input_direction; - } - break; - case SOUTH: - if (at(tux_tile_pos)->south) + // FIXME: Cleanup, seperate tux + switch(input_direction) { - tux_tile_pos.y += 1; - tux_moving = true; + case WEST: + if (at(tux_tile_pos)->west && at(next_tile)->east) + { + tux_tile_pos.x -= 1; + tux_moving = true; + tux_direction = input_direction; + } + break; + case EAST: + if (at(tux_tile_pos)->east && at(next_tile)->west) + { + tux_tile_pos.x += 1; + tux_moving = true; + tux_direction = input_direction; + } + break; + case NORTH: + if (at(tux_tile_pos)->north && at(next_tile)->south) + { + tux_tile_pos.y -= 1; + tux_moving = true; + tux_direction = input_direction; + } + break; + case SOUTH: + if (at(tux_tile_pos)->south && at(next_tile)->north) + { + tux_tile_pos.y += 1; + tux_moving = true; + tux_direction = input_direction; + } + break; + case NONE: + tux_moving = false; + tux_offset = 0; tux_direction = input_direction; + break; } - break; - case NONE: + } + else + { tux_moving = false; tux_offset = 0; - tux_direction = input_direction; - break; + tux_direction = NONE; } } else diff --git a/src/worldmap.h b/src/worldmap.h index d8317936c..ef5d419cb 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -110,6 +110,7 @@ private: bool enter_level; Tile* at(Point pos); + Point get_next_tile(Point pos, Direction direction); public: WorldMap(); ~WorldMap(); -- 2.11.0