4 ms·
I did the same, but played around a bit more and made an "AI" mode: maxScore = 0; setInterval( function() { if (score > maxScore) { maxScore = score
by wrayjustin 8y ago
I did the same, but played around a bit more and made an "AI" mode:
maxScore = 0;
setInterval( function() {
if (score > maxScore) {
maxScore = score;
}
if (distance(hero.y, hero.x, ennemi.y, ennemi.x) < (vitesseEnnemi * 15 + 30)) {
hero.y += (hero.y - ennemi.y) * speedLimit / distance(hero.y, hero.x, ennemi.y, ennemi.x);
hero.x += (hero.x - ennemi.x) * speedLimit / distance(hero.y, hero.x, ennemi.y, ennemi.x);
}
if (spawn > PowerUpspawnRate) {
hero.y += (powerUp.y - hero.y) * speedLimit / distance(hero.y, hero.x, powerUp.y, powerUp.x);
hero.x += (powerUp.x - hero.x) * speedLimit/ distance(hero.y, hero.x, powerUp.y, powerUp.x);
} else {
hero.y += (reward.y - hero.y) * speedLimit / distance(hero.y, hero.x, reward.y, reward.x);
hero.x += (reward.x - hero.x) * speedLimit/ distance(hero.y, hero.x, reward.y, reward.x);
}
}, 25);
It's oddly fun to watch the little green guy pull off some sick dekes.
If you want your green guy to flat-out avoid the enemy, just wrap the second set of conditions there in an else block.
edit: Formatting for readability/copy+paste
- krozgen 8y agoI love when the red square comes close and the green one jukes in a tight spiral around it, just thinking "Whoa nope nope NOPE ah it's okay"
- wrayjustin 8y agoLOL yeah, it's like watching a sport. By about a score of 300 the enemy is just too fast for our hero. =/
- toabi 8y agoInteresting, I just watched it and for me the limit is around ~130.
- toabi 8y agoLower the timeout from 25 to 5 and it's like Neo fighting agent smith :D