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

View File

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