From 213203fbe3352e084c8875acfbf435a948824c08 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 10 Feb 2021 19:48:27 -0500 Subject: Removed out-of-bounds tile collision This allows running off screen for a map transition to happen without bumping into something that isn't there. --- src/transform_system.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/transform_system.cpp') diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 6ed6210..e5b0363 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp @@ -45,6 +45,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire const Map& map = game_.getMap(); bool blocked = false; + vec2i mapBounds = map.getMapSize() * map.getTileSize(); + vec2i oldColUL = sprite.loc + sprite.collisionOffset; vec2i oldColDR = oldColUL + sprite.collisionSize; vec2i newColUL = newLoc + sprite.collisionOffset; @@ -56,7 +58,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire vec2i newTileDR = newColDR / map.getTileSize(); if (dirHasDir(sprite.dir, Direction::right)) { - if (newTileDR.x() > oldTileDR.x()) { + if (newTileDR.x() > oldTileDR.x() && + newColDR.x() < mapBounds.w()) { for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { if (map.isBlocked(newTileDR.x(), y)) { result.horiz.blocked = true; @@ -88,7 +91,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (dirHasDir(sprite.dir, Direction::left)) { - if (newTileUL.x() < oldTileUL.x()) { + if (newTileUL.x() < oldTileUL.x() && + newColUL.x() >= 0) { for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { if (map.isBlocked(newTileUL.x(), y)) { result.horiz.blocked = true; @@ -120,7 +124,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (dirHasDir(sprite.dir, Direction::down)) { - if (newTileDR.y() > oldTileDR.y()) { + if (newTileDR.y() > oldTileDR.y() && + newColDR.y() < mapBounds.h()) { for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { if (map.isBlocked(x, newTileDR.y())) { result.vert.blocked = true; @@ -152,7 +157,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire } if (dirHasDir(sprite.dir, Direction::up)) { - if (newTileUL.y() < oldTileUL.y()) { + if (newTileUL.y() < oldTileUL.y() && + newColUL.y() >= 0) { for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { if (map.isBlocked(x, newTileUL.y())) { result.vert.blocked = true; -- cgit 1.4.1