added game over screen

This commit is contained in:
2025-12-12 12:26:32 +01:00
parent 785a76942e
commit 5dd43b6f9d
7 changed files with 123 additions and 56 deletions

View File

@@ -47,26 +47,17 @@ public class UI {
if(panel.gameState == null) return;
switch (panel.gameState) {
case GameState.PLAY:
drawPlayScreen();
break;
case GameState.PAUSE:
drawPauseScreen();
break;
case GameState.DIALOGUE:
drawDialogueScreen();
break;
case TITLE:
drawTitleScreen();
break;
case CHARACTER:
drawCharacterScreen();
break;
case GameState.PLAY -> drawPlayScreen();
case GameState.PAUSE -> drawPauseScreen();
case GameState.DIALOGUE -> drawDialogueScreen();
case TITLE -> drawTitleScreen();
case CHARACTER -> drawCharacterScreen();
case GAMEOVER -> drawGameOverScreen();
}
}
// HUD
public void drawPlayerLife() {
private void drawPlayerLife() {
int x = panel.tileSize / 2;
int y = panel.tileSize / 2;
int i = 0;
@@ -91,7 +82,7 @@ public class UI {
x += panel.tileSize;
}
}
public void drawMessages() {
private void drawMessages() {
int messageX = panel.tileSize;
int messageY = panel.tileSize*4;
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 32F));
@@ -112,7 +103,7 @@ public class UI {
}
}
}
public void drawCharStats() {
private void drawCharStats() {
// DRAW FRAME
final int frameX = panel.tileSize*2;
final int frameY = panel.tileSize;
@@ -159,7 +150,7 @@ public class UI {
textY += panel.tileSize;
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
}
public void drawInventory() {
private void drawInventory() {
// DRAW FRAME
int frameX = panel.tileSize*12;
int frameY = panel.tileSize;
@@ -221,7 +212,7 @@ public class UI {
}
// GAME STATES
public void drawPauseScreen() {
private void drawPauseScreen() {
graphics2d.setColor(Color.white);
graphics2d.setFont(graphics2d.getFont().deriveFont(32F));
@@ -240,7 +231,7 @@ public class UI {
}
panel.keyH.spacePressed = false;
}
public void drawDialogueScreen() {
private void drawDialogueScreen() {
drawPlayerLife();
// WINDOW
int x = panel.tileSize*2;
@@ -258,7 +249,7 @@ public class UI {
y += 40;
}
}
public void drawTitleScreen() {
private void drawTitleScreen() {
graphics2d.setColor(new Color(0, 0, 0));
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
@@ -296,27 +287,59 @@ public class UI {
graphics2d.drawString(text, x, y);
if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y);
}
public void drawCharacterScreen() {
private void drawCharacterScreen() {
drawCharStats();
drawInventory();
}
public void drawPlayScreen() {
private void drawPlayScreen() {
drawPlayerLife();
drawMessages();
}
private void drawGameOverScreen() {
graphics2d.setColor(new Color(0,0,0, 150));
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
int x, y;
String text;
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 110F));
text = "GAME OVER";
// SHADOW
graphics2d.setColor(Color.black);
x = getCenteredX(text);
y = panel.tileSize*3;
graphics2d.drawString(text, x, y);
// MAIN TEXT
graphics2d.setColor(Color.white);
graphics2d.drawString(text, x-4, y-4);
// OPTIONS
graphics2d.setFont(graphics2d.getFont().deriveFont(50F));
text = "Retry";
x = getCenteredX(text);
y += panel.tileSize*4;
graphics2d.drawString(text, x, y);
if(commandNum == 0) graphics2d.drawString(">", x-panel.tileSize, y);
text = "Return to title";
x = getCenteredX(text);
y += 55;
graphics2d.drawString(text, x, y);
if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y);
}
// UTILITY
public void drawSubWindow(int x, int y, int width, int height) {
private void drawSubWindow(int x, int y, int width, int height) {
graphics2d.setColor(new Color(0,0,0,210));
graphics2d.fillRoundRect(x, y, width, height, 35, 35);
graphics2d.setColor(new Color(255,255,255));
graphics2d.setStroke(new BasicStroke(5));
graphics2d.drawRoundRect(x+5, y+5, width-10, height-10, 25, 25);
}
public int getCenteredX(String text) {
private int getCenteredX(String text) {
return panel.screenWidth / 2 - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2;
}
public int getAlignedToRightX(String text, int tailX) {
private int getAlignedToRightX(String text, int tailX) {
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
}
public int getItemIndex() {
@@ -328,7 +351,7 @@ public class UI {
}
// OPTIONS UI
public void optionsTop(int frameX, int frameY) {
private void optionsTop(int frameX, int frameY) {
int textX, textY;
String title = "Options";
textX = getCenteredX(title);
@@ -412,7 +435,7 @@ public class UI {
panel.config.save();
}
public void optionsControls(int frameX, int frameY) {
private void optionsControls(int frameX, int frameY) {
int textX;
int textY;
@@ -445,7 +468,7 @@ public class UI {
graphics2d.drawString(">", textX-25, textY);
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
}
public void optionsFSNotify(int frameX, int frameY) {
private void optionsFSNotify(int frameX, int frameY) {
int textX = frameX + panel.tileSize;
int textY = frameY + panel.tileSize*3;
@@ -464,7 +487,7 @@ public class UI {
}
}
public void optionsQuitNotify(int frameX, int frameY) {
private void optionsQuitNotify(int frameX, int frameY) {
int textX = frameX + panel.tileSize;
int textY = frameY + panel.tileSize*3;