summary refs log tree commit diff stats
path: root/src/transform_system.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/transform_system.cpp')
-rw-r--r--src/transform_system.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/transform_system.cpp b/src/transform_system.cpp index ee392f1..4056f46 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp
@@ -72,7 +72,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
72 enclosureZone = &map.getZone(sprite.enclosureZone); 72 enclosureZone = &map.getZone(sprite.enclosureZone);
73 } 73 }
74 74
75 if (dirHasDir(sprite.dir, Direction::right)) { 75 if (dirHasDir(dir, Direction::right)) {
76 if (newTileDR.x() > oldTileDR.x() && 76 if (newTileDR.x() > oldTileDR.x() &&
77 newColDR.x() < mapBounds.w()) { 77 newColDR.x() < mapBounds.w()) {
78 for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { 78 for (int y = newTileUL.y(); y <= newTileDR.y(); y++) {
@@ -113,7 +113,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
113 } 113 }
114 } 114 }
115 115
116 if (dirHasDir(sprite.dir, Direction::left)) { 116 if (dirHasDir(dir, Direction::left)) {
117 if (newTileUL.x() < oldTileUL.x() && 117 if (newTileUL.x() < oldTileUL.x() &&
118 newColUL.x() >= 0) { 118 newColUL.x() >= 0) {
119 for (int y = newTileUL.y(); y <= newTileDR.y(); y++) { 119 for (int y = newTileUL.y(); y <= newTileDR.y(); y++) {
@@ -154,7 +154,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
154 } 154 }
155 } 155 }
156 156
157 if (dirHasDir(sprite.dir, Direction::down)) { 157 if (dirHasDir(dir, Direction::down)) {
158 if (newTileDR.y() > oldTileDR.y() && 158 if (newTileDR.y() > oldTileDR.y() &&
159 newColDR.y() < mapBounds.h()) { 159 newColDR.y() < mapBounds.h()) {
160 for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { 160 for (int x = newTileUL.x(); x <= newTileDR.x(); x++) {
@@ -195,7 +195,7 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
195 } 195 }
196 } 196 }
197 197
198 if (dirHasDir(sprite.dir, Direction::up)) { 198 if (dirHasDir(dir, Direction::up)) {
199 if (newTileUL.y() < oldTileUL.y() && 199 if (newTileUL.y() < oldTileUL.y() &&
200 newColUL.y() >= 0) { 200 newColUL.y() >= 0) {
201 for (int x = newTileUL.x(); x <= newTileDR.x(); x++) { 201 for (int x = newTileUL.x(); x <= newTileDR.x(); x++) {
@@ -239,6 +239,29 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
239 return result; 239 return result;
240} 240}
241 241
242CharacterMedium TransformSystem::getMediumAtPosition(int spriteId, vec2i newLoc) {
243 Sprite& sprite = game_.getSprite(spriteId);
244
245 const Map& map = game_.getMap();
246
247 vec2i newColUL = newLoc + sprite.collisionOffset;
248 vec2i newColDR = newColUL + sprite.collisionSize;
249 vec2i newTileUL = newColUL / map.getTileSize();
250 vec2i newTileDR = newColDR / map.getTileSize();
251
252 CharacterMedium result = CharacterMedium::Normal;
253 for (int y=newTileUL.y(); y<=newTileDR.y(); y++) {
254 for (int x=newTileUL.x(); x<=newTileDR.x(); x++) {
255 CharacterMedium tileMedium = map.getMedium(x, y);
256 if (tileMedium > result) {
257 result = tileMedium;
258 }
259 }
260 }
261
262 return result;
263}
264
242void TransformSystem::addCollidable(int spriteId) { 265void TransformSystem::addCollidable(int spriteId) {
243 Sprite& sprite = game_.getSprite(spriteId); 266 Sprite& sprite = game_.getSprite(spriteId);
244 267