Put bullets into Array and made 4 spawn each wave
This commit is contained in:
40
web/game.js
40
web/game.js
@@ -17,8 +17,8 @@ let bossPosY = 100;
|
|||||||
let shotSpeed = 9;
|
let shotSpeed = 9;
|
||||||
let projectile;
|
let projectile;
|
||||||
let projSize = 5;
|
let projSize = 5;
|
||||||
let shot;
|
let shot = false;
|
||||||
let hit;
|
let hit = false;
|
||||||
let shotPosX;
|
let shotPosX;
|
||||||
let shotPosY;
|
let shotPosY;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ let bounceX = bossPosX;
|
|||||||
let bounceY = bossPosY;
|
let bounceY = bossPosY;
|
||||||
let predictiveBounceX;
|
let predictiveBounceX;
|
||||||
let predictiveBounceY;
|
let predictiveBounceY;
|
||||||
|
let bullets = [];
|
||||||
let direction;
|
let direction;
|
||||||
|
|
||||||
let time = 0;
|
let time = 0;
|
||||||
@@ -166,6 +166,24 @@ function draw() {
|
|||||||
text(time, 10, 20);
|
text(time, 10, 20);
|
||||||
|
|
||||||
if (shot == false || hit == true) {
|
if (shot == false || hit == true) {
|
||||||
|
spawnRandomBullet()
|
||||||
|
spawnRandomBullet()
|
||||||
|
spawnRandomBullet()
|
||||||
|
spawnRandomBullet()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bullets.forEach(myBullet => {
|
||||||
|
//zolang mybullet bestaat blijft hij drawen en updaten
|
||||||
|
({ hit, shot } = myBullet.update(playerPosX, playerPosY));
|
||||||
|
myBullet.draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function spawnRandomBullet(){
|
||||||
let patern = random([1,2]);
|
let patern = random([1,2]);
|
||||||
if (patern == 1) {
|
if (patern == 1) {
|
||||||
nextAttack = random([1, 2, 3, 4]);
|
nextAttack = random([1, 2, 3, 4]);
|
||||||
@@ -173,33 +191,29 @@ function draw() {
|
|||||||
if (nextAttack == 1) {
|
if (nextAttack == 1) {
|
||||||
shotPosX = 500;
|
shotPosX = 500;
|
||||||
shotPosY = 100;
|
shotPosY = 100;
|
||||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY);
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||||
}
|
}
|
||||||
if (nextAttack == 2) {
|
if (nextAttack == 2) {
|
||||||
shotPosX = random(0, 1000);
|
shotPosX = random(0, 1000);
|
||||||
shotPosY = 600;
|
shotPosY = 600;
|
||||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY);
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||||
}
|
}
|
||||||
if (nextAttack == 3) {
|
if (nextAttack == 3) {
|
||||||
shotPosX = 0;
|
shotPosX = 0;
|
||||||
shotPosY = random(0, 600);
|
shotPosY = random(0, 600);
|
||||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY);
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||||
}
|
}
|
||||||
if (nextAttack == 4) {
|
if (nextAttack == 4) {
|
||||||
shotPosX = 1000;
|
shotPosX = 1000;
|
||||||
shotPosY = random(0, 600);
|
shotPosY = random(0, 600);
|
||||||
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (patern == 2) {
|
if (patern == 2) {
|
||||||
shotPosX = bounceX;
|
shotPosX = bounceX;
|
||||||
shotPosY = bounceY;
|
shotPosY = bounceY;
|
||||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY);
|
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
if (myBullet) {
|
|
||||||
myBullet.draw();
|
|
||||||
({ hit, shot } = myBullet.update(playerPosX, playerPosY));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user