Skip to content

Instantly share code, notes, and snippets.

@henrysher
Forked from CodyWalker/TwentyBot
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrysher/27c707a507d44ca84344 to your computer and use it in GitHub Desktop.
Save henrysher/27c707a507d44ca84344 to your computer and use it in GitHub Desktop.
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(){
b.setTarget({x: (Math.floor(Math.random()*7)*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