added bouncing bullets

This commit is contained in:
Mees Roelofsz
2023-11-27 21:03:18 +01:00
parent aebc811f29
commit a6d4a75e15

View File

@@ -12,7 +12,8 @@ let playerSpeed = 3;
let booleanArray = window.booleanArray; let booleanArray = window.booleanArray;
let lives = 2; let lives = 2;
let bossPosX = 500;
let bossPosY = 100;
let shotSpeed = 9; let shotSpeed = 9;
let projectile; let projectile;
let projSize = 5; let projSize = 5;
@@ -22,6 +23,10 @@ let shotPosX;
let shotPosY; let shotPosY;
let nextAttack; let nextAttack;
let bounceX = bossPosX;
let bounceY = bossPosY;
let predictiveBounceX;
let predictiveBounceY;
let time = 0; let time = 0;
@@ -59,6 +64,8 @@ function life() {
if (key == ' ') { if (key == ' ') {
lives = 2; lives = 2;
time = 0; time = 0;
bounceX = bossPosX;
bounceY = bossPosY;
} }
} }
@@ -124,7 +131,9 @@ function shoot(directionX, directionY) {
projectile = null; projectile = null;
hit = true; hit = true;
} }
else if (projectile.x < 0-10 || projectile.x > width+10 || projectile.y < 0-10 || projectile.y > height+10) { else if (projectile.x < 0 - 10 || projectile.x > width + 10 || projectile.y < 0 - 10 || projectile.y > height + 10) {
bounceX = projectile.x;
bounceY = projectile.y;
projectile = null; projectile = null;
shot = false; shot = false;
} }
@@ -153,29 +162,37 @@ function draw() {
text(time, 10, 20); text(time, 10, 20);
if (shot == false || hit == true) { if (shot == false || hit == true) {
nextAttack = random([1,2,3,4]); let patern = random([1,2]);
text(nextAttack, 30, 50); if (patern == 1) {
if (nextAttack == 1) { nextAttack = random([1, 2, 3, 4]);
shotPosX = 500; text(nextAttack, 30, 50);
shotPosY = 100; if (nextAttack == 1) {
shotPosX = 500;
shotPosY = 100;
shoot(playerPosX, playerPosY);
}
if (nextAttack == 2) {
shotPosX = random(0, 1000);
shotPosY = 600;
shoot(playerPosX, playerPosY);
}
if (nextAttack == 3) {
shotPosX = 0;
shotPosY = random(0, 600);
shoot(playerPosX, playerPosY);
}
if (nextAttack == 4) {
shotPosX = 1000;
shotPosY = random(0, 600);
shoot(playerPosX, playerPosY);
}
}
if (patern == 2) {
shotPosX = bounceX;
shotPosY = bounceY;
shoot(playerPosX, playerPosY); shoot(playerPosX, playerPosY);
} }
if (nextAttack == 2) {
shotPosX = random(0, 1000);
shotPosY = 600;
shoot(playerPosX, playerPosY);
}
if (nextAttack == 3) {
shotPosX = 0;
shotPosY = random(0, 600);
shoot(playerPosX, playerPosY);
}
if (nextAttack == 4) {
shotPosX = 1000;
shotPosY = random(0, 600);
shoot(playerPosX, playerPosY);
}
}
}
} }
}
}