added phases

This commit is contained in:
Mees Roelofsz
2023-12-08 10:30:25 +01:00
parent adfee64d1a
commit b49694da69

View File

@@ -34,6 +34,7 @@ let shotPoint = 0;
let angle = 0; let angle = 0;
let patern; let patern;
let paternArray = [];
let suroundX = 300; let suroundX = 300;
let suroundY = 300; let suroundY = 300;
let x2; let x2;
@@ -47,7 +48,7 @@ let y5;
let homescreenOn = true; let homescreenOn = true;
let chosen = false; let chosen = false;
let bulletAmount = 20; let bulletAmount = 5;
//let myBullet = new bullet(); //let myBullet = new bullet();
// the function setup() is called once when the page is loaded // the function setup() is called once when the page is loaded
function setup() { function setup() {
@@ -73,7 +74,7 @@ function life() {
fill(255, 0, 0); fill(255, 0, 0);
textSize(40); textSize(40);
textAlign(CENTER); textAlign(CENTER);
text("Game Over", width/2, height/2); text("Game Over", width / 2, height / 2);
pop(); pop();
if (key == ' ') { if (key == ' ') {
lives = 1; lives = 1;
@@ -88,7 +89,7 @@ function life() {
chosen = false; chosen = false;
} }
} }
} }
function movementCheck() { function movementCheck() {
@@ -144,6 +145,7 @@ async function Movementloop() {
function draw() { function draw() {
keyPressed(); keyPressed();
life(); life();
phase();
// draw background // draw background
//myBullet.draw(); //myBullet.draw();
background(0, 0, 0, 100); background(0, 0, 0, 100);
@@ -156,8 +158,8 @@ function draw() {
} }
} }
async function randPatern () { async function randPatern() {
patern = random([5]); patern = random(paternArray);
chosen = true; chosen = true;
if (patern == 1) { if (patern == 1) {
await wait(3000); await wait(3000);
@@ -167,6 +169,14 @@ async function randPatern () {
await wait(5000); await wait(5000);
chosen = false; chosen = false;
} }
if (patern == 3) {
await wait(1000);
chosen = false;
}
if (patern == 4) {
await wait(1000);
chosen = false;
}
if (patern == 5) { if (patern == 5) {
await wait(30000); await wait(30000);
chosen = false; chosen = false;
@@ -182,6 +192,47 @@ function randomAttackPattern() {
} }
} }
function phase() {
switch (true) {
case (time < 10):
paternArray = [1]
push();
fill(255, 0, 255);
textSize(10);
textAlign(LEFT);
text("phase 1", 10, 50);
pop();
break;
case (time < 20):
paternArray = [2, 5]
push();
fill(255, 0, 255);
textSize(10);
textAlign(LEFT);
text("phase 2", 10, 50);
pop();
break;
case (time < 30):
paternArray = [3, 4]
push();
fill(255, 0, 255);
textSize(10);
textAlign(LEFT);
text("phase 3", 10, 50);
pop();
break;
case (time > 30):
paternArray = [1, 2, 3, 4, 5]
push();
fill(255, 0, 255);
textSize(10);
textAlign(LEFT);
text("phase 4", 10, 50);
pop();
break;
}
}
function spawnRandomBullet() { function spawnRandomBullet() {
if (chosen == false) { if (chosen == false) {
randPatern(); randPatern();
@@ -243,8 +294,8 @@ function spawnRandomBullet() {
angle = 0; angle = 0;
// changing the angle of the bullets // changing the angle of the bullets
for (let i = 0; i < 86; i++) { for (let i = 0; i < 86; i++) {
setTimeout(function() { setTimeout(function () {
bullets.push(new bullet(0, 100, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); bullets.push(new bullet(0, 100, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle));
angle -= 360 / 1; angle -= 360 / 1;
}, i * 100); }, i * 100);
} }
@@ -256,46 +307,46 @@ function spawnRandomBullet() {
angle = 0; angle = 0;
// changing the angle of the bullets // changing the angle of the bullets
for (let i = 0; i < 86; i++) { for (let i = 0; i < 86; i++) {
bullets.push(new bullet(0, 100, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); bullets.push(new bullet(0, 100, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle));
angle -= 360 / 3; angle -= 360 / 3;
} }
angle = 0; angle = 0;
} }
if (patern == 5) { if (patern == 5) {
let nextAttack = random([1, 2, 3]); let nextAttack = random([1, 2, 3, 4]);
if (nextAttack == 1) { if (nextAttack == 1) {
for (let i = 0; i < random(3, 10); i++) { for (let i = 0; i < random(3, 15); i++) {
let shotWidth = random(0, width); let shotWidth = random(0, width);
shotPosX = shotWidth; shotPosX = shotWidth;
shotPosY = height; shotPosY = height;
bullets.push(new bullet(shotWidth, 0, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); bullets.push(new bullet(shotWidth, 0, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle));
} }
} }
if (nextAttack == 2) { if (nextAttack == 2) {
for (let i = 0; i < random(3, 10); i++) { for (let i = 0; i < random(3, 15); i++) {
let shotWidth = random(0, width); let shotWidth = random(0, width);
shotPosX = shotWidth; shotPosX = shotWidth;
shotPosY = 0; shotPosY = 0;
bullets.push(new bullet(shotWidth, height, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); bullets.push(new bullet(shotWidth, height, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle));
} }
} }
if (nextAttack == 3) { if (nextAttack == 3) {
for (let i = 0; i < random(3, 10); i++) { for (let i = 0; i < random(3, 15); i++) {
let shotHeight = random(0, width); let shotHeight = random(0, width);
shotPosX = 0; shotPosX = 0;
shotPosY = shotHeight; shotPosY = shotHeight;
bullets.push(new bullet(width, shotHeight, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); bullets.push(new bullet(width, shotHeight, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle));
} }
} }
if (nextAttack == 3) { if (nextAttack == 4) {
for (let i = 0; i < random(3, 10); i++) { for (let i = 0; i < random(3, 15); i++) {
let shotHeight = random(0, width); let shotHeight = random(0, width);
shotPosX = width; shotPosX = width;
shotPosY = shotHeight; shotPosY = shotHeight;
bullets.push(new bullet(0, shotHeight, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); bullets.push(new bullet(0, shotHeight, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle));
} }
} }
} }
} }
@@ -319,18 +370,18 @@ function homescreen() {
// } // }
// } // }
// pop() // pop()
button(0,0,0 ,width/2-90, height/2, 200, 40, "Start Game") button(0, 0, 0, width / 2 - 90, height / 2, 200, 40, "Start Game")
button(0,0,0 ,width/2-90, height/2+50, 200, 40, "Scores") button(0, 0, 0, width / 2 - 90, height / 2 + 50, 200, 40, "Scores")
push() push()
stroke(255,0,0) stroke(255, 0, 0)
strokeWeight(5) strokeWeight(5)
fill(0, 255, 0, 0) fill(0, 255, 0, 0)
rect(100, 150, 300, 400 , 20, 20, 20, 20) rect(100, 150, 300, 400, 20, 20, 20, 20)
pop() pop()
}
}
@@ -339,10 +390,10 @@ function button(r, g, b, buttonX, buttonY, buttonWidth, buttonHeight, buttonText
fill(255, 0, 0) fill(255, 0, 0)
rect(buttonX, buttonY, buttonWidth, buttonHeight, 20, 20, 20, 20) rect(buttonX, buttonY, buttonWidth, buttonHeight, 20, 20, 20, 20)
textSize(25) textSize(25)
fill(r,g,b) fill(r, g, b)
text(buttonText, buttonX+100, buttonY+30) text(buttonText, buttonX + 100, buttonY + 30)
textAlign(CENTER); textAlign(CENTER);
if (mouseX > buttonX-90 && mouseX < width/2+110 && mouseY > height/2 && mouseY < buttonY+40) { if (mouseX > buttonX - 90 && mouseX < width / 2 + 110 && mouseY > height / 2 && mouseY < buttonY + 40) {
if (mouseIsPressed) { if (mouseIsPressed) {
homescreenOn = false; homescreenOn = false;
} }
@@ -350,7 +401,7 @@ function button(r, g, b, buttonX, buttonY, buttonWidth, buttonHeight, buttonText
pop() pop()
} }
function game(){ function game() {
if (!(lives == 0)) { if (!(lives == 0)) {
// draw player // draw player
push(); push();
@@ -403,9 +454,9 @@ function game(){
circle(x3, y3, 50); circle(x3, y3, 50);
circle(x4, y4, 50); circle(x4, y4, 50);
circle(x5, y5, 50); circle(x5, y5, 50);
pop(); pop();
} else { } else {
x2 = width / 2; x2 = width / 2;
y2 = 100; y2 = 100;