From f8fa2747c7098ba2aa4893fa89a2d193ab6fc04c Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Sat, 25 Nov 2023 18:59:29 +0100 Subject: [PATCH] bullets now respawn (bit jittery) --- web/game.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/web/game.js b/web/game.js index fb954b4..9f57890 100644 --- a/web/game.js +++ b/web/game.js @@ -83,10 +83,10 @@ let playerSpeed = 3; // let squareY = 100; // const squareSize = 100; -let shotSpeed = 2; +let shotSpeed = 5; let projectile; let projSize = 5; -let shot = false; +let shot; // the function setup() is called once when the page is loaded function setup() { @@ -142,7 +142,7 @@ async function Movementloop() { function shoot(directionX, directionY) { shot = true; - + if (!projectile) { // Set the initial position of the projectile to the player's position projectile = createVector(500, 100); @@ -159,9 +159,9 @@ function shoot(directionX, directionY) { direction.mult(shotSpeed); projectile.add(direction); - if (projectile.dist(target) >= 1) { + if (projectile.dist(target) <= radius) { shot = false; - // projectile = null; + projectile = null; } } @@ -184,5 +184,8 @@ function draw() { if (shot == false) { shoot(playerPosX, playerPosY); + } else { + shot = false; } + } \ No newline at end of file