summaryrefslogtreecommitdiff
path: root/src/systems/gridSystem.js
diff options
context:
space:
mode:
authorphat_sumo <ethanjpayne1@gmail.com>2022-04-02 18:48:00 -0600
committerphat_sumo <ethanjpayne1@gmail.com>2022-04-02 18:48:00 -0600
commitcf4dbf91ddb980c051ee2905367143d433c376a5 (patch)
tree9b4697850979774ba8056ac792230bfb7b8a2073 /src/systems/gridSystem.js
parentaef3c05bc7f3feba7832078aa1cb4bd96c52c1dd (diff)
downloadbbiy-cf4dbf91ddb980c051ee2905367143d433c376a5.tar.gz
bbiy-cf4dbf91ddb980c051ee2905367143d433c376a5.zip
the mess that is pushable
Diffstat (limited to 'src/systems/gridSystem.js')
-rw-r--r--src/systems/gridSystem.js12
1 files changed, 11 insertions, 1 deletions
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
+};