summary refs log tree commit diff stats
path: root/src/transform_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-20 13:19:15 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-20 13:19:15 -0500
commitca4935cb65325edbd45d4a3aacc921ea9ed9483b (patch)
tree28376ffac0f817fc3f1f7290745e91d603fd59e8 /src/transform_system.cpp
parent996076cf151a27a7a8d278aa4d15b28cfb196c46 (diff)
downloadtanetane-ca4935cb65325edbd45d4a3aacc921ea9ed9483b.tar.gz
tanetane-ca4935cb65325edbd45d4a3aacc921ea9ed9483b.tar.bz2
tanetane-ca4935cb65325edbd45d4a3aacc921ea9ed9483b.zip
Added enclosure zones
A sprite with an enclosure zone will collide with it if it attempts to leave the area defined by the zone. This is used to make sure that wandering sprites don't end up in weird places.
Diffstat (limited to 'src/transform_system.cpp')
-rw-r--r--src/transform_system.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/transform_system.cpp b/src/transform_system.cpp index 1d4a9f3..b5e9b7c 100644 --- a/src/transform_system.cpp +++ b/src/transform_system.cpp
@@ -67,6 +67,11 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
67 vec2i oldTileDR = oldColDR / map.getTileSize(); 67 vec2i oldTileDR = oldColDR / map.getTileSize();
68 vec2i newTileDR = newColDR / map.getTileSize(); 68 vec2i newTileDR = newColDR / map.getTileSize();
69 69
70 const Zone* enclosureZone = nullptr;
71 if (!sprite.enclosureZone.empty()) {
72 enclosureZone = &map.getZone(sprite.enclosureZone);
73 }
74
70 if (dirHasDir(sprite.dir, Direction::right)) { 75 if (dirHasDir(sprite.dir, Direction::right)) {
71 if (newTileDR.x() > oldTileDR.x() && 76 if (newTileDR.x() > oldTileDR.x() &&
72 newColDR.x() < mapBounds.w()) { 77 newColDR.x() < mapBounds.w()) {
@@ -80,6 +85,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
80 } 85 }
81 } 86 }
82 87
88 if (!result.horiz.blocked && enclosureZone) {
89 if (oldColDR.x() <= enclosureZone->dr.x() &&
90 newColDR.x() > enclosureZone->dr.x()) {
91 result.horiz.blocked = true;
92 result.horiz.dir = Direction::right;
93 }
94 }
95
83 if (!result.horiz.blocked) { 96 if (!result.horiz.blocked) {
84 auto it = rightCollidables_.lower_bound({oldColDR.x(), INT_MAX}); 97 auto it = rightCollidables_.lower_bound({oldColDR.x(), INT_MAX});
85 for (; 98 for (;
@@ -113,6 +126,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
113 } 126 }
114 } 127 }
115 128
129 if (!result.horiz.blocked && enclosureZone) {
130 if (oldColUL.x() >= enclosureZone->ul.x() &&
131 newColUL.x() < enclosureZone->ul.x()) {
132 result.horiz.blocked = true;
133 result.horiz.dir = Direction::left;
134 }
135 }
136
116 if (!result.horiz.blocked) { 137 if (!result.horiz.blocked) {
117 auto it = leftCollidables_.lower_bound({oldColUL.x(), 0}); 138 auto it = leftCollidables_.lower_bound({oldColUL.x(), 0});
118 for (; 139 for (;
@@ -146,6 +167,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
146 } 167 }
147 } 168 }
148 169
170 if (!result.vert.blocked && enclosureZone) {
171 if (oldColDR.y() <= enclosureZone->dr.y() &&
172 newColDR.y() > enclosureZone->dr.y()) {
173 result.vert.blocked = true;
174 result.vert.dir = Direction::down;
175 }
176 }
177
149 if (!result.vert.blocked) { 178 if (!result.vert.blocked) {
150 auto it = downCollidables_.lower_bound({oldColDR.y(), INT_MAX}); 179 auto it = downCollidables_.lower_bound({oldColDR.y(), INT_MAX});
151 for (; 180 for (;
@@ -179,6 +208,14 @@ CollisionResult TransformSystem::checkCollision(int spriteId, vec2i newLoc, Dire
179 } 208 }
180 } 209 }
181 210
211 if (!result.vert.blocked && enclosureZone) {
212 if (oldColUL.y() >= enclosureZone->ul.y() &&
213 newColUL.y() < enclosureZone->ul.y()) {
214 result.vert.blocked = true;
215 result.vert.dir = Direction::up;
216 }
217 }
218
182 if (!result.vert.blocked) { 219 if (!result.vert.blocked) {
183 auto it = upCollidables_.lower_bound({oldColUL.y(), 0}); 220 auto it = upCollidables_.lower_bound({oldColUL.y(), 0});
184 for (; 221 for (;