Fix pushable bugs
This commit is contained in:
parent
59880d4b2a
commit
8cdffd7915
@ -51,30 +51,31 @@ 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};
|
||||||
let found = false;
|
if (entity.hasComponent("controllable")) {
|
||||||
do {
|
let found = false;
|
||||||
found = false;
|
do {
|
||||||
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)) {
|
|
||||||
found = false;
|
found = false;
|
||||||
}
|
const entitiesInCell = entitiesGrid[proposedCopy.y][proposedCopy.x];
|
||||||
} while (found);
|
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};
|
entity.components.gridPosition = {...entity.components.gridPosition, ...proposed};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user