diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-12-23 18:32:29 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-12-23 18:32:29 +0100 |
commit | a840990bdcabf45fb0d377478ba0ab27222434ae (patch) | |
tree | 030a6c3a6befce284733f5643d3972e3a1504bb2 /src/engine/keyboard.js |
initial commit
Diffstat (limited to 'src/engine/keyboard.js')
-rw-r--r-- | src/engine/keyboard.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/engine/keyboard.js b/src/engine/keyboard.js new file mode 100644 index 0000000..d634519 --- /dev/null +++ b/src/engine/keyboard.js @@ -0,0 +1,23 @@ +export function setUpKeyboard() { + document.addEventListener("keyup", k => trigger(k)) + document.addEventListener("keydown", k => trigger(k)) +} + +export const keys = { + right: false, + left: false, + up: false, + down: false, + shoot: false, +} + +function trigger(event) { + let on = event.type == "keydown" + switch (event.key) { + case "ArrowRight": keys.right = on; break; + case "ArrowLeft": keys.left = on; break; + case "ArrowUp": keys.up = on; break; + case "ArrowDown": keys.down = on; break; + case "z": case "Z": keys.shoot = on; break; + } +} |