From 2b83a023eb5c8be0ca2aaa47d9e028119b69a8de Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 19 Aug 2012 18:32:49 +0200 Subject: [PATCH] don't avoid corners when avoiding shoots --- herzle.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/herzle.js b/herzle.js index 82ee0bf..9f4d267 100644 --- a/herzle.js +++ b/herzle.js @@ -170,20 +170,24 @@ function animate() { new_enemy_pos[1] += off; } // avoid shoots + var avoiding_shoots = false; for(var i = 0; i < shoots.length; i++) { if (shoots[i]) { if (dist(enemy_pos, shoots[i]) < 100) { + avoiding_shoots = true; new_enemy_pos[0] = lerp(-0.50, enemy_pos[0], shoots[i][0]); new_enemy_pos[1] = lerp(-0.35, enemy_pos[1], shoots[i][1]); } } } // avoid corners - if (new_enemy_pos[0] < 0.05 * window.innerWidth || new_enemy_pos[0] > 0.95 * window.innerWidth) { - new_enemy_pos[0] = lerp(0.2, enemy_pos[0], 0.5 * window.innerWidth); - } - if (new_enemy_pos[1] < 0.05 * window.innerHeight || new_enemy_pos[1] > 0.95 * window.innerHeight) { - new_enemy_pos[1] = lerp(0.2, enemy_pos[1], 0.25 * window.innerHeight); + if (!avoiding_shoots) { + if (new_enemy_pos[0] < 0.1 * window.innerWidth || new_enemy_pos[0] > 0.9 * window.innerWidth) { + new_enemy_pos[0] = lerp(0.2, enemy_pos[0], 0.5 * window.innerWidth); + } + if (new_enemy_pos[1] < 0.1 * window.innerHeight || new_enemy_pos[1] > 0.5 * window.innerHeight) { + new_enemy_pos[1] = lerp(0.2, enemy_pos[1], 0.25 * window.innerHeight); + } } // stay inside!