Last active
August 29, 2015 14:03
-
-
Save dpickett/fbe3e7cdcdcbebb67a8b to your computer and use it in GitHub Desktop.
players
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
function KeyHandler(){ | |
//handy underscoreJS function | |
_.bindAll(this, 'handleUpKey', 'handleKey'); | |
this.handleUp = function(e){ | |
//we can use jQuery to trigger events on plain ol' JavaScript objects | |
$(this).trigger('up'); | |
} | |
this.handleKey = function(e){ | |
if(e.keyCode === UP_KEY){ | |
this.handleUp(e); | |
} | |
} | |
} | |
function PlayerKeyBinding(player, keyHandler){ | |
$(keyhandler).on('up', function(){ | |
player.moveUp(); | |
}); | |
} | |
var keyhandler = new KeyHandler(); | |
var player = new Player(); | |
var playerKeyBinding = new PlayerKeyBinding(player, keyhandler) | |
$(document).on('keydown', keyhandler.handleKey); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment