From cf4dbf91ddb980c051ee2905367143d433c376a5 Mon Sep 17 00:00:00 2001 From: phat_sumo Date: Sat, 2 Apr 2022 18:48:00 -0600 Subject: the mess that is pushable --- src/systems/gridSystem.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/systems/gridSystem.js') diff --git a/src/systems/gridSystem.js b/src/systems/gridSystem.js index 05ce17e..c80fe1a 100644 --- a/src/systems/gridSystem.js +++ b/src/systems/gridSystem.js @@ -52,6 +52,16 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => { }); // 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 entitiesInCell = entitiesGrid[proposed.x][proposed.y]; + + for (let id in entitiesInCell) { + if (entitiesInCell[id].hasComponent("pushable")) { + entitiesInCell[id].addComponent(game.components.Momentum({...momentumVector})); + } + } + entity.components.gridPosition.x = entity.components.gridPosition.x + momentumVector.dx; entity.components.gridPosition.y = entity.components.gridPosition.y + momentumVector.dy; @@ -70,4 +80,4 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => { }; return { entitiesGrid, gameCoordsToGrid, gridCoordsToGame, update, gridWidth, gridHeight }; -}; \ No newline at end of file +}; -- cgit v1.2.3-70-g09d2