diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-04 18:30:11 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-04 18:30:11 -0600 |
commit | dee568c51dbf2393aa7bd75f4241602af8022a2c (patch) | |
tree | 2e559ede69540b680a00ccf20bf96ff998230ed8 /src/game.js | |
parent | 14ddb31441e35dce7425385948a9ee63b262cece (diff) | |
download | bbiy-dee568c51dbf2393aa7bd75f4241602af8022a2c.tar.gz bbiy-dee568c51dbf2393aa7bd75f4241602af8022a2c.zip |
Fix flickering issue by having singleton sprites; add loading priority; load levels from source
Diffstat (limited to 'src/game.js')
-rw-r--r-- | src/game.js | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/game.js b/src/game.js index 69a91ce..073455a 100644 --- a/src/game.js +++ b/src/game.js @@ -7,37 +7,25 @@ game.loop = (timeStamp) => { game.systems[i].update(elapsedTime, game.entities); }); + if (game.nextLevel) { + game.loadLevel(game.nextLevel); + game.nextLevel = false; + } + requestAnimationFrame(game.loop); } game.initialize = () => { + [game.entities, game.config] = game.loadLevel(game.levels[0]); + game.systemOrder = ["render", "physics", "gridSystem", "keyboardInput"]; 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, - }), + gridSystem: game.system.GridSystem({...game.config}), keyboardInput: game.system.KeyboardInput(), }; - game.entities = {}; - - Array(10).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)})); - bigBlue.addComponent(game.components.Controllable({controls: ['left', 'right', 'up', 'down']})); - game.entities[bigBlue.id] = bigBlue; - }); - - game.rock = game.createRock(); - game.rock.addComponent(game.components.Position({x: 200, y: 200})); - game.rock.addComponent(game.components.GridPosition({x: 0, y: 0})); - game.rock.addComponent(game.components.Pushable()); - game.entities[game.rock.id] = game.rock; lastTimeStamp = performance.now() requestAnimationFrame(game.loop); |