Fix pushable bugs

This commit is contained in:
Logan Hunt 2022-04-04 15:24:30 -06:00
parent 59880d4b2a
commit 8cdffd7915
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1

View File

@ -51,13 +51,13 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => {
dy: newGridCoords.y - oldGridCoords.y, dy: newGridCoords.y - oldGridCoords.y,
}); });
// TODO: Loop in momentum direction until we find an entity that does not have "push" component
const proposed = { const proposed = {
x: entity.components.gridPosition.x + momentumVector.dx, x: entity.components.gridPosition.x + momentumVector.dx,
y: entity.components.gridPosition.y + momentumVector.dy y: entity.components.gridPosition.y + momentumVector.dy
}; };
const proposedCopy = {...proposed}; const proposedCopy = {...proposed};
if (entity.hasComponent("controllable")) {
let found = false; let found = false;
do { do {
found = false; found = false;
@ -70,11 +70,12 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => {
}); });
proposedCopy.x += momentumVector.dx; proposedCopy.x += momentumVector.dx;
proposedCopy.y += momentumVector.dy; proposedCopy.y += momentumVector.dy;
const proposedCopyInBounds = clamp(proposedCopy, xDim, yDim); const proposedCopyInBounds = clamp(proposedCopy, xDim-1, yDim-1);
if (!equivalence(proposedCopyInBounds, proposedCopy)) { if (!equivalence(proposedCopyInBounds, proposedCopy)) {
found = false; found = false;
} }
} while (found); } while (found);
}
entity.components.gridPosition = {...entity.components.gridPosition, ...proposed}; entity.components.gridPosition = {...entity.components.gridPosition, ...proposed};