projectile dissapears after hit (doesn't return)

This commit is contained in:
Mees Roelofsz
2023-11-25 17:41:25 +01:00
parent 844a82057b
commit 3352ed4dc5

View File

@@ -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);
}
}