-
-
Save inDream/c4c1eb78faf2742c5e58 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 getPieces() { | |
var arr = []; | |
it = b.pieces(); | |
while (it.current()){ arr.push(it.current()); it.next() } | |
return arr; | |
} | |
var needCalcPos = true; | |
var arr = []; | |
var current = 0; | |
function getMoveFactor() { | |
if (arr.length > 15 || b.score > 10) { | |
return 3; | |
} else { | |
return 2; | |
} | |
} | |
function stackRandPiece(){ | |
if (b.isBusy()) { return; } | |
if (b.isGameOver()) { clearInterval(randInterval); return; } | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i].value != arr[i].old) { | |
needCalcPos = true; | |
break; | |
} | |
}; | |
if (needCalcPos) { | |
arr = getPieces(); | |
arr = arr.sort(function(a, b){ | |
a.old = a.value; | |
b.old = b.value; | |
return a.value > b.value; | |
}); | |
needCalcPos = false; | |
} | |
if (current > arr.length - 1){ | |
current = 0; | |
} | |
var p = arr[current]; | |
if (!p || p.value > 20) { | |
current++; | |
return; | |
} | |
b.setTarget({x: p.pos.x + 100, y: 1500}); | |
b.grab(p); | |
window.setTimeout(function(){ | |
var val = p.value; | |
b.setTarget({x: ((Math.floor((val/20)*7) + Math.floor(Math.random()*getMoveFactor()))*200), y: 1500}); | |
window.setTimeout(function(){b.release();}, 15); | |
}, 15); | |
current++; | |
} | |
randInterval = window.setInterval(stackRandPiece, 40); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Best score:
