[Super-tux-commit] supertux/src worldmap.cpp,1.68.2.10,1.68.2.11 worldmap.h,1.28.2.8,1.28.2.9
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-07-30 22:34:41
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9844/src Modified Files: Tag: supertux_0_1_1_branch worldmap.cpp worldmap.h Log Message: Added support for one way roads, as requested by Marek. Possible of usage: (one-way "north-south"), (one-way "south-north"), (one-way "east-west") or (one-way "west-east"). Use only one. And none for both ways. Worldmap stuff is getting too many expections, which is not bad, but is getting bloated. After the release of 0.1.2, I will port all these new aditions, but in a way to avoid both worldmap dta and source code getting bloated. The use of strings in worldmap data (like in this case), and arrays of booleans or peraphs bitfields in the code sound like a good choice. Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.68.2.10 retrieving revision 1.68.2.11 diff -u -d -r1.68.2.10 -r1.68.2.11 --- worldmap.cpp 30 Jul 2004 10:54:53 -0000 1.68.2.10 +++ worldmap.cpp 30 Jul 2004 22:34:30 -0000 1.68.2.11 @@ -125,6 +125,21 @@ reader.read_bool("auto-walk", &tile->auto_walk); reader.read_string("image", &filename); + std::string temp; + reader.read_string("one-way", &temp); + tile->one_way = BOTH_WAYS; + if(!temp.empty()) + { + if(temp == "north-south") + tile->one_way = NORTH_SOUTH_WAY; + else if(temp == "south-north") + tile->one_way = SOUTH_NORTH_WAY; + else if(temp == "east-west") + tile->one_way = EAST_WEST_WAY; + else if(temp == "west-east") + tile->one_way = WEST_EAST_WAY; + } + tile->sprite = new Surface( datadir + "/images/worldmap/" + filename, USE_ALPHA); @@ -265,7 +280,6 @@ } else if (input_direction == back_direction) { - std::cout << "Back triggered" << std::endl; moving = true; direction = input_direction; tile_pos = worldmap->get_next_tile(tile_pos, direction); @@ -296,7 +310,12 @@ } } - if (worldmap->at(tile_pos)->stop || (level && !level->name.empty())) + Tile* cur_tile = worldmap->at(tile_pos); + if (cur_tile->stop || (level && !level->name.empty()) || + (cur_tile->one_way == NORTH_SOUTH_WAY && direction != D_SOUTH) || + (cur_tile->one_way == SOUTH_NORTH_WAY && direction != D_NORTH) || + (cur_tile->one_way == EAST_WEST_WAY && direction != D_WEST) || + (cur_tile->one_way == WEST_EAST_WAY && direction != D_EAST)) { stop(); } @@ -642,6 +661,15 @@ { // New position is outsite the tilemap return false; } + else if(at(*new_pos)->one_way != BOTH_WAYS) + { + if((at(*new_pos)->one_way == NORTH_SOUTH_WAY && direction != D_SOUTH) || + (at(*new_pos)->one_way == SOUTH_NORTH_WAY && direction != D_NORTH) || + (at(*new_pos)->one_way == EAST_WEST_WAY && direction != D_WEST) || + (at(*new_pos)->one_way == WEST_EAST_WAY && direction != D_EAST)) + return false; + return true; + } else { // Check if we the tile allows us to go to new_pos switch(direction) Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.28.2.8 retrieving revision 1.28.2.9 diff -u -d -r1.28.2.8 -r1.28.2.9 --- worldmap.h 30 Jul 2004 10:54:53 -0000 1.28.2.8 +++ worldmap.h 30 Jul 2004 22:34:31 -0000 1.28.2.9 @@ -46,6 +46,15 @@ int y; }; +// For one way tiles +enum { + BOTH_WAYS, + NORTH_SOUTH_WAY, + SOUTH_NORTH_WAY, + EAST_WEST_WAY, + WEST_EAST_WAY + }; + class Tile { public: @@ -60,6 +69,9 @@ bool south; bool west; + /** One way tile */ + int one_way; + /** Stop on this tile or walk over it? */ bool stop; |