Created
May 5, 2011 19:10
-
-
Save diegoponciano/957684 to your computer and use it in GitHub Desktop.
input controls
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
var gamejs = require('gamejs'); | |
exports.UserControls = function(size, sticker) { | |
this.size = size; | |
this.sticker = sticker; | |
this.left = false; | |
this.right = false; | |
this.paused = false; | |
this.initialClick = false; | |
this.handle = function(event) { | |
if (event.type === gamejs.event.KEY_DOWN) { | |
if (event.key === gamejs.event.K_LEFT) { | |
this.left = true; | |
} else if (event.key === gamejs.event.K_RIGHT) { | |
this.right = true; | |
} else if (event.key === gamejs.event.K_ESC) { | |
this.paused = !this.paused; | |
} else { | |
console.debug(event.key); | |
} | |
} else if (event.type === gamejs.event.KEY_UP) { | |
if (event.key === gamejs.event.K_LEFT) { | |
this.left = false; | |
} else if (event.key === gamejs.event.K_RIGHT) { | |
this.right = false; | |
} | |
} else if (event.type === gamejs.event.MOUSE_DOWN) { | |
if ((event.pos[0] > 0 && event.pos[0] < this.size[0]) && (event.pos[1] > 0 && event.pos[1] < this.size[1])) { | |
this.initialClick = true; | |
} | |
} | |
} | |
this.angle = function () { | |
if (this.left) { | |
return Math.PI; | |
} else if (this.right) { | |
return 0; | |
} | |
return null; | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment