From a6554afe5f006a29418e2a5f812a7c0d6688a3ea Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Sun, 26 Nov 2023 16:24:29 +0100 Subject: [PATCH] added border and player collision to projectiles --- web/game.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/web/game.js b/web/game.js index c5f9ede..7af1100 100644 --- a/web/game.js +++ b/web/game.js @@ -109,15 +109,13 @@ function shoot(directionX, directionY) { // Move the projectile towards the movable circle projectile.add(p5.Vector.mult(direction, shotSpeed)); - if (dist(projectile.x, projectile.y, targetX, targetY) <= radius) { - if (playerPosX == targetX && playerPosY == targetY) { - projectile = null; - shot = false; - } - // if (projectile.x < 0 || projectile.x > width || projectile.y < 0 || projectile.y > height) { - // projectile = null; - // shot = false; - // } + if (dist(projectile.x, projectile.y, directionX, directionY) <= radius) { + projectile = null; + shot = false; + } + else if (projectile.x < 0 || projectile.x > width || projectile.y < 0 || projectile.y > height) { + projectile = null; + shot = false; } } @@ -138,6 +136,7 @@ function draw() { score(); text(time, 10, 20); + // square(squareX,squareY,squareSize); // object_collision();