i keep gettin infinite loop in level stranded in the dunes
function moveTo(position) {
if (hero.isReady("jump")) {
hero.jumpTo(position);
}
else {
hero.moveXY(position.pos.x, position.pos.y);
}
}
function atk(enemy) {
if (enemy && enemy.type != "sand-yak") {
if (hero.canCast("chain-lightning", enemy)) {
hero.cast("chain-lightning", enemy);
}
else if (hero.distanceTo(enemy) < 10) {
moveTo(enemy);
}
else if (hero.isReady("bash")){
hero.bash(enemy);
}
else {
hero.attack(enemy);
hero.shield();
}
}
}
hero.moveXY(120,39);
while(hero.time < 100) {
var enemy = hero.findNearestEnemy();
if (enemy) {
atk(enemy);
}
else {
hero.moveXY(120, 39);
}
}
while(true) {
var enemy = hero.findNearestEnemy();
var item = hero.findNearestItem();
if (item) {
moveTo(item);
}
else if(enemy) {
atk(enemy);
}
else {
hero.move({'x':60, 'y':35});
}
}