-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.js
33 lines (31 loc) · 872 Bytes
/
input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
let inputDirection = {x: 0, y: 0};
let lastInputDirection = {x: 0, y:0}
window.addEventListener('keydown', e => {
switch (e.key) {
case 'ArrowUp':
if (lastInputDirection.y !== 0)
break;
inputDirection = {x: 0, y: -1}
break;
case 'ArrowDown':
if (lastInputDirection.y !== 0)
break;
inputDirection = {x: 0, y: 1}
break;
case 'ArrowLeft':
if (lastInputDirection.x !== 0)
break;
inputDirection = {x: -1, y: 0}
break;
case 'ArrowRight':
if (lastInputDirection.x !== 0)
break;
inputDirection = {x: 1, y: 0}
break;
}
})
export function getInputDirection()
{
lastInputDirection = inputDirection;
return(inputDirection);
}