From 986e5343bf52f16ee212d2ef31f31b0be7fb1706 Mon Sep 17 00:00:00 2001 From: neingeist Date: Sun, 19 Aug 2012 18:00:47 +0200 Subject: [PATCH] not so fast --- herzle.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/herzle.js b/herzle.js index d06e948..9e3d92d 100644 --- a/herzle.js +++ b/herzle.js @@ -5,6 +5,7 @@ enemy_pos = [0.5 * window.innerWidth, 0.1 * window.innerHeight]; new_enemy_pos = [enemy_pos[0], enemy_pos[1]]; pewpew = 0; herzles = 0; +lastshoot = 0; document.onkeydown = onKeyDown; @@ -18,12 +19,15 @@ function onKeyDown(e) { player_pos[0] += 10; } if (e.keyCode == '32') { // space = fire - shoot(player_pos); + if ((new Date()).getTime() - lastshoot > 300) { + shoot(player_pos); + } } } shoots = []; function shoot(pos) { + lastshoot = (new Date()).getTime(); shoots[shoots.length] = [pos[0], pos[1], false]; // pewpew = 5; }