Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Created August 1, 2012 20:47
Show Gist options
  • Save cfjedimaster/3230580 to your computer and use it in GitHub Desktop.
Save cfjedimaster/3230580 to your computer and use it in GitHub Desktop.
function loop() {
//check for gamepad
if(navigator.webkitGamepads) {
var gamepads = navigator.webkitGamepads;
for (var padindex = 0; padindex < gamepads.length; ++padindex) {
var pad = gamepads[padindex];
var i;
if (!pad) continue;
//focus on the first stick
if(pad.axes.length >= 1) {
var axevalue = pad.axes[0];
if(axevalue == -1) {input.left=true; input.right=false; }
else if(axevalue ==1) {input.left=false; input.right=true;}
else {input.left=false; input.right=false;}
}
}
}
draw.clear();
ball.move();
ball.draw();
paddle.draw();
paddle.move();
draw.text("Misses: "+score, 10, 20, 20, "white");
window.requestAnimationFrame(loop);
}
window.requestAnimationFrame(loop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment