Skip to content

Instantly share code, notes, and snippets.

@paulbatum
Created September 26, 2011 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulbatum/1241611 to your computer and use it in GitHub Desktop.
Save paulbatum/1241611 to your computer and use it in GitHub Desktop.
PushFrenzy input
game.input = (($, game) ->
updatePlayEnabled = ->
if($('#namebox').val().length == 0)
$('#playbutton').attr('disabled', 'disabled')
else
$('#playbutton').removeAttr('disabled')
bindKeyboardControls = (websocket) ->
moveKeyMap =
Down: ['down', 's']
Up: ['up', 'w']
Left: ['left', 'a']
Right: ['right', 'd']
for direction, keys of moveKeyMap
for key in keys
$(document).bind('keydown', key, -> move(websocket, direction))
bindTouchControls = (websocket) =>
$('#arrorImg').bind('dragstart', (event) -> event.preventDefault())
$('#arrowMap area')
.click( (event) -> event.preventDefault())
.mousedown( (event) ->
moveFn = -> move(websocket, $(event.target).attr('alt'))
moveFn()
clearInterval(interval) if interval
interval = setInterval(moveFn, 200)
event.preventDefault())
.bind('mouseup mouseleave', -> clearInterval(interval))
move = (websocket, direction) ->
msg =
Type: 'PlayerMoveCommand'
Direction: direction
websocket.send(JSON.stringify(msg))
input =
prepareNameBox: ->
updatePlayEnabled()
$('#namebox').keyup(updatePlayEnabled).focus()
bindControls: (websocket) ->
bindTouchControls(websocket)
bindKeyboardControls(websocket)
)(jQuery, game)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment