changing long if statements to arrays (start)

This commit is contained in:
Mees Roelofsz
2023-12-15 12:09:00 +01:00
parent 2775f8c299
commit 4916644d51

View File

@@ -60,11 +60,8 @@ let iIndex = 0;
let bulletAmount = 5; let bulletAmount = 5;
let phase1 = false; let phases = [false, false, false, false, false];
let phase2 = false;
let phase3 = false;
let phase4 = false;
let phase5 = false;
//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() {
@@ -269,7 +266,7 @@ async function randPatern() {
chosen = false; chosen = false;
} }
if (patern == 5) { if (patern == 5) {
if (phase1 == true) { if (phases[0] == true) {
nextWave = random([1, 2, 3, 4]); nextWave = random([1, 2, 3, 4]);
} }
await wait(3000); await wait(3000);
@@ -289,9 +286,9 @@ function randomAttackPattern() {
function phase() { function phase() {
switch (true) { switch (true) {
case (time < 20): case (time < 20):
phase1 = true; phases[0] = true;
paternArray = [5]; paternArray = [5];
shotSpeedAdj = 3; shotSpeedAdj = 2;
push(); push();
fill(255, 0, 255); fill(255, 0, 255);
textSize(10); textSize(10);
@@ -302,8 +299,8 @@ function phase() {
case (time < 60): case (time < 60):
shotSpeedAdj = 5; shotSpeedAdj = 5;
paternArray = [5]; paternArray = [5];
phase1 = false; phases[0] = false;
phase2 = true; phases[1] = true;
push(); push();
fill(255, 0, 255); fill(255, 0, 255);
textSize(10); textSize(10);
@@ -312,8 +309,8 @@ function phase() {
pop(); pop();
break; break;
case (time < 90): case (time < 90):
phase2 = false; phases[1] = false;
phase3 = true; phases[2] = true;
paternArray = [2]; paternArray = [2];
push(); push();
fill(255, 0, 255); fill(255, 0, 255);
@@ -323,8 +320,8 @@ function phase() {
pop(); pop();
break; break;
case (time < 120): case (time < 120):
phase3 = false; phases[2] = false;
phase4 = true; phases[3] = true;
paternArray = [3, 4]; paternArray = [3, 4];
push(); push();
fill(255, 0, 255); fill(255, 0, 255);
@@ -334,8 +331,8 @@ function phase() {
pop(); pop();
break; break;
case (time >= 120): case (time >= 120):
phase4 = false; phases[3] = false;
phase5 = false; phases[4] = false;
finalPhase = true; finalPhase = true;
paternArray = [1, 2, 3, 4, 5]; paternArray = [1, 2, 3, 4, 5];
push(); push();
@@ -428,7 +425,7 @@ function spawnRandomBullet() {
angle = 0; angle = 0;
} }
if (patern == 5) { if (patern == 5) {
if (phase1 == false) { if (phases[0] == false) {
nextWave = random([1, 2, 3, 4]); nextWave = random([1, 2, 3, 4]);
bulletAmount = 10; bulletAmount = 10;
} }