Compare commits

...

3 Commits

Author SHA1 Message Date
5192c8df87 continued options menu 2025-12-09 14:47:43 +01:00
2abdb3b5fb added start of options menu 2025-12-08 20:29:11 +01:00
7ac1207c83 added option subwindow 2025-12-08 14:23:39 +01:00
4 changed files with 107 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ public class Boot {
window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
window.setResizable(false); window.setResizable(false);
window.setTitle("JGame2D"); window.setTitle("JGame2D");
window.setUndecorated(true); //window.setUndecorated(true);
GamePanel gamePanel = new GamePanel(); GamePanel gamePanel = new GamePanel();
window.add(gamePanel); window.add(gamePanel);

View File

@@ -31,6 +31,7 @@ public class GamePanel extends JPanel implements Runnable {
int fScreenHeight = screenHeight; int fScreenHeight = screenHeight;
BufferedImage tempScreen; BufferedImage tempScreen;
Graphics2D fg2; Graphics2D fg2;
public boolean fullscreen;
// WORLD SETTINGS // WORLD SETTINGS
public final int maxWorldCol = 50; public final int maxWorldCol = 50;
@@ -223,7 +224,7 @@ public class GamePanel extends JPanel implements Runnable {
tempScreen = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB); tempScreen = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB);
fg2 = (Graphics2D) tempScreen.getGraphics(); fg2 = (Graphics2D) tempScreen.getGraphics();
setFullscreen(); //setFullscreen();
} }
public void setFullscreen() { public void setFullscreen() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

View File

@@ -19,6 +19,7 @@ public class UI {
BufferedImage heart_full, heart_half, heart_blank; BufferedImage heart_full, heart_half, heart_blank;
ArrayList<String> messages = new ArrayList<>(); ArrayList<String> messages = new ArrayList<>();
ArrayList<Integer> messageCounter = new ArrayList<>(); ArrayList<Integer> messageCounter = new ArrayList<>();
public OptionState optionState;
public String currentDialogue; public String currentDialogue;
public int commandNum; public int commandNum;
public int slotCol, slotRow; public int slotCol, slotRow;
@@ -221,11 +222,19 @@ public class UI {
// GAME STATES // GAME STATES
public void drawPauseScreen() { public void drawPauseScreen() {
drawPlayerLife(); graphics2d.setColor(Color.white);
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.PLAIN, 80)); graphics2d.setFont(graphics2d.getFont().deriveFont(32F));
String text = "PAUSED";
int y = panel.screenHeight / 2; // SUB WINDOW
graphics2d.drawString(text, getCenteredX(text), y); int frameX = panel.tileSize*6;
int frameY = panel.tileSize;
int frameWidth = panel.tileSize*8;
int frameHeight = panel.tileSize*10;
drawSubWindow(frameX, frameY, frameWidth, frameHeight);
switch(optionState) {
case OVERVIEW -> optionsTop(frameX, frameY);
}
} }
public void drawDialogueScreen() { public void drawDialogueScreen() {
drawPlayerLife(); drawPlayerLife();
@@ -314,4 +323,68 @@ public class UI {
messageCounter.add(0); messageCounter.add(0);
} }
public void optionsTop(int frameX, int frameY) {
int textX, textY;
String title = "Options";
textX = getCenteredX(title);
textY = frameY + panel.tileSize;
graphics2d.drawString(title, textX, textY);
// FULLSCREEN ON/OFF
textX = frameX + panel.tileSize;
textY += panel.tileSize;
graphics2d.drawString("Full Screen", textX, textY);
if(commandNum == 0) {
graphics2d.drawString(">", textX-25, textY);
if(panel.keyH.spacePressed) panel.fullscreen = !panel.fullscreen;
}
// MUSIC
textY += panel.tileSize;
graphics2d.drawString("Music", textX, textY);
if(commandNum == 1) graphics2d.drawString(">", textX-25, textY);
// SOUND EFFECTS
textY += panel.tileSize;
graphics2d.drawString("SFX", textX, textY);
if(commandNum == 2) graphics2d.drawString(">", textX-25, textY);
// CONTROL
textY += panel.tileSize;
graphics2d.drawString("Controls", textX, textY);
if(commandNum == 3) graphics2d.drawString(">", textX-25, textY);
// END GAME
textY += panel.tileSize;
graphics2d.drawString("Quit Game", textX, textY);
if(commandNum == 4) graphics2d.drawString(">", textX-25, textY);
// BACK
textY += panel.tileSize*2;
graphics2d.drawString("Back to Game", textX, textY);
if(commandNum == 5) graphics2d.drawString(">", textX-25, textY);
// FULL SCREEN CHECKBOX
textX = frameX + (int)(panel.tileSize*4.5);
textY = frameY + panel.tileSize*2 - panel.tileSize/2;
graphics2d.setStroke(new BasicStroke(3));
graphics2d.drawRect(textX, textY, panel.tileSize/2, panel.tileSize/2);
// MUSIC VOLUME
textY += panel.tileSize;
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2);
// SFX VOLUME
textY += panel.tileSize;
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2);
}
public enum OptionState {
OVERVIEW,
SCREEN,
MUSIC,
SFX,
CONTROLS,
}
} }

View File

@@ -1,6 +1,7 @@
package de.miaurizius.jgame2d.core.handlers; package de.miaurizius.jgame2d.core.handlers;
import de.miaurizius.jgame2d.core.GamePanel; import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.UI;
import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.core.enums.GameState;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@@ -56,11 +57,35 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_R -> panel.tileM.loadMap(panel.currentMap); case KeyEvent.VK_R -> panel.tileM.loadMap(panel.currentMap);
// GAME STATES // GAME STATES
case KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PAUSE; case KeyEvent.VK_ESCAPE -> {
panel.gameState = GameState.PAUSE;
panel.ui.optionState = UI.OptionState.OVERVIEW;
}
case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER; case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER;
} }
} }
public void handlePause(int code) { public void handlePause(int code) {
if(code == KeyEvent.VK_SPACE) spacePressed = true;
int maxCommandNum = 0;
switch (panel.ui.optionState) {
case OVERVIEW -> maxCommandNum = 5;
}
switch(code) {
case KeyEvent.VK_UP:
if(panel.ui.commandNum <= 0) break;
panel.ui.commandNum--;
panel.playSE(9);
break;
case KeyEvent.VK_DOWN:
if(panel.ui.commandNum >= maxCommandNum) break;
panel.ui.commandNum++;
panel.playSE(9);
break;
}
// EXIT STATE // EXIT STATE
if(code == KeyEvent.VK_ESCAPE) panel.gameState = GameState.PLAY; if(code == KeyEvent.VK_ESCAPE) panel.gameState = GameState.PLAY;
} }