aboutsummaryrefslogtreecommitdiffstats
path: root/src/Events.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-06-02 23:13:07 +0200
committerMaksymilian Jopek <maks@jopek.eu>2022-06-02 23:16:33 +0200
commitb4defa324a330217f0139f1240bcf53c0b1f996a (patch)
treedeabb94fd351b10d3d6b38d967424149536b3927 /src/Events.ts
parentef76266d1a61c02f1721efedc830fab12279d2b9 (diff)
download1942-b4defa324a330217f0139f1240bcf53c0b1f996a.tar.gz
1942-b4defa324a330217f0139f1240bcf53c0b1f996a.tar.zst
1942-b4defa324a330217f0139f1240bcf53c0b1f996a.zip
v1.0.0
Diffstat (limited to 'src/Events.ts')
-rw-r--r--src/Events.ts10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Events.ts b/src/Events.ts
index 2a07ea9..7d925b4 100644
--- a/src/Events.ts
+++ b/src/Events.ts
@@ -14,6 +14,8 @@ export const keys = {
roll: false,
repeat: false,
fps: 50,
+ lastx: "",
+ lasty: "",
}
// window.onkeydown = window.onkeydown ?? ((e: KeyboardEvent) => e.repeat ? keys.fire = false : setKey(e.key, true))
@@ -21,10 +23,10 @@ window.onkeydown = window.onkeydown ?? ((e: KeyboardEvent) => setKey(e.key, true
window.onkeyup = window.onkeyup ?? ((e: KeyboardEvent) => setKey(e.key, false, e.repeat))
function setKey(key: string, val: boolean, repeat: boolean) {
- if (["w", "k"].includes(key)) keys.up = val;
- else if (["a", "h"].includes(key)) keys.left = val;
- else if (["s", "j"].includes(key)) keys.down = val;
- else if (["d", "l"].includes(key)) keys.right = val;
+ if (["w", "k"].includes(key)) { keys.up = val; keys.lasty = "up" }
+ else if (["a", "h"].includes(key)) { keys.left = val; keys.lastx = "left" }
+ else if (["s", "j"].includes(key)) { keys.down = val; keys.lasty = "down" }
+ else if (["d", "l"].includes(key)) { keys.right = val; keys.lastx = "right" }
else if (["m", ";", "/"].includes(key)) { keys.fire = val; keys.repeat = repeat }
else if ([" "].includes(key)) keys.roll = val;
else if (["r"].includes(key)) location.reload();