Guest User

Untitled

a guest
Jan 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. game.input = (($, game) ->
  2. updatePlayEnabled = ->
  3. if($('#namebox').val().length == 0)
  4. $('#playbutton').attr('disabled', 'disabled')
  5. else
  6. $('#playbutton').removeAttr('disabled')
  7.  
  8. bindKeyboardControls = (websocket) ->
  9. moveKeyMap =
  10. Down: ['down', 's']
  11. Up: ['up', 'w']
  12. Left: ['left', 'a']
  13. Right: ['right', 'd']
  14. for direction, keys of moveKeyMap
  15. for key in keys
  16. $(document).bind('keydown', key, -> move(websocket, direction))
  17.  
  18. bindTouchControls = (websocket) =>
  19. $('#arrorImg').bind('dragstart', (event) -> event.preventDefault())
  20. $('#arrowMap area')
  21. .click( (event) -> event.preventDefault())
  22. .mousedown( (event) ->
  23. moveFn = -> move(websocket, $(event.target).attr('alt'))
  24. moveFn()
  25. clearInterval(interval) if interval
  26. interval = setInterval(moveFn, 200)
  27. event.preventDefault())
  28. .bind('mouseup mouseleave', -> clearInterval(interval))
  29.  
  30. move = (websocket, direction) ->
  31. msg =
  32. Type: 'PlayerMoveCommand'
  33. Direction: direction
  34.  
  35. websocket.send(JSON.stringify(msg))
  36.  
  37. input =
  38. prepareNameBox: ->
  39. updatePlayEnabled()
  40. $('#namebox').keyup(updatePlayEnabled).focus()
  41. bindControls: (websocket) ->
  42. bindTouchControls(websocket)
  43. bindKeyboardControls(websocket)
  44.  
  45. )(jQuery, game)
Add Comment
Please, Sign In to add comment