From: Florian Forster Date: Thu, 11 Mar 2010 09:33:59 +0000 (+0000) Subject: supertux/sector.cpp: Add support for "south", "west" and "east" unisolid tiles. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2ce399800763c136c022a20d30910293ab7e407a;p=supertux.git supertux/sector.cpp: Add support for "south", "west" and "east" unisolid tiles. I.e. "south" meaning "can go down, not up", and "west" and "east" for left and right as appropriate. SVN-Revision: 6595 --- diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index b60a70ea9..f85ef49f8 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -973,9 +973,19 @@ int check_movement_unisolid (Vector movement, const Tile* tile) /* If the tile is not a slope, this is very easy. */ if (!tile->is_slope ()) { - if (movement.y >= 0) /* moving down */ + int dir = tile->getData () & ((int) Tile::UNI_DIR_MASK); + + log_debug << "Tile data is " << tile->getData () << ", dir = " << dir << std::endl; + + if (dir != Tile::UNI_DIR_NORTH) + log_debug << "Found non-north facing unisolid tile." << std::endl; + + if (((dir == Tile::UNI_DIR_NORTH) && (movement.y >= 0)) /* moving down */ + || ((dir == Tile::UNI_DIR_SOUTH) && (movement.y < 0)) /* moving up */ + || ((dir == Tile::UNI_DIR_WEST) && (movement.x >= 0)) /* moving right */ + || ((dir == Tile::UNI_DIR_EAST) && (movement.x < 0))) /* moving left */ return MV_SOLID; - else /* moving up */ + else return MV_NON_SOLID; } @@ -1101,10 +1111,22 @@ int check_position_unisolid (const Rectf& obj_bbox, /* If this is not a slope, this is - again - easy */ if (!tile->is_slope ()) { - if ((obj_bbox.get_bottom () - SHIFT_DELTA) <= tile_bbox.get_top ()) + int dir = tile->getData () & Tile::UNI_DIR_MASK; + + if ((dir == Tile::UNI_DIR_NORTH) + && ((obj_bbox.get_bottom () - SHIFT_DELTA) <= tile_bbox.get_top ())) return POS_SOLID; - else - return POS_NON_SOLID; + else if ((dir == Tile::UNI_DIR_SOUTH) + && ((obj_bbox.get_top () + SHIFT_DELTA) >= tile_bbox.get_bottom ())) + return POS_SOLID; + else if ((dir == Tile::UNI_DIR_WEST) + && ((obj_bbox.get_right () - SHIFT_DELTA) <= tile_bbox.get_left ())) + return POS_SOLID; + else if ((dir == Tile::UNI_DIR_EAST) + && ((obj_bbox.get_left () + SHIFT_DELTA) >= tile_bbox.get_right ())) + return POS_SOLID; + + return POS_NON_SOLID; } /* There are 20 different cases. For each case, calculate a line that diff --git a/src/supertux/tile.hpp b/src/supertux/tile.hpp index 465c55995..805d85be2 100644 --- a/src/supertux/tile.hpp +++ b/src/supertux/tile.hpp @@ -91,6 +91,15 @@ public: Rectf rect; }; + enum + { + UNI_DIR_NORTH = 0, + UNI_DIR_SOUTH = 1, + UNI_DIR_WEST = 2, + UNI_DIR_EAST = 3, + UNI_DIR_MASK = 3 + }; + private: std::vector imagespecs; std::vector images;