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 lives = 2;
let bossPosX = 500;
let bossPosY = 100;
let shotSpeed = 9;
let projectile;
let projSize = 5;
@@ -22,6 +23,10 @@ let shotPosX;
let shotPosY;
let nextAttack;
let bounceX = bossPosX;
let bounceY = bossPosY;
let predictiveBounceX;
let predictiveBounceY;
let time = 0;
@@ -59,6 +64,8 @@ function life() {
if (key == ' ') {
lives = 2;
time = 0;
bounceX = bossPosX;
bounceY = bossPosY;
}
}
@@ -125,6 +132,8 @@ function shoot(directionX, directionY) {
hit = true;
}
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;
shot = false;
}
@@ -153,6 +162,8 @@ function draw() {
text(time, 10, 20);
if (shot == false || hit == true) {
let patern = random([1,2]);
if (patern == 1) {
nextAttack = random([1, 2, 3, 4]);
text(nextAttack, 30, 50);
if (nextAttack == 1) {
@@ -176,6 +187,12 @@ function draw() {
shoot(playerPosX, playerPosY);
}
}
if (patern == 2) {
shotPosX = bounceX;
shotPosY = bounceY;
shoot(playerPosX, playerPosY);
}
}
}
}