Coffeescript Game Tutorial the Keyboard 2014-07-29 ProgrammingCoffeScript CoffeScript, Game, Programming 키보드 이벤트를 추가한 코드이다. 1234567891011121314151617181920212223242526272829303132333435363738rightDown = falseleftDown = false# set rightDown or leftDown if the right or left key are downdocument.onkeydown = (evt) ->switch evt.keyCodewhen 39 then rightDown = truewhen 37 then leftDown = true# and unset then when the right or left key is releaseddocument.onkeyup = (evt) ->switch evt.keyCodewhen 39 then rightDown = falsewhen 37 then leftDown = falsedraw = ->clear()circle(x, y, 10)# move the paddle if left or right is currently pressedpaddlex += 5 if rightDownpaddlex -= 5 if leftDownrect(paddlex, HEIGHT-paddleh, paddlew, paddleh)dx = -dx if x + dx > WIDTH or x + dx < 0if y + dy < 0 then dy = -dyelse if y + dy > HEIGHTif x > paddlex and x < paddlex + paddlewdy = -dyelse# game over, so stop the animationclearInterval(intervalId)x += dx;y += dy;window.onload = ->init() Reference Newer Coffeescript Game Tutorial Add a Paddle Older Coffeescript Game Tutorial the Mouse