diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/transform_system.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
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 | |||
45 | const Map& map = game_.getMap(); | 45 | const Map& map = game_.getMap(); |
46 | bool blocked = false; | 46 | bool blocked = false; |
47 | 47 | ||
48 | vec2i mapBounds = map.getMapSize() * map.getTileSize(); | ||
49 | |||
48 | vec2i oldColUL = sprite.loc + sprite.collisionOffset; | 50 | vec2i oldColUL = sprite.loc + sprite.collisionOffset; |
49 | vec2i oldColDR = oldColUL + sprite.collisionSize; | 51 | vec2i oldColDR = oldColUL + sprite.collisionSize; |
50 | vec2i newColUL = newLoc + sprite.collisionOffset; | 52 | vec2i newColUL = newLoc + sprite.collisionOffset; |
@@ -56,7 +58,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire | |||
56 | vec2i newTileDR = newColDR / map.getTileSize(); | 58 | vec2i newTileDR = newColDR / map.getTileSize(); |
57 | 59 | ||
58 | if (dirHasDir(sprite.dir, Direction::right)) { | 60 | if (dirHasDir(sprite.dir, Direction::right)) { |
59 | if (newTileDR.x() > oldTileDR.x()) { | 61 | if (newTileDR.x() > oldTileDR.x() && |
62 | newColDR.x() < mapBounds.w()) { | ||
60 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { | 63 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { |
61 | if (map.isBlocked(newTileDR.x(), y)) { | 64 | if (map.isBlocked(newTileDR.x(), y)) { |
62 | result.horiz.blocked = true; | 65 | result.horiz.blocked = true; |
@@ -88,7 +91,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire | |||
88 | } | 91 | } |
89 | 92 | ||
90 | if (dirHasDir(sprite.dir, Direction::left)) { | 93 | if (dirHasDir(sprite.dir, Direction::left)) { |
91 | if (newTileUL.x() < oldTileUL.x()) { | 94 | if (newTileUL.x() < oldTileUL.x() && |
95 | newColUL.x() >= 0) { | ||
92 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { | 96 | for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { |
93 | if (map.isBlocked(newTileUL.x(), y)) { | 97 | if (map.isBlocked(newTileUL.x(), y)) { |
94 | result.horiz.blocked = true; | 98 | result.horiz.blocked = true; |
@@ -120,7 +124,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire | |||
120 | } | 124 | } |
121 | 125 | ||
122 | if (dirHasDir(sprite.dir, Direction::down)) { | 126 | if (dirHasDir(sprite.dir, Direction::down)) { |
123 | if (newTileDR.y() > oldTileDR.y()) { | 127 | if (newTileDR.y() > oldTileDR.y() && |
128 | newColDR.y() < mapBounds.h()) { | ||
124 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { | 129 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { |
125 | if (map.isBlocked(x, newTileDR.y())) { | 130 | if (map.isBlocked(x, newTileDR.y())) { |
126 | result.vert.blocked = true; | 131 | result.vert.blocked = true; |
@@ -152,7 +157,8 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire | |||
152 | } | 157 | } |
153 | 158 | ||
154 | if (dirHasDir(sprite.dir, Direction::up)) { | 159 | if (dirHasDir(sprite.dir, Direction::up)) { |
155 | if (newTileUL.y() < oldTileUL.y()) { | 160 | if (newTileUL.y() < oldTileUL.y() && |
161 | newColUL.y() >= 0) { | ||
156 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { | 162 | for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { |
157 | if (map.isBlocked(x, newTileUL.y())) { | 163 | if (map.isBlocked(x, newTileUL.y())) { |
158 | result.vert.blocked = true; | 164 | result.vert.blocked = true; |