-
-
Save KFMichael/f8e19f376d16b834a62f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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