Skip to content

Commit 93954e4

Browse files
committed
Section 22: Handling Keypresses
1 parent f57893d commit 93954e4

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

22-Javascript-with-the-Canvas-API/02-Maze copy/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,21 @@ const ball = Bodies.circle(
183183
unitLength / 2,
184184
unitLength / 4
185185
)
186-
World.add(world, ball)
186+
World.add(world, ball)
187+
188+
document.addEventListener('keydown', event => {
189+
console.log(event.keyCode)
190+
console.log(event);
191+
if (event.keyCode === 38) {
192+
console.log('move ball up')
193+
}
194+
if (event.keyCode === 39) {
195+
console.log('move ball right')
196+
}
197+
if (event.keyCode === 40) {
198+
console.log('move ball down')
199+
}
200+
if (event.keyCode === 37) {
201+
console.log('move ball left')
202+
}
203+
})

22-Javascript-with-the-Canvas-API/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@ console.log(grid)
8181

8282
## 21. 25 Drawing the Goal
8383

84-
## 22. 26 Drawing the Playing Ball
84+
## 22. 26 Drawing the Playing Ball
85+
86+
## 23. 27 Handling Keypresses

0 commit comments

Comments
 (0)