summaryrefslogtreecommitdiff
path: root/src/game.js
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-02 16:04:13 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-02 16:04:13 -0600
commit5a55b5fa0c678ff03842d2adec8543e754546718 (patch)
tree4f615829acc10045d81a9d553c757a14792bf81a /src/game.js
parent4d34b0b4b890e957030fbf6e3c8e1d4a02d2a627 (diff)
downloadbbiy-5a55b5fa0c678ff03842d2adec8543e754546718.tar.gz
bbiy-5a55b5fa0c678ff03842d2adec8543e754546718.zip
Grid system & simple physics
Diffstat (limited to 'src/game.js')
-rw-r--r--src/game.js37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/game.js b/src/game.js
index cd82cc0..9cf60c6 100644
--- a/src/game.js
+++ b/src/game.js
@@ -1,20 +1,41 @@
-game.loop = (elapsedTime) => {
- game.systems.Render.update(elapsedTime);
+let lastTimeStamp;
+game.loop = (timeStamp) => {
+ let elapsedTime = timeStamp - lastTimeStamp;
+ lastTimeStamp = timeStamp;
+
+ game.systemOrder.map((i) => {
+ game.systems[i].update(elapsedTime, game.entities);
+ });
requestAnimationFrame(game.loop);
}
game.initialize = () => {
+ game.systemOrder = ["render", "physics", "gridSystem"];
+ game.systems = {
+ render: game.system.Render(game.graphics),
+ physics: game.system.Physics(),
+ gridSystem: game.system.GridSystem({
+ xDim: 15,
+ yDim: 15,
+ canvasWidth: game.canvas.width,
+ canvasHeight: game.canvas.height,
+ }),
+ };
+
game.entities = {};
- game.bigBlue = game.createBigBlue();
- game.entities[game.bigBlue.id] = game.bigBlue;
- game.bigBlue2 = game.createBigBlue();
- game.bigBlue2.components.position = game.components.Position({x: 200, y: 100});
- game.entities[game.bigBlue2.id] = game.bigBlue2;
+
+ Array(400).fill(null).forEach((_, i) => {
+ const bigBlue = game.createBigBlue();
+ bigBlue.addComponent(game.components.GridPosition({x: Math.floor(Math.random() * 15), y: Math.floor(Math.random() * 13)}));
+ game.entities[bigBlue.id] = bigBlue;
+ });
game.rock = game.createRock();
- game.rock.components.position = game.components.Position({x: 200, y: 200});
+ game.rock.addComponent(game.components.Position({x: 200, y: 200}));
+ game.rock.addComponent(game.components.GridPosition({x: 0, y: 0}));
game.entities[game.rock.id] = game.rock;
+ lastTimeStamp = performance.now()
requestAnimationFrame(game.loop);
}