From 8996810b1356c2224d4f34423fd4211de20da238 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 19 Feb 2019 16:22:39 -0500 Subject: 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. --- src/simulation.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/simulation.cpp') 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( { Entity& block = entities_.at(blockId); - if (!block.moving && block.playerCanPush) + if (!block.moving && block.canBePushedBy.count(ColliderType::player)) { moveEntityOnGrid(blockId, lookDir); } @@ -169,6 +169,8 @@ bool Simulation::moveEntityOnGrid( Direction moveDir, bool validate) { + bool actuallyMove = true; + Entity& entity = entities_.at(id); vec2s shouldMoveTo = posInDir(entity.gridPos, moveDir); @@ -216,18 +218,20 @@ bool Simulation::moveEntityOnGrid( } } - if (entity.colliderType == ColliderType::player) + if (!level_.getTileset().canEntityMoveTo( + entity.colliderType, + level_.at(shouldMoveTo))) { - if (!level_.getTileset().canPlayerMoveTo(level_.at(shouldMoveTo))) - { - return false; - } + return false; + } - for (id_type blockId : getGridEntities(shouldMoveTo)) - { - Entity& block = entities_.at(blockId); + for (id_type blockId : getGridEntities(shouldMoveTo)) + { + Entity& block = entities_.at(blockId); - if (block.moving || !block.playerCanPush) + if (!block.moving) + { + if (!block.canBePushedBy.count(entity.colliderType)) { return false; } @@ -238,13 +242,20 @@ bool Simulation::moveEntityOnGrid( } } + double entityTimeLeft = 1.0 / entity.speed; + double blockTimeLeft = (1.0 - block.movementTween) / block.speed; + + if (entityTimeLeft < blockTimeLeft) + { + actuallyMove = false; + } } - if (!validate) + if (!validate && actuallyMove) { entity.moving = true; entity.destPos = shouldMoveTo; -- cgit 1.4.1