summaryrefslogtreecommitdiff
path: root/src/systems/keyboardInput.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems/keyboardInput.js')
-rw-r--r--src/systems/keyboardInput.js24
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 };
}