From 3352ed4dc5199c69b15b611ba58e356b6a2febbf Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Sat, 25 Nov 2023 17:41:25 +0100 Subject: [PATCH] projectile dissapears after hit (doesn't return) --- web/game.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web/game.js b/web/game.js index 0e1c0ac..fb954b4 100644 --- a/web/game.js +++ b/web/game.js @@ -142,7 +142,6 @@ async function Movementloop() { function shoot(directionX, directionY) { shot = true; - circle(500, 100, 50); if (!projectile) { // Set the initial position of the projectile to the player's position @@ -159,16 +158,31 @@ function shoot(directionX, directionY) { direction.normalize(); direction.mult(shotSpeed); projectile.add(direction); + + if (projectile.dist(target) >= 1) { + shot = false; + // projectile = null; + } } // the function draw() is called every frame function draw() { keyPressed(); + // draw background background(0, 0, 0, 100); + // draw player + fill(0, 255, 255) circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize); + + // draw boss + fill(255,165,0) + circle(500, 100, 50); + // square(squareX,squareY,squareSize); // object_collision(); - - shoot(playerPosX, playerPosY); + + if (shot == false) { + shoot(playerPosX, playerPosY); + } } \ No newline at end of file