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
projectile.add(p5.Vector.mult(direction, shotSpeed));
if (dist(projectile.x, projectile.y, targetX, targetY) <= radius) {
if (playerPosX == targetX && playerPosY == targetY) {
if (dist(projectile.x, projectile.y, directionX, directionY) <= radius) {
projectile = null;
shot = false;
}
// if (projectile.x < 0 || projectile.x > width || projectile.y < 0 || projectile.y > height) {
// 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();