Back to front pageView on Hacker News (opens in a new tab)Show HN: I taught my little brother JS, and he made this videogame in a week (opens in a new tab)s-poony.github.io1079 pointsby lovasoa (on Hacker News)7 years agos-poony.github.io (opens in a new tab)Ultra Square CatcherComments (270) 108 threadsShow all commentsShowing thread 30 of 108[-]krozgen7 years ago2 replies#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);lmitchell7 years ago#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.[-]wrayjustin7 years ago2 replies#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[-]krozgen7 years ago1 reply#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"[-]wrayjustin7 years ago1 reply#LOL yeah, it's like watching a sport. By about a score of 300 the enemy is just too fast for our hero. =/toabi7 years ago#Interesting, I just watched it and for me the limit is around ~130.toabi7 years ago#Lower the timeout from 25 to 5 and it's like Neo fighting agent smith :D
Show HN: I taught my little brother JS, and he made this videogame in a week (opens in a new tab)s-poony.github.io1079 pointsby lovasoa (on Hacker News)7 years ago
krozgen7 years ago2 replies#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);
lmitchell7 years ago#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.
wrayjustin7 years ago2 replies#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
krozgen7 years ago1 reply#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"
wrayjustin7 years ago1 reply#LOL yeah, it's like watching a sport. By about a score of 300 the enemy is just too fast for our hero. =/
Comments (270) 108 threads
Show all comments
Showing thread 30 of 108
I think I need to get more fresh air or something.
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