diff options
author | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-12 22:22:33 -0600 |
---|---|---|
committer | Logan Hunt <loganhunt@simponic.xyz> | 2022-04-12 22:22:33 -0600 |
commit | 27fa6357a699771ade4ed5bf8c3fb32d7e73f4d4 (patch) | |
tree | 10e5eb62dc2bfcdf26ced2bfc45f7645408c5307 /src/systems/keyboardInput.js | |
parent | cdb258991cc6ba8d4219038d9580e64d5e416803 (diff) | |
download | bbiy-27fa6357a699771ade4ed5bf8c3fb32d7e73f4d4.tar.gz bbiy-27fa6357a699771ade4ed5bf8c3fb32d7e73f4d4.zip |
Add menuing system with level select and control changing
Diffstat (limited to 'src/systems/keyboardInput.js')
-rw-r--r-- | src/systems/keyboardInput.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/systems/keyboardInput.js b/src/systems/keyboardInput.js index 80feeef..06a73c9 100644 --- a/src/systems/keyboardInput.js +++ b/src/systems/keyboardInput.js @@ -1,4 +1,4 @@ -game.system.KeyboardInput = (undoSystem) => { +game.system.KeyboardInput = () => { "use strict"; const keys = {}; const keyPress = (event) => { @@ -6,31 +6,41 @@ game.system.KeyboardInput = (undoSystem) => { keys[event.key] = true; } }; + const removeKey = (event) => { + delete keys[event.key]; + }; const update = (elapsedTime, entities, changedIds) => { for (let id in entities) { const entity = entities[id]; if (entity.hasComponent('controllable')) { const controls = entity.components.controllable.controls; if (!changedIds.has(entity.id)) { - if (controls.includes('left') && keys['ArrowLeft']) { + if (controls.includes('left') && keys[game.controls.left]) { entity.addComponent(game.components.Momentum({ dx: -1, dy: 0 })); - } else if (controls.includes('right') && keys['ArrowRight']) { + } else if (controls.includes('right') && keys[game.controls.right]) { entity.addComponent(game.components.Momentum({ dx: 1, dy: 0 })); - } else if (controls.includes('up') && keys['ArrowUp']) { + } else if (controls.includes('up') && keys[game.controls.up]) { entity.addComponent(game.components.Momentum({ dx: 0, dy: -1 })); - } else if (controls.includes('down') && keys['ArrowDown']) { + } else if (controls.includes('down') && keys[game.controls.down]) { entity.addComponent(game.components.Momentum({ dx: 0, dy: 1 })); } } } } - if (keys['z']) { - undoSystem.undo(entities); + if (keys[game.controls.undo]) { + game.systems.undo.undo(entities); + } + if (keys[game.controls.reset]) { + game.loadLevelIndex(game.level); + } + if (keys["Escape"]) { + game.systems.menu.bringUpMenu(); } Object.keys(keys).map((key) => delete keys[key]); return new Set(); }; window.addEventListener("keydown", keyPress); + window.addEventListener("keyup", removeKey); return { keys, update }; } |