diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-19 16:22:39 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-02-19 16:22:39 -0500 |
commit | 8996810b1356c2224d4f34423fd4211de20da238 (patch) | |
tree | 9beab3f77e6af1c769e14cff4234ad649cf857f2 /src/simulation.cpp | |
parent | 7514077a07076403f29050e57fa87f24fc614122 (diff) | |
download | dispatcher-8996810b1356c2224d4f34423fd4211de20da238.tar.gz dispatcher-8996810b1356c2224d4f34423fd4211de20da238.tar.bz2 dispatcher-8996810b1356c2224d4f34423fd4211de20da238.zip |
Restrictions for moving into a space a block is moving out of
An entity can only move into a space a block is moving out of if the time it would take the entity to move into the tile is at least the time remaining for the other block to finish moving out of the space. Also, crates can push each other now.
Diffstat (limited to 'src/simulation.cpp')
-rw-r--r-- | src/simulation.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/simulation.cpp b/src/simulation.cpp index ca6ca3d..912f7f0 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp | |||
@@ -42,7 +42,7 @@ void Simulation::tick( | |||
42 | { | 42 | { |
43 | Entity& block = entities_.at(blockId); | 43 | Entity& block = entities_.at(blockId); |
44 | 44 | ||
45 | if (!block.moving && block.playerCanPush) | 45 | if (!block.moving && block.canBePushedBy.count(ColliderType::player)) |
46 | { | 46 | { |
47 | moveEntityOnGrid(blockId, lookDir); | 47 | moveEntityOnGrid(blockId, lookDir); |
48 | } | 48 | } |
@@ -169,6 +169,8 @@ bool Simulation::moveEntityOnGrid( | |||
169 | Direction moveDir, | 169 | Direction moveDir, |
170 | bool validate) | 170 | bool validate) |
171 | { | 171 | { |
172 | bool actuallyMove = true; | ||
173 | |||
172 | Entity& entity = entities_.at(id); | 174 | Entity& entity = entities_.at(id); |
173 | 175 | ||
174 | vec2s shouldMoveTo = posInDir(entity.gridPos, moveDir); | 176 | vec2s shouldMoveTo = posInDir(entity.gridPos, moveDir); |
@@ -216,18 +218,20 @@ bool Simulation::moveEntityOnGrid( | |||
216 | } | 218 | } |
217 | } | 219 | } |
218 | 220 | ||
219 | if (entity.colliderType == ColliderType::player) | 221 | if (!level_.getTileset().canEntityMoveTo( |
222 | entity.colliderType, | ||
223 | level_.at(shouldMoveTo))) | ||
220 | { | 224 | { |
221 | if (!level_.getTileset().canPlayerMoveTo(level_.at(shouldMoveTo))) | 225 | return false; |
222 | { | 226 | } |
223 | return false; | ||
224 | } | ||
225 | 227 | ||
226 | for (id_type blockId : getGridEntities(shouldMoveTo)) | 228 | for (id_type blockId : getGridEntities(shouldMoveTo)) |
227 | { | 229 | { |
228 | Entity& block = entities_.at(blockId); | 230 | Entity& block = entities_.at(blockId); |
229 | 231 | ||
230 | if (block.moving || !block.playerCanPush) | 232 | if (!block.moving) |
233 | { | ||
234 | if (!block.canBePushedBy.count(entity.colliderType)) | ||
231 | { | 235 | { |
232 | return false; | 236 | return false; |
233 | } | 237 | } |
@@ -238,13 +242,20 @@ bool Simulation::moveEntityOnGrid( | |||
238 | } | 242 | } |
239 | } | 243 | } |
240 | 244 | ||
245 | double entityTimeLeft = 1.0 / entity.speed; | ||
246 | double blockTimeLeft = (1.0 - block.movementTween) / block.speed; | ||
247 | |||
248 | if (entityTimeLeft < blockTimeLeft) | ||
249 | { | ||
250 | actuallyMove = false; | ||
251 | } | ||
241 | } | 252 | } |
242 | 253 | ||
243 | 254 | ||
244 | 255 | ||
245 | 256 | ||
246 | 257 | ||
247 | if (!validate) | 258 | if (!validate && actuallyMove) |
248 | { | 259 | { |
249 | entity.moving = true; | 260 | entity.moving = true; |
250 | entity.destPos = shouldMoveTo; | 261 | entity.destPos = shouldMoveTo; |