added title screen

This commit is contained in:
2025-11-28 20:37:45 +01:00
parent 88c6f4be72
commit 5fbf815595
5 changed files with 78 additions and 4 deletions

View File

@@ -64,8 +64,8 @@ public class GamePanel extends JPanel implements Runnable {
public void setupGame() {
assetSetter.setObject();
assetSetter.setNPC();
playMusic(0); //Play main theme
gameState = GameState.PLAY;
//playMusic(0); //Play main theme
gameState = GameState.TITLE;
}
public void startGameThread() {
@@ -121,7 +121,13 @@ public class GamePanel extends JPanel implements Runnable {
long drawStart = 0;
drawStart = System.nanoTime();
// COMPONENTS
// TITLE SCREEN
if(gameState == GameState.TITLE) {
ui.draw(graphics2d);
return;
}
// GAME
tileM.draw(graphics2d);
for (SuperObject superObject : obj) if (superObject != null) superObject.draw(graphics2d, this);
for(Entity npc : npc) if(npc != null) npc.draw(graphics2d);

View File

@@ -10,6 +10,7 @@ public class UI {
Graphics2D graphics2d;
Font arial_40, arial_80B;
public String currentDialogue;
public int commandNum = 0;
public UI(GamePanel panel) {
this.panel = panel;
@@ -33,6 +34,9 @@ public class UI {
case GameState.DIALOGUE:
drawDialogueScreen();
break;
case TITLE:
drawTitleScreen();
break;
}
}
@@ -61,6 +65,45 @@ public class UI {
}
}
public void drawTitleScreen() {
graphics2d.setColor(new Color(0, 0, 0));
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
// TITLE NAME
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 96F));
String text = "JGame2D";
int x = getCenteredX(text);
int y = panel.tileSize*3;
// SHADOW
graphics2d.setColor(Color.gray);
graphics2d.drawString(text, x+5, y+5);
// MAIN COLOR
graphics2d.setColor(Color.white);
graphics2d.drawString(text, x, y);
// MENU
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 48F));
text = "NEW GAME";
x = getCenteredX(text);
y += panel.tileSize*4;
graphics2d.drawString(text, x, y);
if(commandNum == 0) graphics2d.drawString(">", x-panel.tileSize, y);
text = "LOAD GAME";
x = getCenteredX(text);
y += panel.tileSize;
graphics2d.drawString(text, x, y);
if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y);
text = "QUIT";
x = getCenteredX(text);
y += panel.tileSize;
graphics2d.drawString(text, x, y);
if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y);
}
public 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);

View File

@@ -5,5 +5,6 @@ public enum GameState {
PLAY,
PAUSE,
DIALOGUE,
TITLE,
}

View File

@@ -45,6 +45,30 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_SPACE -> panel.gameState = GameState.PLAY;
}
break;
case TITLE:
switch (code) {
case KeyEvent.VK_UP -> {
if(panel.ui.commandNum != 0) panel.ui.commandNum--;
}
case KeyEvent.VK_DOWN -> {
if(panel.ui.commandNum != 2) panel.ui.commandNum++;
}
case KeyEvent.VK_ENTER -> {
switch (panel.ui.commandNum) {
case 0:
panel.gameState = GameState.PLAY;
panel.playMusic(0);
break;
case 1:
// add later
break;
case 2:
System.exit(0);
break;
}
}
}
break;
}
}

View File

@@ -30,7 +30,7 @@ public class OldManNPC extends Entity {
public void setDialogue() {
dialogue[0] = "Hello, lad.";
dialogue[1] = "So you've come to this island to \nfind the treasure?";
dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure";
dialogue[2] = "I used to be a great wizard but now... \nI'm a bit too old for taking an \nadventure.";
dialogue[3] = "Well, good luck on you.";
}