added border and player collision to projectiles

This commit is contained in:
Mees Roelofsz
2023-11-26 16:24:29 +01:00
parent e4354f78f0
commit a6554afe5f

View File

@@ -109,15 +109,13 @@ function shoot(directionX, directionY) {
// Move the projectile towards the movable circle // Move the projectile towards the movable circle
projectile.add(p5.Vector.mult(direction, shotSpeed)); projectile.add(p5.Vector.mult(direction, shotSpeed));
if (dist(projectile.x, projectile.y, targetX, targetY) <= radius) { if (dist(projectile.x, projectile.y, directionX, directionY) <= radius) {
if (playerPosX == targetX && playerPosY == targetY) { projectile = null;
projectile = null; shot = false;
shot = false; }
} else if (projectile.x < 0 || projectile.x > width || projectile.y < 0 || projectile.y > height) {
// if (projectile.x < 0 || projectile.x > width || projectile.y < 0 || projectile.y > height) { projectile = null;
// projectile = null; shot = false;
// shot = false;
// }
} }
} }
@@ -138,6 +136,7 @@ function draw() {
score(); score();
text(time, 10, 20); text(time, 10, 20);
// square(squareX,squareY,squareSize); // square(squareX,squareY,squareSize);
// object_collision(); // object_collision();