Merge branch 'main' of https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-2/cuujooceevii61
This commit is contained in:
101
web/game.js
101
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;
|
||||
@@ -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 < 40):
|
||||
paternArray = [2, 5]
|
||||
push();
|
||||
fill(255, 0, 255);
|
||||
textSize(10);
|
||||
textAlign(LEFT);
|
||||
text("phase 2", 10, 50);
|
||||
pop();
|
||||
break;
|
||||
case (time < 60):
|
||||
paternArray = [3, 4]
|
||||
push();
|
||||
fill(255, 0, 255);
|
||||
textSize(10);
|
||||
textAlign(LEFT);
|
||||
text("phase 3", 10, 50);
|
||||
pop();
|
||||
break;
|
||||
case (time > 6):
|
||||
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,43 +307,43 @@ 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,14 +370,14 @@ 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();
|
||||
|
Reference in New Issue
Block a user