From b49694da69499d55954e98cd569ff334dc8274cb Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Fri, 8 Dec 2023 10:30:25 +0100 Subject: [PATCH 1/2] added phases --- web/game.js | 113 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 31 deletions(-) diff --git a/web/game.js b/web/game.js index 8898a98..8d5cfb5 100644 --- a/web/game.js +++ b/web/game.js @@ -34,6 +34,7 @@ let shotPoint = 0; let angle = 0; let patern; +let paternArray = []; let suroundX = 300; let suroundY = 300; let x2; @@ -47,7 +48,7 @@ let y5; let homescreenOn = true; let chosen = false; -let bulletAmount = 20; +let bulletAmount = 5; //let myBullet = new bullet(); // the function setup() is called once when the page is loaded function setup() { @@ -73,7 +74,7 @@ function life() { fill(255, 0, 0); textSize(40); textAlign(CENTER); - text("Game Over", width/2, height/2); + text("Game Over", width / 2, height / 2); pop(); if (key == ' ') { lives = 1; @@ -88,7 +89,7 @@ function life() { chosen = false; } } - + } function movementCheck() { @@ -144,6 +145,7 @@ async function Movementloop() { function draw() { keyPressed(); life(); + phase(); // draw background //myBullet.draw(); background(0, 0, 0, 100); @@ -156,8 +158,8 @@ function draw() { } } -async function randPatern () { - patern = random([5]); +async function randPatern() { + patern = random(paternArray); chosen = true; if (patern == 1) { await wait(3000); @@ -167,6 +169,14 @@ async function randPatern () { await wait(5000); chosen = false; } + if (patern == 3) { + await wait(1000); + chosen = false; + } + if (patern == 4) { + await wait(1000); + chosen = false; + } if (patern == 5) { await wait(30000); 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() { if (chosen == false) { randPatern(); @@ -243,8 +294,8 @@ function spawnRandomBullet() { angle = 0; // changing the angle of the bullets for (let i = 0; i < 86; i++) { - setTimeout(function() { - bullets.push(new bullet(0, 100, radius, shotSpeed/4, shotPosX, shotPosY, hasMoved, angle)); + setTimeout(function () { + bullets.push(new bullet(0, 100, radius, shotSpeed / 4, shotPosX, shotPosY, hasMoved, angle)); angle -= 360 / 1; }, i * 100); } @@ -256,46 +307,46 @@ function spawnRandomBullet() { angle = 0; // changing the angle of the bullets 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 = 0; } if (patern == 5) { - let nextAttack = random([1, 2, 3]); + let nextAttack = random([1, 2, 3, 4]); 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); shotPosX = shotWidth; 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) { - for (let i = 0; i < random(3, 10); i++) { + for (let i = 0; i < random(3, 15); i++) { let shotWidth = random(0, width); shotPosX = shotWidth; 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) { - for (let i = 0; i < random(3, 10); i++) { + for (let i = 0; i < random(3, 15); i++) { let shotHeight = random(0, width); shotPosX = 0; 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) { - for (let i = 0; i < random(3, 10); i++) { + if (nextAttack == 4) { + for (let i = 0; i < random(3, 15); i++) { let shotHeight = random(0, width); shotPosX = width; 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() - 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, 200, 40, "Start Game") + button(0, 0, 0, width / 2 - 90, height / 2 + 50, 200, 40, "Scores") push() - stroke(255,0,0) + stroke(255, 0, 0) strokeWeight(5) fill(0, 255, 0, 0) - rect(100, 150, 300, 400 , 20, 20, 20, 20) + rect(100, 150, 300, 400, 20, 20, 20, 20) pop() - -} + +} @@ -339,10 +390,10 @@ function button(r, g, b, buttonX, buttonY, buttonWidth, buttonHeight, buttonText fill(255, 0, 0) rect(buttonX, buttonY, buttonWidth, buttonHeight, 20, 20, 20, 20) textSize(25) - fill(r,g,b) - text(buttonText, buttonX+100, buttonY+30) + fill(r, g, b) + text(buttonText, buttonX + 100, buttonY + 30) 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) { homescreenOn = false; } @@ -350,7 +401,7 @@ function button(r, g, b, buttonX, buttonY, buttonWidth, buttonHeight, buttonText pop() } -function game(){ +function game() { if (!(lives == 0)) { // draw player push(); @@ -403,9 +454,9 @@ function game(){ circle(x3, y3, 50); circle(x4, y4, 50); circle(x5, y5, 50); - pop(); + pop(); + - } else { x2 = width / 2; y2 = 100; From 54f9932dd9ab59ea09032781100140d8f8b57456 Mon Sep 17 00:00:00 2001 From: Mees Roelofsz Date: Fri, 8 Dec 2023 10:40:23 +0100 Subject: [PATCH 2/2] changed times --- web/game.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/game.js b/web/game.js index 8d5cfb5..767b4c7 100644 --- a/web/game.js +++ b/web/game.js @@ -203,7 +203,7 @@ function phase() { text("phase 1", 10, 50); pop(); break; - case (time < 20): + case (time < 40): paternArray = [2, 5] push(); fill(255, 0, 255); @@ -212,7 +212,7 @@ function phase() { text("phase 2", 10, 50); pop(); break; - case (time < 30): + case (time < 60): paternArray = [3, 4] push(); fill(255, 0, 255); @@ -221,7 +221,7 @@ function phase() { text("phase 3", 10, 50); pop(); break; - case (time > 30): + case (time > 6): paternArray = [1, 2, 3, 4, 5] push(); fill(255, 0, 255);