summaryrefslogtreecommitdiff
path: root/src/systems/gridSystem.js
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-04 18:30:11 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-04 18:30:11 -0600
commitdee568c51dbf2393aa7bd75f4241602af8022a2c (patch)
tree2e559ede69540b680a00ccf20bf96ff998230ed8 /src/systems/gridSystem.js
parent14ddb31441e35dce7425385948a9ee63b262cece (diff)
downloadbbiy-dee568c51dbf2393aa7bd75f4241602af8022a2c.tar.gz
bbiy-dee568c51dbf2393aa7bd75f4241602af8022a2c.zip
Fix flickering issue by having singleton sprites; add loading priority; load levels from source
Diffstat (limited to 'src/systems/gridSystem.js')
-rw-r--r--src/systems/gridSystem.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/systems/gridSystem.js b/src/systems/gridSystem.js
index b8d49e6..ef5a6e1 100644
--- a/src/systems/gridSystem.js
+++ b/src/systems/gridSystem.js
@@ -1,11 +1,11 @@
-game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => {
+game.system.GridSystem = ({ xDim, yDim }) => {
const entitiesGrid = Array(yDim).fill(null).map(() => Array(xDim).fill(null).map(() => new Map()));
- const gridWidth = canvasWidth / xDim;
- const gridHeight = canvasHeight / yDim;
+ let gridWidth = game.canvas.width / xDim;
+ let gridHeight = game.canvas.height / yDim;
const gameCoordsToGrid = ({ x, y }) => {
- return { x: Math.floor((x+gridWidth/2) / canvasWidth * xDim), y: Math.floor((y+gridHeight/2) / canvasHeight * yDim) };
+ return { x: Math.floor((x+gridWidth/2) / game.canvas.width * xDim), y: Math.floor((y+gridHeight/2) / game.canvas.height * yDim) };
};
const gridCoordsToGame = ({ x, y }) => {
@@ -39,8 +39,8 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => {
rebuildGrid(gridEntities);
gridEntities.map((entity) => {
if (entity.hasComponent("appearance")) {
- entity.components.appearance.width = canvasWidth / xDim;
- entity.components.appearance.height = canvasHeight / yDim;
+ entity.components.appearance.width = gridWidth;
+ entity.components.appearance.height = gridHeight;
}
if (entity.hasComponent("position")) {
const newGridCoords = gameCoordsToGrid(entity.components.position);
@@ -89,7 +89,9 @@ game.system.GridSystem = ({ xDim, yDim, canvasWidth, canvasHeight }) => {
entity.components.momentum.dy = 0;
}
}
- }
+ } else {
+ entity.addComponent(game.components.Position({...gridCoordsToGame(entity.components.gridPosition)}));
+ };
});
};