sam
2024-01-16 15:55:19 +01:00
3 changed files with 128 additions and 106 deletions

View File

@@ -3,8 +3,8 @@
const width = 1260; const width = 1260;
const height = 620; const height = 620;
let requesteddata = []; let requesteddata = [];
let buttonWidth = width/ 6 let buttonWidth = width / 6
let buttonHeight = buttonWidth/5 let buttonHeight = buttonWidth / 5
// Menu variables // Menu variables
let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let currentIndex = [0, 0, 0]; let currentIndex = [0, 0, 0];
@@ -81,11 +81,9 @@ function setup() {
// disable the outline of shapes // disable the outline of shapes
noStroke(); noStroke();
} }
function score() { function score() {
time += 3 / framerate; time += 3 / framerate;
} }
function reset() { function reset() {
lives = 1; lives = 1;
time = 0; time = 0;
@@ -106,7 +104,6 @@ function reset() {
submitted = false; submitted = false;
escaped = false; escaped = false;
} }
function gameOver() { function gameOver() {
if (lives == 0) { if (lives == 0) {
//game over screen //game over screen
@@ -116,32 +113,31 @@ function gameOver() {
fill(255, 0, 0); fill(255, 0, 0);
textSize(40); textSize(40);
textAlign(CENTER); textAlign(CENTER);
text("Game Over", width / 2, height / 2 - 80); text("Game Over", width / 2, height / 2 - height/6);
fill(255, 255, 255) fill(255, 255, 255)
textSize(18); textSize(18);
textAlign(CENTER); textAlign(CENTER);
text("Score: " + int(time), width / 2, height / 2 - 55); text("Score: " + int(time), width / 2, height / 2 - height/8);
textSize(32); textSize(32);
textAlign(CENTER, CENTER);
text(letters[currentIndex[0]], width / 2 - 30, height / 2); text(letters[currentIndex[0]], width / 2 - 30, height / 2);
text(letters[currentIndex[1]], width / 2, height / 2); text(letters[currentIndex[1]], width / 2, height / 2);
text(letters[currentIndex[2]], width / 2 + 30, height / 2); text(letters[currentIndex[2]], width / 2 + 30, height / 2);
text("Restart", width / 2, height / 2 + 45); text("Restart", width / 2, height / 2 + height/12);
text("Main Menu", width / 2, height / 2 + 90); text("Main Menu", width / 2, height / 2 + height/6);
pop(); pop();
} }
} }
function movementCheck() { function movementCheck() {
//check if the player has moved //check if the player has moved
if (playerPosX != initialPlayerPosX || playerPosY != initialPlayerPosY) { if (playerPosX != initialPlayerPosX || playerPosY != initialPlayerPosY) {
hasMoved = true; hasMoved = true;
} }
} }
async function keyPressed() { async function keyPressed() {
if (!isDead && !homescreenOn && !pausescreenOn) { if (!isDead && !homescreenOn && !pausescreenOn) {
if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) { if (keyIsDown(LEFT_ARROW) && playerPosX > 0 + radius) {
@@ -158,32 +154,7 @@ async function keyPressed() {
} }
} }
if (isDead && keyReleasedFlag && !entered) { if (isDead && keyReleasedFlag && !entered) {
if ((!(iIndex > 2)) || (!(iIndex < 0))) { nameSubmit();
if (keyCode == LEFT_ARROW) {
iIndex -= 1;
keyReleasedFlag = false;
}
if (keyCode == RIGHT_ARROW) {
iIndex += 1;
keyReleasedFlag = false;
}
}
if (keyCode == UP_ARROW) {
currentIndex[iIndex] = (currentIndex[iIndex] + 1) % letters.length;
keyReleasedFlag = false;
}
if (keyCode == DOWN_ARROW) {
currentIndex[iIndex] = (currentIndex[iIndex] - 1 + letters.length) % letters.length;
keyReleasedFlag = false;
}
if (keyCode == ENTER) {
nameHS += letters[currentIndex[0]];
nameHS += letters[currentIndex[1]];
nameHS += letters[currentIndex[2]];
entered = true;
submit();
keyReleasedFlag = false;
}
} }
if (isDead && keyReleasedFlag && entered) { if (isDead && keyReleasedFlag && entered) {
if (keyCode == UP_ARROW) { if (keyCode == UP_ARROW) {
@@ -194,16 +165,6 @@ async function keyPressed() {
buttonSelectDead += 1; buttonSelectDead += 1;
keyReleasedFlag = false; keyReleasedFlag = false;
} }
if (buttonSelectDead == 0) {
if (keyCode == RIGHT_ARROW && !submitted) {
entered = false;
nameHS = '';
keyReleasedFlag = false;
}
if (keyCode == ENTER) {
keyReleasedFlag = false;
}
}
if (buttonSelectDead == 1) { if (buttonSelectDead == 1) {
if (keyCode == ENTER) { if (keyCode == ENTER) {
//reset all the variables so the game can be played again //reset all the variables so the game can be played again
@@ -284,7 +245,6 @@ async function keyPressed() {
} }
} }
} }
function submit() { function submit() {
if (entered == true) { if (entered == true) {
sendData(nameHS, int(time)); sendData(nameHS, int(time));
@@ -293,11 +253,9 @@ function submit() {
submitted = true; submitted = true;
} }
} }
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
} }
function wait(waitTime) { function wait(waitTime) {
return new Promise(resolve => { return new Promise(resolve => {
setTimeout(() => { setTimeout(() => {
@@ -305,7 +263,65 @@ function wait(waitTime) {
}, waitTime); }, waitTime);
}); });
} }
function nameSubmit() {
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) {
currentIndex[iIndex] = (currentIndex[iIndex] + 1) % letters.length;
keyReleasedFlag = false;
}
if (keyCode == DOWN_ARROW) {
currentIndex[iIndex] = (currentIndex[iIndex] - 1 + letters.length) % letters.length;
keyReleasedFlag = false;
}
if (keyCode == ENTER) {
nameHS += letters[currentIndex[0]];
nameHS += letters[currentIndex[1]];
nameHS += letters[currentIndex[2]];
entered = true;
if (isDead) {
submit();
} else {
// do nothing
}
keyReleasedFlag = false;
}
}
function nameDraw(positiony) {
if (iIndex == 0) {
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2 - 30, height / positiony, 30, 40)
pop()
}
if (iIndex == 1) {
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2, height / positiony, 30, 40)
pop()
}
if (iIndex == 2) {
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2 + 30, height / positiony, 30, 40)
pop()
}
}
// the function draw() is called every frame // the function draw() is called every frame
function draw() { function draw() {
keyPressed(); keyPressed();
@@ -331,7 +347,7 @@ function draw() {
stroke(205, 205, 205) stroke(205, 205, 205)
strokeWeight(2) strokeWeight(2)
fill(0, 0, 0, 0) fill(0, 0, 0, 0)
rect(width / 2, height / 2 + height/12, buttonWidth, buttonHeight) rect(width / 2, height / 2 + height / 12, buttonWidth, buttonHeight)
pop() pop()
} }
} }
@@ -360,7 +376,7 @@ function draw() {
strokeWeight(2) strokeWeight(2)
fill(0, 0, 0, 0) fill(0, 0, 0, 0)
rectMode(CENTER); rectMode(CENTER);
rect(width / 2, height / 2 + height/12, buttonWidth, buttonHeight) rect(width / 2, height / 2 + height / 12, buttonWidth, buttonHeight)
pop() pop()
} }
} }
@@ -368,11 +384,10 @@ function draw() {
if (entered) { if (entered) {
if (buttonSelectDead == 0) { if (buttonSelectDead == 0) {
push() push()
stroke(205, 205, 205) stroke(205, 205, 205)
strokeWeight(2) strokeWeight(2)
fill(0, 0, 0, 0) fill(0, 0, 0, 0)
rect(width / 2, height / 2 - 15, 90, 40) rect(width / 2, height / 2, 90, 40)
pop() pop()
} }
if (buttonSelectDead == 1) { if (buttonSelectDead == 1) {
@@ -380,7 +395,7 @@ function draw() {
stroke(205, 205, 205) stroke(205, 205, 205)
strokeWeight(2) strokeWeight(2)
fill(0, 0, 0, 0) fill(0, 0, 0, 0)
rect(width / 2, height / 2 + 30, 110, 40) rect(width / 2, height / 2 + height/12, 110, 40)
pop() pop()
} }
if (buttonSelectDead == 2) { if (buttonSelectDead == 2) {
@@ -388,35 +403,12 @@ function draw() {
stroke(205, 205, 205) stroke(205, 205, 205)
strokeWeight(2) strokeWeight(2)
fill(0, 0, 0, 0) fill(0, 0, 0, 0)
rect(width / 2, height / 2 + 75, 160, 40) rect(width / 2, height / 2 + height/6, 160, 40)
pop() pop()
} }
} }
else { else {
if (iIndex == 0) { nameDraw(2);
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2 - 30, height / 2 - 15, 30, 40)
pop()
}
if (iIndex == 1) {
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2, height / 2 - 15, 30, 40)
pop()
}
if (iIndex == 2) {
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2 + 30, height / 2 - 15, 30, 40)
pop()
}
} }
} }
} }
@@ -448,7 +440,6 @@ async function randPatern() {
} }
} }
function randomAttackPattern() { function randomAttackPattern() {
if (shot == false || hit == true) { if (shot == false || hit == true) {
for (i = 0; i < bulletAmount; i++) { for (i = 0; i < bulletAmount; i++) {
@@ -456,12 +447,11 @@ function randomAttackPattern() {
} }
} }
} }
function phase() { function phase() {
switch (true) { switch (true) {
case (time < 20): case (time < 20):
phases[0] = true; phases[0] = true;
paternArray = [5]; paternArray = [1];
shotSpeedAdj = 2; shotSpeedAdj = 2;
push(); push();
fill(255, 0, 255); fill(255, 0, 255);
@@ -518,7 +508,6 @@ function phase() {
break; break;
} }
} }
function spawnRandomBullet() { function spawnRandomBullet() {
if (chosen == false) { if (chosen == false) {
randPatern(); randPatern();
@@ -640,7 +629,6 @@ function spawnRandomBullet() {
bulletAmount = 5; bulletAmount = 5;
} }
} }
function game() { function game() {
if (!(lives == 0)) { if (!(lives == 0)) {
// draw player // draw player

View File

@@ -1,12 +1,6 @@
let buttonSelectScore = 0; let buttonSelectScore = 0;
let searchName = ''; let searchName = '';
let scorescreenOn = false; let scorescreenOn = false;
function scoremenu() {
textSize(50)
fill(255, 255, 255)
text("Hi, dit is een scorescreen", width / 2, height / 2 - 100)
}
function keyPressed() { function keyPressed() {
// Check if the back button was selected and the Enter key was pressed // Check if the back button was selected and the Enter key was pressed
@@ -18,19 +12,19 @@ function keyPressed() {
function homescreen() { function homescreen() {
textAlign(CENTER); textAlign(CENTER);
button(255, 255, 255, width / 2, height / 2, "Start Game") button(255, 255, 255, width / 2, height / 2, "Start Game")
button(255, 255, 255, width / 2, height / 2 + height/12, "Scores") button(255, 255, 255, width / 2, height / 2 + height / 12, "Scores")
push() push()
stroke(4,217,255) stroke(4, 217, 255)
strokeWeight(5) strokeWeight(5)
fill(0, 255, 0, 0) fill(0, 255, 0, 0)
rect(width/5*4, height/2, width/4, height/1.5) rect(width / 5 * 4, height / 2, width / 4, height / 1.5)
pop() pop()
//highscores rectangle //highscores rectangle
push() push()
textSize(50) textSize(50)
fill(255, 255, 255) fill(255, 255, 255)
text("Highscores", width/5, height/4) text("Highscores", width / 5, height / 4)
pop() pop()
push() push()
@@ -38,21 +32,21 @@ function homescreen() {
textSize(25) textSize(25)
textAlign(CENTER, CENTER) textAlign(CENTER, CENTER)
for (let i = 0; i < requesteddata.length; i++) { for (let i = 0; i < requesteddata.length; i++) {
text(i + 1 + ". " + requesteddata[i].Naam + ": " + requesteddata[i].Score, width/5, height/3 + (i * 30)) text(i + 1 + ". " + requesteddata[i].Naam + ": " + requesteddata[i].Score, width / 5, height / 3 + (i * 30))
} }
pop() pop()
push() push()
stroke(4,217,255) stroke(4, 217, 255)
strokeWeight(5) strokeWeight(5)
fill(0, 255, 0, 0) fill(0, 255, 0, 0)
rect(width/5, height/2, width/4, height/1.5) rect(width / 5, height / 2, width / 4, height / 1.5)
pop() pop()
push() push()
textSize(50) textSize(50)
fill(255, 255, 255) fill(255, 255, 255)
text("Controls", width/5*4, height/4) text("Controls", width / 5 * 4, height / 4)
pop() pop()
} }
@@ -64,16 +58,55 @@ function button(r, g, b, buttonX, buttonY, buttonText) {
textSize(25) textSize(25)
fill(r, g, b) fill(r, g, b)
textAlign(CENTER); textAlign(CENTER);
text(buttonText, buttonX, buttonY + buttonHeight/4) text(buttonText, buttonX, buttonY + buttonHeight / 4)
pop() pop()
} }
function pauseMenu(){ function pauseMenu() {
textAlign(CENTER); textAlign(CENTER);
textSize(50); textSize(50);
fill(255, 255, 255); fill(255, 255, 255);
text("Paused", width / 2, height / 2 - height/6); text("Paused", width / 2, height / 2 - height / 6);
button(255, 255, 255, width / 2, height / 2, "Resume"); button(255, 255, 255, width / 2, height / 2, "Resume");
button(255, 255, 255, width / 2, height / 2 + height/12, "Main Menu"); button(255, 255, 255, width / 2, height / 2 + height / 12, "Main Menu");
}
function scoremenu() {
textAlign(CENTER, CENTER);
textSize(50);
fill(255, 255, 255);
text("Score", width / 2, height / 5);
textSize(32);
text(letters[currentIndex[0]], width / 2 - 30, height / 3);
text(letters[currentIndex[1]], width / 2, height / 3);
text(letters[currentIndex[2]], width / 2 + 30, height / 3);
if (scorescreenOn && keyReleasedFlag) {
nameSubmit();
}
if (entered) {
push()
stroke(205, 205, 205)
strokeWeight(2)
fill(0, 0, 0, 0)
rect(width / 2, height / 3, 90, 40)
pop()
}
else {
nameDraw(3);
}
push()
stroke(4, 217, 255)
strokeWeight(5)
fill(0, 255, 0, 0)
rect(width / 4 * 3, height / 2, width / 4, height / 1.25)
rect(width / 4, height / 2, width / 4, height / 1.25)
pop()
push()
text("Your scores", width / 4, height / 6)
text("Your achievements", width / 4 * 3, height / 6)
pop()
} }

View File

@@ -42,6 +42,7 @@ class bullet {
let hit = false; let hit = false;
let shot = true; let shot = true;
let travelled = false;
// check if the projectile has hit the player // check if the projectile has hit the player
if (dist(this.projectile.x, this.projectile.y, this.targetx, this.targety) <= this.radius) { if (dist(this.projectile.x, this.projectile.y, this.targetx, this.targety) <= this.radius) {
hit = true; hit = true;