Skip to content

Instantly share code, notes, and snippets.

@KFMichael
Forked from cfjedimaster/gist:3230580
Last active August 29, 2015 14:25
Show Gist options
  • Save KFMichael/f8e19f376d16b834a62f to your computer and use it in GitHub Desktop.
Save KFMichael/f8e19f376d16b834a62f 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