From ce109aaebf474a2bf821d855d95516da80b862ad Mon Sep 17 00:00:00 2001 From: Thunraz Date: Sat, 13 Sep 2014 02:39:36 +0200 Subject: [PATCH] Distributing enemies more evenly (not just spawning them at the corners) --- lib/main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7f296a7..759a153 100644 --- a/lib/main.js +++ b/lib/main.js @@ -33,8 +33,8 @@ loop.start(function frame(deltaT) { if(player.health <= 0) { if(controls.states.shoot && gameOverTimer <= 0) { - resetGame(); - } + resetGame(); + } gameOverTimer -= deltaT; } @@ -53,8 +53,10 @@ loop.start(function frame(deltaT) { function placeRandomEnemy() { if(player.health > 0) { - var x = player.x + Math.sign(Math.random() - 0.5) * 100; - var y = player.y + Math.sign(Math.random() - 0.5) * 100; + var rad = Math.random() * 2 * Math.PI; + + var x = player.x + 100 * Math.cos(rad); + var y = player.y + 100 * Math.sin(rad); entities.push(new Enemy(x, y)); }