From 0736ba27c97e4a678973ac0aa82b0ad0d685db7e Mon Sep 17 00:00:00 2001 From: Eric Robinson <68359262+kphoenix137@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:41:17 -0400 Subject: [PATCH] Fix Sideways Walk Draw Order (#7056) --- Source/engine/render/scrollrt.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 62ecac9e3..4a6db674f 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -736,10 +736,10 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit } Player *player = PlayerAtPosition(tilePosition); if (player != nullptr) { - // If sprite is moving southwards, we want to draw it offset from the tile it's moving to, so we need negative ID - int8_t playerId = static_cast(player->getId() + 1); - - if (player->_pmode == PM_WALK_SOUTHWARDS) + auto playerId = static_cast(player->getId() + 1); + // If sprite is moving southwards or east, we want to draw it offset from the tile it's moving to, so we need negative ID + // This respests the order that tiles are drawn. By using the negative id, we ensure that the sprite is drawn with priority + if (player->_pmode == PM_WALK_SOUTHWARDS || (player->_pmode == PM_WALK_SIDEWAYS && player->_pdir == Direction::East)) playerId = -playerId; if (dPlayer[tilePosition.x][tilePosition.y] == playerId) { auto tempTilePosition = tilePosition; @@ -759,17 +759,20 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit break; } tempTilePosition += Opposite(player->_pdir); + } else if (player->_pmode == PM_WALK_SIDEWAYS && player->_pdir == Direction::East) { + tempTargetBufferPosition += { -TILE_WIDTH, 0 }; + tempTilePosition += Opposite(player->_pdir); } - DrawPlayerHelper(out, *player, tempTilePosition, tempTargetBufferPosition); // BUGFIX: Player sprite gets cut off walking in front of certain corners in caves + DrawPlayerHelper(out, *player, tempTilePosition, tempTargetBufferPosition); } } Monster *monster = FindMonsterAtPosition(tilePosition); if (monster != nullptr) { - // If sprite is moving southwards, we want to draw it offset from the tile it's moving to, so we need negative ID - int8_t monsterId = static_cast(monster->getId() + 1); - - if (monster->mode == MonsterMode::MoveSouthwards) + auto monsterId = static_cast(monster->getId() + 1); + // If sprite is moving southwards or east, we want to draw it offset from the tile it's moving to, so we need negative ID + // This respests the order that tiles are drawn. By using the negative id, we ensure that the sprite is drawn with priority + if (monster->mode == MonsterMode::MoveSouthwards || (monster->mode == MonsterMode::MoveSideways && monster->direction == Direction::East)) monsterId = -monsterId; if (dMonster[tilePosition.x][tilePosition.y] == monsterId) { auto tempTilePosition = tilePosition; @@ -789,8 +792,11 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit break; } tempTilePosition += Opposite(monster->direction); + } else if (monster->mode == MonsterMode::MoveSideways && monster->direction == Direction::East) { + tempTargetBufferPosition += { -TILE_WIDTH, 0 }; + tempTilePosition += Opposite(monster->direction); } - DrawMonsterHelper(out, tempTilePosition, tempTargetBufferPosition); // BUGFIX: Monster sprite gets cut off walking in front of certain corners in caves + DrawMonsterHelper(out, tempTilePosition, tempTargetBufferPosition); } }