sam
2024-01-17 15:39:51 +01:00
2 changed files with 36 additions and 25 deletions

View File

@@ -625,27 +625,31 @@ function spawnRandomBullet() {
bulletAmount = 5;
}
}
// function bouncing() {
// // Update position
// bossPosX += bossVelX;
// bossPosY += bossVelY;
// // Check for bounce
// if (bossPosX > width - 25) {
// bossVelX = random([-4,-5,-6])
// }
// if (bossPosX < 25) {
// bossVelX = random([4,5,6])
// }
// if (bossPosY > height - 25) {
// bossVelY = random([-4,-5,-6])
// }
// if (bossPosY < 25) {
// bossVelY = random([4,5,6])
// }
function bouncing() {
// Update position
bossPosX += bossVelX;
bossPosY += bossVelY;
// Check for bounce
if (bossPosX > width - 25) {
bossVelX = random([-4,-5,-6]);
}
if (bossPosX < 25) {
bossVelX = random([4,5,6]);
}
if (bossPosY > height - 25) {
bossVelY = random([-4,-5,-6]);
}
if (bossPosY < 25) {
bossVelY = random([4,5,6]);
}
// // Draw the boss
// circle(bossPosX, bossPosY, 50);
// }
// Draw the boss
circle(bossPosX, bossPosY, 50);
if (dist(bossPosX, bossPosY, playerPosX, playerPosY) <= 25 + radius) {
lives -= 1;
}
}
function game() {
if (!(lives == 0)) {
@@ -656,7 +660,15 @@ function game() {
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
pop();
movementCheck();
//bouncing();
if (phases[2] == false || phase[3] == false) {
bouncing();
} else if (phases[2] = true) {
bossPosX = x2;
bossPosY = y2;
} else{
bossPosX = width / 2;
bossPosY = height / 6;
}
push();
fill(255, 165, 0)
@@ -714,7 +726,7 @@ function game() {
if (!pausescreenOn) {
bullets.forEach(myBullet => {
//zolang mybullet bestaat blijft hij drawen en updaten
({ hit, shot, isOffScreen, originalPos } = myBullet.update(playerPosX, playerPosY));
({ hit, shot, isOffScreen, originalPos } = myBullet.update(playerPosX, playerPosY, hasMoved));
myBullet.draw();
if (isOffScreen == true) {

View File

@@ -11,7 +11,6 @@ class bullet {
this.bulletHit = false;
this.directionX = null;
this.directionY = null;
this.hasMoved = hasMoved;
// Set a variable that cant be changed
if ((this.directionX === null) || (this.directionY === null)) {
this.directionX = this.targetx;
@@ -33,7 +32,7 @@ class bullet {
pop();
}
update(targetx, targety) {
update(targetx, targety, hasMoved) {
// keeps the projetile updated so hit collision can be checked
this.targetx = targetx;
this.targety = targety;
@@ -48,7 +47,7 @@ class bullet {
hit = true;
shot = false;
// if the projectile has hit the player and the player has lives left, remove a life
if (this.hasMoved && lives != 0 && this.bulletHit == false) {
if (hasMoved && lives != 0 && this.bulletHit == false) {
this.bulletHit = true;
lives -= 1;
}