added gameover screen to menu.js and stopped drawing player and boss when paused

This commit is contained in:
Mees Roelofsz
2024-01-19 10:17:22 +01:00
parent f5f9efc137
commit dd5c48926b
2 changed files with 50 additions and 44 deletions

View File

@@ -103,35 +103,12 @@ function reset() {
buttonSelectPause = 0; buttonSelectPause = 0;
submitted = false; submitted = false;
escaped = false; escaped = false;
bossPosX = width / 2;
bossPosY = height / 6;
bossVelX = 5;
bossVelY = 5;
} }
function gameOver() {
if (lives == 0) {
//game over screen
iIndex = constrain(iIndex, 0, 2);
isDead = true;
push();
fill(255, 0, 0);
textSize(40);
textAlign(CENTER);
text("Game Over", width / 2, height / 2 - height / 6);
fill(255, 255, 255)
textSize(18);
textAlign(CENTER);
text("Score: " + int(time), width / 2, height / 2 - height / 8);
textSize(32);
textAlign(CENTER, 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);
text("Restart", width / 2, height / 2 + height / 12);
text("Main Menu", width / 2, height / 2 + height / 6);
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) {
@@ -646,7 +623,7 @@ function bouncing() {
// Draw the boss // Draw the boss
circle(bossPosX, bossPosY, 50); circle(bossPosX, bossPosY, 50);
if (dist(bossPosX, bossPosY, playerPosX, playerPosY) <= 25 + radius) { if ((dist(bossPosX, bossPosY, playerPosX, playerPosY) <= 25 + radius) && hasMoved) {
lives -= 1; lives -= 1;
} }
} }
@@ -655,23 +632,24 @@ function game() {
if (!(lives == 0)) { if (!(lives == 0)) {
// draw player // draw player
phase(); phase();
push();
fill(0, 255, 255)
circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
pop();
movementCheck(); movementCheck();
push(); push();
fill(0, 255, 0); fill(0, 255, 0);
if (phases[2] == false || phase[3] == false) { if (!pausescreenOn) {
bouncing(); push();
} else if (phases[2] = true) { fill(0, 255, 255);
bossPosX = x2; circle(constrain(playerPosX, 0 + radius, width - radius), constrain(playerPosY, 0 + radius, height - radius), playerSize);
bossPosY = y2; pop();
} else { if (phases[2] == false || phase[3] == false) {
bossPosX = width / 2; bouncing();
bossPosY = height / 6; } else if (phases[2] = true) {
bossPosX = x2;
bossPosY = y2;
} else {
bossPosX = width / 2;
bossPosY = height / 6;
}
} }
pop(); pop();
if (hasMoved == true) { if (hasMoved == true) {
@@ -726,7 +704,7 @@ function game() {
if (!pausescreenOn) { if (!pausescreenOn) {
bullets.forEach(myBullet => { bullets.forEach(myBullet => {
//zolang mybullet bestaat blijft hij drawen en updaten //zolang mybullet bestaat blijft hij drawen en updaten
({ hit, shot, isOffScreen, originalPos } = myBullet.update(playerPosX, playerPosY, hasMoved)); ({ hit, shot, isOffScreen, originalPos } = myBullet.update(playerPosX, playerPosY, hasMoved, radius));
myBullet.draw(); myBullet.draw();
if (isOffScreen == true) { if (isOffScreen == true) {

View File

@@ -81,7 +81,6 @@ function scoremenu() {
clearDataOnce = true; clearDataOnce = true;
} }
if (scorescreenOn && keyReleasedFlag) { if (scorescreenOn && keyReleasedFlag) {
nameSubmit(); nameSubmit();
} }
@@ -135,3 +134,32 @@ function scoremenu() {
text("Your achievements", width / 4 * 3, height / 6) text("Your achievements", width / 4 * 3, height / 6)
pop() pop()
} }
function gameOver() {
if (lives <= 0) {
//game over screen
iIndex = constrain(iIndex, 0, 2);
isDead = true;
push();
fill(255, 0, 0);
textSize(60);
textAlign(CENTER, CENTER);
text("Game Over", width / 2, height / 2 - height / 5);
fill(255, 255, 255)
textSize(18);
text("Score: " + int(time), width / 2, height / 2 - height / 8);
textSize(32);
textAlign(CENTER, 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);
text("Restart", width / 2, height / 2 + height / 12);
text("Main Menu", width / 2, height / 2 + height / 6);
pop();
}
}