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 projectile;
|
||||
let projSize = 5;
|
||||
let shot;
|
||||
let hit;
|
||||
let shot = false;
|
||||
let hit = false;
|
||||
let shotPosX;
|
||||
let shotPosY;
|
||||
|
||||
@@ -27,7 +27,7 @@ let bounceX = bossPosX;
|
||||
let bounceY = bossPosY;
|
||||
let predictiveBounceX;
|
||||
let predictiveBounceY;
|
||||
|
||||
let bullets = [];
|
||||
let direction;
|
||||
|
||||
let time = 0;
|
||||
@@ -166,6 +166,24 @@ function draw() {
|
||||
text(time, 10, 20);
|
||||
|
||||
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]);
|
||||
if (patern == 1) {
|
||||
nextAttack = random([1, 2, 3, 4]);
|
||||
@@ -173,33 +191,29 @@ function draw() {
|
||||
if (nextAttack == 1) {
|
||||
shotPosX = 500;
|
||||
shotPosY = 100;
|
||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY);
|
||||
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||
}
|
||||
if (nextAttack == 2) {
|
||||
shotPosX = random(0, 1000);
|
||||
shotPosY = 600;
|
||||
myBullet = new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY);
|
||||
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||
}
|
||||
if (nextAttack == 3) {
|
||||
shotPosX = 0;
|
||||
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) {
|
||||
shotPosX = 1000;
|
||||
shotPosY = random(0, 600);
|
||||
bullets.push(new bullet(playerPosX, playerPosY, radius, shotSpeed, shotPosX, shotPosY));
|
||||
|
||||
}
|
||||
}
|
||||
if (patern == 2) {
|
||||
shotPosX = bounceX;
|
||||
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