diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-04 15:24:30 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-04 15:24:30 -0600 |
commit | 8cdffd7915be4f9e39b0eb667f92667d72140880 (patch) | |
tree | c4e63fc206224d7d30341f0791b3469b44e9e9da | |
parent | 59880d4b2a7c3298561ad37d04ee502ec5c51b2c (diff) | |
download | bbiy-8cdffd7915be4f9e39b0eb667f92667d72140880.tar.gz bbiy-8cdffd7915be4f9e39b0eb667f92667d72140880.zip |
Fix pushable bugs
-rw-r--r-- | src/systems/gridSystem.js | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/systems/gridSystem.js b/src/systems/gridSystem.js index bc67bbb..b8d49e6 100644 --- a/src/systems/gridSystem.js +++ b/src/systems/gridSystem.js @@ -51,30 +51,31 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => { dy: newGridCoords.y - oldGridCoords.y, }); - // TODO: Loop in momentum direction until we find an entity that does not have "push" component const proposed = { x: entity.components.gridPosition.x + momentumVector.dx, y: entity.components.gridPosition.y + momentumVector.dy }; const proposedCopy = {...proposed}; - let found = false; - do { - found = false; - const entitiesInCell = entitiesGrid[proposedCopy.y][proposedCopy.x]; - entitiesInCell.forEach((entity) => { - if (entity.hasComponent("pushable")) { - entity.addComponent(game.components.Momentum({...momentumVector})); - found = true; - } - }); - proposedCopy.x += momentumVector.dx; - proposedCopy.y += momentumVector.dy; - const proposedCopyInBounds = clamp(proposedCopy, xDim, yDim); - if (!equivalence(proposedCopyInBounds, proposedCopy)) { + if (entity.hasComponent("controllable")) { + let found = false; + do { found = false; - } - } while (found); + const entitiesInCell = entitiesGrid[proposedCopy.y][proposedCopy.x]; + entitiesInCell.forEach((entity) => { + if (entity.hasComponent("pushable")) { + entity.addComponent(game.components.Momentum({...momentumVector})); + found = true; + } + }); + proposedCopy.x += momentumVector.dx; + proposedCopy.y += momentumVector.dy; + const proposedCopyInBounds = clamp(proposedCopy, xDim-1, yDim-1); + if (!equivalence(proposedCopyInBounds, proposedCopy)) { + found = false; + } + } while (found); + } entity.components.gridPosition = {...entity.components.gridPosition, ...proposed}; |