From 263dfcd56385cef3ac54c7c1d127307491f68f83 Mon Sep 17 00:00:00 2001 From: florianf Date: Thu, 11 Mar 2010 09:33:59 +0000 Subject: [PATCH] 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. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6595 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/supertux/sector.cpp | 32 +++++++++++++++++++++++++++----- src/supertux/tile.hpp | 9 +++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) 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; -- 2.11.0