-
-
Save alandownie/8e2fe28e9edf356ac966 to your computer and use it in GitHub Desktop.
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 countPieces() { | |
it = b.pieces(); | |
var i = 0; | |
while (it.current()){ i++; it.next() } | |
return i; | |
} | |
function getRandPiece() { | |
var it = b.pieces(); | |
var n = Math.floor(Math.random()*countPieces()); | |
for (var i = 0; i < n; i++){ it.next(); } | |
return it.current(); | |
} | |
function stackRandPiece(){ | |
if (b.isBusy()) { return; } | |
if (b.isGameOver()) { clearInterval(randInterval); return; } | |
var p = getRandPiece(); | |
b.setTarget({x: p.pos.x + 100, y: 1500}); | |
b.grab(p); | |
window.setTimeout(function(){ | |
var val = p.value ; | |
if (val>17) val=17; | |
b.setTarget({x: (((val%7) + Math.floor(Math.random()*2) - Math.floor(Math.random()*2))*200)+100, y: 1500}); | |
window.setTimeout(function(){b.release();}, 15); | |
}, 15); | |
} | |
randInterval = window.setInterval(stackRandPiece, 40); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍