File tree Expand file tree Collapse file tree
22-Javascript-with-the-Canvas-API Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ } )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments