diff --git a/web/game.js b/web/game.js index 2319e91..af85fd5 100644 --- a/web/game.js +++ b/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,40 +166,54 @@ function draw() { text(time, 10, 20); if (shot == false || hit == true) { - let patern = random([1,2]); + 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]); text(nextAttack, 30, 50); 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)); - } - } -} +} \ No newline at end of file