FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Javascript-Snake-Game/input.js at master · WebDevSimplified/Javascript-Snake-Game · GitHub
WebDevSimplified
Javascript-Snake-Game
Repository navigation
Code
Issues
Pull requests
2
(2)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Javascript-Snake-Game
/
input.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (26 loc) · 712 Bytes
Breadcrumbs
Javascript-Snake-Game
/
input.js
Copy path
File metadata and controls
28 lines (26 loc) · 712 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
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
}
Back
|
FazBrowse Home
|
New Git URL