Hacker News new | past | comments | ask | show | jobs | submit login

Snowcrash mode :) (In console): setInterval(function() { hero.x = powerUp.x; hero.y = powerUp.y; }, 50); setInterval(function() { hero.x = reward.x; hero.y = reward.y; }, 100);



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


I 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"


LOL yeah, it's like watching a sport. By about a score of 300 the enemy is just too fast for our hero. =/


Interesting, I just watched it and for me the limit is around ~130.


Lower the timeout from 25 to 5 and it's like Neo fighting agent smith :D


I... definitely did not just watch this play itself for like five straight minutes...

I think I need to get more fresh air or something.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: