Created
September 26, 2011 04:26
-
-
Save paulbatum/1241611 to your computer and use it in GitHub Desktop.
PushFrenzy input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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