2022-04-02 16:04:13 -06:00
|
|
|
let lastTimeStamp;
|
|
|
|
game.loop = (timeStamp) => {
|
|
|
|
let elapsedTime = timeStamp - lastTimeStamp;
|
|
|
|
lastTimeStamp = timeStamp;
|
|
|
|
|
|
|
|
game.systemOrder.map((i) => {
|
|
|
|
game.systems[i].update(elapsedTime, game.entities);
|
|
|
|
});
|
2022-03-27 02:17:26 -06:00
|
|
|
|
2022-04-01 17:12:37 -06:00
|
|
|
requestAnimationFrame(game.loop);
|
|
|
|
}
|
2022-03-27 02:17:26 -06:00
|
|
|
|
2022-04-01 17:12:37 -06:00
|
|
|
game.initialize = () => {
|
2022-04-02 18:37:36 -06:00
|
|
|
game.systemOrder = ["render", "physics", "gridSystem", "keyboardInput"];
|
2022-04-02 16:04:13 -06:00
|
|
|
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,
|
|
|
|
}),
|
2022-04-02 18:37:36 -06:00
|
|
|
keyboardInput: game.system.KeyboardInput(),
|
2022-04-02 16:04:13 -06:00
|
|
|
};
|
|
|
|
|
2022-04-01 17:12:37 -06:00
|
|
|
game.entities = {};
|
2022-04-02 16:04:13 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
2022-04-01 17:49:20 -06:00
|
|
|
|
|
|
|
game.rock = game.createRock();
|
2022-04-02 16:04:13 -06:00
|
|
|
game.rock.addComponent(game.components.Position({x: 200, y: 200}));
|
|
|
|
game.rock.addComponent(game.components.GridPosition({x: 0, y: 0}));
|
2022-04-02 18:37:36 -06:00
|
|
|
game.rock.addComponent(game.components.Controllable({controls: ['left', 'right', 'up', 'down']}));
|
2022-04-01 17:49:20 -06:00
|
|
|
game.entities[game.rock.id] = game.rock;
|
|
|
|
|
2022-04-02 16:04:13 -06:00
|
|
|
lastTimeStamp = performance.now()
|
2022-04-01 17:12:37 -06:00
|
|
|
requestAnimationFrame(game.loop);
|
2022-03-27 02:17:26 -06:00
|
|
|
}
|