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:
83
web/game.js
83
web/game.js
@@ -5,8 +5,8 @@ const height = 620;
|
|||||||
|
|
||||||
// Menu variables
|
// Menu variables
|
||||||
let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||||
let currentIndex = 0;
|
let currentIndex = [0, 0, 0];
|
||||||
let name = '';
|
let nameHS = '';
|
||||||
let pressed = false;
|
let pressed = false;
|
||||||
|
|
||||||
// Player variables
|
// Player variables
|
||||||
@@ -55,6 +55,7 @@ let homescreenOn = true;
|
|||||||
let chosen = false;
|
let chosen = false;
|
||||||
let finalPhase = false;
|
let finalPhase = false;
|
||||||
let nextWave = [];
|
let nextWave = [];
|
||||||
|
let iIndex = 0;
|
||||||
|
|
||||||
let bulletAmount = 5;
|
let bulletAmount = 5;
|
||||||
//let myBullet = new bullet();
|
//let myBullet = new bullet();
|
||||||
@@ -79,6 +80,7 @@ function score() {
|
|||||||
function gameOver() {
|
function gameOver() {
|
||||||
if (lives == 0) {
|
if (lives == 0) {
|
||||||
//game over screen
|
//game over screen
|
||||||
|
iIndex = constrain(iIndex, 0, 2);
|
||||||
isDead = true;
|
isDead = true;
|
||||||
push();
|
push();
|
||||||
fill(255, 0, 0);
|
fill(255, 0, 0);
|
||||||
@@ -89,7 +91,10 @@ function gameOver() {
|
|||||||
push();
|
push();
|
||||||
fill(255, 255, 255)
|
fill(255, 255, 255)
|
||||||
textSize(32);
|
textSize(32);
|
||||||
text(letters[currentIndex], width / 2, height / 2);
|
textAlign(CENTER);
|
||||||
|
text(letters[currentIndex[0]], width / 2 - 30, height / 2);
|
||||||
|
text(letters[currentIndex[1]], width / 2, height / 2);
|
||||||
|
text(letters[currentIndex[2]], width / 2 + 30, height / 2);
|
||||||
pop();
|
pop();
|
||||||
|
|
||||||
if (key == ' ') {
|
if (key == ' ') {
|
||||||
@@ -133,22 +138,35 @@ async function keyPressed() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isDead && keyReleasedFlag) {
|
if (isDead && keyReleasedFlag) {
|
||||||
|
if ((!(iIndex > 2)) || (!(iIndex < 0))) {
|
||||||
|
if (keyCode == LEFT_ARROW) {
|
||||||
|
iIndex -= 1;
|
||||||
|
keyReleasedFlag = false;
|
||||||
|
}
|
||||||
|
if (keyCode == RIGHT_ARROW) {
|
||||||
|
iIndex += 1;
|
||||||
|
keyReleasedFlag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (keyCode == UP_ARROW) {
|
if (keyCode == UP_ARROW) {
|
||||||
currentIndex = (currentIndex + 1) % letters.length;
|
currentIndex[iIndex] = (currentIndex[iIndex] + 1) % letters.length;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
if (keyCode == DOWN_ARROW) {
|
if (keyCode == DOWN_ARROW) {
|
||||||
currentIndex = (currentIndex - 1 + letters.length) % letters.length;
|
currentIndex[iIndex] = (currentIndex[iIndex] - 1 + letters.length) % letters.length;
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
if (keyCode == ENTER) {
|
if (keyCode == ENTER) {
|
||||||
name += letters[currentIndex];
|
nameHS += letters[currentIndex[0]];
|
||||||
console.log(name);
|
nameHS += letters[currentIndex[1]];
|
||||||
|
nameHS += letters[currentIndex[2]];
|
||||||
|
console.log(nameHS + ": " + int(time));
|
||||||
|
nameHS = '';
|
||||||
keyReleasedFlag = false;
|
keyReleasedFlag = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function keyReleased() {
|
function keyReleased() {
|
||||||
keyReleasedFlag = true; // Set the flag to true when a key is released
|
keyReleasedFlag = true; // Set the flag to true when a key is released
|
||||||
}
|
}
|
||||||
@@ -195,9 +213,35 @@ function draw() {
|
|||||||
if (homescreenOn == false) {
|
if (homescreenOn == false) {
|
||||||
game();
|
game();
|
||||||
}
|
}
|
||||||
// keyIsDown();
|
if (isDead == true) {
|
||||||
|
if (iIndex == 0) {
|
||||||
|
push()
|
||||||
|
stroke(205, 205, 205)
|
||||||
|
strokeWeight(2)
|
||||||
|
fill(0, 0, 0, 0)
|
||||||
|
rect(width / 2 - 45, height / 2 - 30, 30, 40)
|
||||||
|
pop()
|
||||||
|
}
|
||||||
|
if (iIndex == 1) {
|
||||||
|
push()
|
||||||
|
stroke(205, 205, 205)
|
||||||
|
strokeWeight(2)
|
||||||
|
fill(0, 0, 0, 0)
|
||||||
|
rect(width / 2 - 15, height / 2 - 30, 30, 40)
|
||||||
|
pop()
|
||||||
|
}
|
||||||
|
if (iIndex == 2) {
|
||||||
|
push()
|
||||||
|
stroke(205, 205, 205)
|
||||||
|
strokeWeight(2)
|
||||||
|
fill(0, 0, 0, 0)
|
||||||
|
rect(width / 2 + 15, height / 2 - 30, 30, 40)
|
||||||
|
pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keyIsDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
async function randPatern() {
|
async function randPatern() {
|
||||||
patern = random(paternArray);
|
patern = random(paternArray);
|
||||||
chosen = true;
|
chosen = true;
|
||||||
@@ -399,24 +443,7 @@ function spawnRandomBullet() {
|
|||||||
|
|
||||||
|
|
||||||
function homescreen() {
|
function homescreen() {
|
||||||
// push()
|
textAlign(CENTER);
|
||||||
// fill(0, 0, 0, 200)
|
|
||||||
// square(0, 0, 1600)
|
|
||||||
// pop()
|
|
||||||
|
|
||||||
// push()
|
|
||||||
// fill(255, 0, 0)
|
|
||||||
// let buttonHeight = height/2
|
|
||||||
// rect(width/2-90, buttonHeight, 200, 40 , 20, 20, 20, 20)
|
|
||||||
// textSize(25)
|
|
||||||
// fill(0,0,0)
|
|
||||||
// text("Start Game", width/2+10, buttonHeight+30)
|
|
||||||
// if (mouseX > width/2-90 && mouseX < width/2+110 && mouseY > height/2 && mouseY < buttonHeight+40) {
|
|
||||||
// if (mouseIsPressed) {
|
|
||||||
// homescreenOn = false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// 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")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user