Compare commits
3 Commits
d294578a74
...
5dd43b6f9d
| Author | SHA1 | Date | |
|---|---|---|---|
|
5dd43b6f9d
|
|||
|
785a76942e
|
|||
|
099f52278c
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -32,4 +32,7 @@ bin/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
### JPackage ###
|
### JPackage ###
|
||||||
JGame2D
|
JGame2D
|
||||||
|
|
||||||
|
### Local Game Settings ###
|
||||||
|
gamedata
|
||||||
3
assets/META-INF/MANIFEST.MF
Normal file
3
assets/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: de.miaurizius.jgame2d.core.Boot
|
||||||
|
|
||||||
@@ -13,11 +13,13 @@ 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);
|
|
||||||
|
|
||||||
GamePanel gamePanel = new GamePanel();
|
GamePanel gamePanel = new GamePanel();
|
||||||
window.add(gamePanel);
|
window.add(gamePanel);
|
||||||
|
|
||||||
|
gamePanel.config.load();
|
||||||
|
if(gamePanel.fullscreen) window.setUndecorated(true);
|
||||||
|
|
||||||
window.pack();
|
window.pack();
|
||||||
|
|
||||||
window.setLocationRelativeTo(null);
|
window.setLocationRelativeTo(null);
|
||||||
|
|||||||
83
src/de/miaurizius/jgame2d/core/Config.java
Normal file
83
src/de/miaurizius/jgame2d/core/Config.java
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package de.miaurizius.jgame2d.core;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
private final GamePanel panel;
|
||||||
|
private final HashMap<String, String> settings = new HashMap<>();
|
||||||
|
|
||||||
|
public Config(GamePanel panel) {
|
||||||
|
this.panel = panel;
|
||||||
|
for (SETTING option : SETTING.values()) settings.put(option.name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GENERAL
|
||||||
|
public final void save() {
|
||||||
|
try {
|
||||||
|
insertToHash();
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter("gamedata/config"));
|
||||||
|
settings.forEach((invoke, value) -> {
|
||||||
|
try {
|
||||||
|
writer.write(invoke + ": " + value);
|
||||||
|
writer.newLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public final void load() {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader("gamedata/config"))) {
|
||||||
|
List<String> lines = reader.lines().toList();
|
||||||
|
if (lines.isEmpty()) return;
|
||||||
|
Map<String, String> configMap = new HashMap<>();
|
||||||
|
for (String line : lines) {
|
||||||
|
String[] parts = line.split(":\\s*", 2);
|
||||||
|
if (parts.length == 2) {
|
||||||
|
configMap.put(parts[0].trim(), parts[1].trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SETTING setting : SETTING.values()) {
|
||||||
|
String value = configMap.get(setting.name);
|
||||||
|
if (value != null) {
|
||||||
|
switch (setting) {
|
||||||
|
case FULLSCREEN -> panel.fullscreen = Boolean.parseBoolean(value);
|
||||||
|
case MUSICVOLUME -> panel.music.volumeScale = Integer.parseInt(value);
|
||||||
|
case SFXVOLUME -> panel.sfx.volumeScale = Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insertToHash();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HELP FUNCTIONS
|
||||||
|
private void insertToHash() {
|
||||||
|
settings.put(SETTING.FULLSCREEN.name, String.valueOf(panel.fullscreen));
|
||||||
|
settings.put(SETTING.MUSICVOLUME.name, String.valueOf(panel.music.volumeScale));
|
||||||
|
settings.put(SETTING.SFXVOLUME.name, String.valueOf(panel.sfx.volumeScale));
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum SETTING {
|
||||||
|
FULLSCREEN("fullscreen"),
|
||||||
|
MUSICVOLUME("music-vol"),
|
||||||
|
SFXVOLUME("sfx-vol");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
SETTING(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -28,11 +28,11 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
public final int screenHeight = tileSize * maxScreenRow; // 576 pixels
|
public final int screenHeight = tileSize * maxScreenRow; // 576 pixels
|
||||||
|
|
||||||
// FULLSCREEN SETTINGS
|
// FULLSCREEN SETTINGS
|
||||||
|
public boolean fullscreen;
|
||||||
int fScreenWidth = screenWidth;
|
int fScreenWidth = screenWidth;
|
||||||
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;
|
||||||
@@ -50,8 +50,9 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
public AssetSetter assetSetter = new AssetSetter(this);
|
public AssetSetter assetSetter = new AssetSetter(this);
|
||||||
public UI ui = new UI(this);
|
public UI ui = new UI(this);
|
||||||
public EventHandler eventH = new EventHandler(this);
|
public EventHandler eventH = new EventHandler(this);
|
||||||
public Sound se = new Sound();
|
public Sound sfx = new Sound();
|
||||||
public Sound music = new Sound();
|
public Sound music = new Sound();
|
||||||
|
public Config config = new Config(this);
|
||||||
Thread gameThread;
|
Thread gameThread;
|
||||||
|
|
||||||
// ENTITY AND OBJECT
|
// ENTITY AND OBJECT
|
||||||
@@ -211,9 +212,9 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
music.stop();
|
music.stop();
|
||||||
}
|
}
|
||||||
public void playSE(int i) {
|
public void playSE(int i) {
|
||||||
Clip c = se.clips[i];
|
Clip c = sfx.clips[i];
|
||||||
se.fc = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
|
sfx.fc = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
|
||||||
se.checkVolume();
|
sfx.checkVolume();
|
||||||
if(c.isRunning()) c.stop();
|
if(c.isRunning()) c.stop();
|
||||||
c.setFramePosition(0);
|
c.setFramePosition(0);
|
||||||
c.start();
|
c.start();
|
||||||
@@ -230,7 +231,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();
|
if(fullscreen) setFullscreen();
|
||||||
}
|
}
|
||||||
public void setFullscreen() {
|
public void setFullscreen() {
|
||||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
@@ -240,5 +241,18 @@ public class GamePanel extends JPanel implements Runnable {
|
|||||||
fScreenWidth = Boot.window.getWidth();
|
fScreenWidth = Boot.window.getWidth();
|
||||||
fScreenHeight = Boot.window.getHeight();
|
fScreenHeight = Boot.window.getHeight();
|
||||||
}
|
}
|
||||||
|
public void retry() {
|
||||||
|
player.setDefaultPositions();
|
||||||
|
player.restoreLife();
|
||||||
|
assetSetter.setNPC();
|
||||||
|
assetSetter.setMonster();
|
||||||
|
}
|
||||||
|
public void restart() {
|
||||||
|
player.setDefaultValues();
|
||||||
|
assetSetter.setObject();
|
||||||
|
assetSetter.setNPC();
|
||||||
|
assetSetter.setMonster();
|
||||||
|
assetSetter.setITiles();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,26 +47,17 @@ public class UI {
|
|||||||
|
|
||||||
if(panel.gameState == null) return;
|
if(panel.gameState == null) return;
|
||||||
switch (panel.gameState) {
|
switch (panel.gameState) {
|
||||||
case GameState.PLAY:
|
case GameState.PLAY -> drawPlayScreen();
|
||||||
drawPlayScreen();
|
case GameState.PAUSE -> drawPauseScreen();
|
||||||
break;
|
case GameState.DIALOGUE -> drawDialogueScreen();
|
||||||
case GameState.PAUSE:
|
case TITLE -> drawTitleScreen();
|
||||||
drawPauseScreen();
|
case CHARACTER -> drawCharacterScreen();
|
||||||
break;
|
case GAMEOVER -> drawGameOverScreen();
|
||||||
case GameState.DIALOGUE:
|
|
||||||
drawDialogueScreen();
|
|
||||||
break;
|
|
||||||
case TITLE:
|
|
||||||
drawTitleScreen();
|
|
||||||
break;
|
|
||||||
case CHARACTER:
|
|
||||||
drawCharacterScreen();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HUD
|
// HUD
|
||||||
public void drawPlayerLife() {
|
private void drawPlayerLife() {
|
||||||
int x = panel.tileSize / 2;
|
int x = panel.tileSize / 2;
|
||||||
int y = panel.tileSize / 2;
|
int y = panel.tileSize / 2;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -91,7 +82,7 @@ public class UI {
|
|||||||
x += panel.tileSize;
|
x += panel.tileSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void drawMessages() {
|
private void drawMessages() {
|
||||||
int messageX = panel.tileSize;
|
int messageX = panel.tileSize;
|
||||||
int messageY = panel.tileSize*4;
|
int messageY = panel.tileSize*4;
|
||||||
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 32F));
|
graphics2d.setFont(graphics2d.getFont().deriveFont(Font.BOLD, 32F));
|
||||||
@@ -112,7 +103,7 @@ public class UI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void drawCharStats() {
|
private void drawCharStats() {
|
||||||
// DRAW FRAME
|
// DRAW FRAME
|
||||||
final int frameX = panel.tileSize*2;
|
final int frameX = panel.tileSize*2;
|
||||||
final int frameY = panel.tileSize;
|
final int frameY = panel.tileSize;
|
||||||
@@ -159,7 +150,7 @@ public class UI {
|
|||||||
textY += panel.tileSize;
|
textY += panel.tileSize;
|
||||||
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
|
graphics2d.drawImage(panel.player.currentShield.down1, tailX - panel.tileSize, textY-14, null);
|
||||||
}
|
}
|
||||||
public void drawInventory() {
|
private void drawInventory() {
|
||||||
// DRAW FRAME
|
// DRAW FRAME
|
||||||
int frameX = panel.tileSize*12;
|
int frameX = panel.tileSize*12;
|
||||||
int frameY = panel.tileSize;
|
int frameY = panel.tileSize;
|
||||||
@@ -221,7 +212,7 @@ public class UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GAME STATES
|
// GAME STATES
|
||||||
public void drawPauseScreen() {
|
private void drawPauseScreen() {
|
||||||
graphics2d.setColor(Color.white);
|
graphics2d.setColor(Color.white);
|
||||||
graphics2d.setFont(graphics2d.getFont().deriveFont(32F));
|
graphics2d.setFont(graphics2d.getFont().deriveFont(32F));
|
||||||
|
|
||||||
@@ -240,7 +231,7 @@ public class UI {
|
|||||||
}
|
}
|
||||||
panel.keyH.spacePressed = false;
|
panel.keyH.spacePressed = false;
|
||||||
}
|
}
|
||||||
public void drawDialogueScreen() {
|
private void drawDialogueScreen() {
|
||||||
drawPlayerLife();
|
drawPlayerLife();
|
||||||
// WINDOW
|
// WINDOW
|
||||||
int x = panel.tileSize*2;
|
int x = panel.tileSize*2;
|
||||||
@@ -258,7 +249,7 @@ public class UI {
|
|||||||
y += 40;
|
y += 40;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void drawTitleScreen() {
|
private void drawTitleScreen() {
|
||||||
graphics2d.setColor(new Color(0, 0, 0));
|
graphics2d.setColor(new Color(0, 0, 0));
|
||||||
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
|
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
|
||||||
|
|
||||||
@@ -296,27 +287,59 @@ public class UI {
|
|||||||
graphics2d.drawString(text, x, y);
|
graphics2d.drawString(text, x, y);
|
||||||
if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y);
|
if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y);
|
||||||
}
|
}
|
||||||
public void drawCharacterScreen() {
|
private void drawCharacterScreen() {
|
||||||
drawCharStats();
|
drawCharStats();
|
||||||
drawInventory();
|
drawInventory();
|
||||||
}
|
}
|
||||||
public void drawPlayScreen() {
|
private void drawPlayScreen() {
|
||||||
drawPlayerLife();
|
drawPlayerLife();
|
||||||
drawMessages();
|
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
|
// 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.setColor(new Color(0,0,0,210));
|
||||||
graphics2d.fillRoundRect(x, y, width, height, 35, 35);
|
graphics2d.fillRoundRect(x, y, width, height, 35, 35);
|
||||||
graphics2d.setColor(new Color(255,255,255));
|
graphics2d.setColor(new Color(255,255,255));
|
||||||
graphics2d.setStroke(new BasicStroke(5));
|
graphics2d.setStroke(new BasicStroke(5));
|
||||||
graphics2d.drawRoundRect(x+5, y+5, width-10, height-10, 25, 25);
|
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;
|
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();
|
return tailX - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth();
|
||||||
}
|
}
|
||||||
public int getItemIndex() {
|
public int getItemIndex() {
|
||||||
@@ -328,7 +351,7 @@ public class UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OPTIONS UI
|
// OPTIONS UI
|
||||||
public void optionsTop(int frameX, int frameY) {
|
private void optionsTop(int frameX, int frameY) {
|
||||||
int textX, textY;
|
int textX, textY;
|
||||||
String title = "Options";
|
String title = "Options";
|
||||||
textX = getCenteredX(title);
|
textX = getCenteredX(title);
|
||||||
@@ -370,7 +393,7 @@ public class UI {
|
|||||||
|
|
||||||
// END GAME
|
// END GAME
|
||||||
textY += panel.tileSize;
|
textY += panel.tileSize;
|
||||||
graphics2d.drawString("Quit Game", textX, textY);
|
graphics2d.drawString("Title Screen", textX, textY);
|
||||||
if(commandNum == 4) {
|
if(commandNum == 4) {
|
||||||
graphics2d.drawString(">", textX-25, textY);
|
graphics2d.drawString(">", textX-25, textY);
|
||||||
if(panel.keyH.spacePressed) {
|
if(panel.keyH.spacePressed) {
|
||||||
@@ -408,9 +431,11 @@ public class UI {
|
|||||||
// SFX VOLUME
|
// SFX VOLUME
|
||||||
textY += panel.tileSize;
|
textY += panel.tileSize;
|
||||||
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2); // 120/5 = 24
|
graphics2d.drawRect(textX, textY, 120, panel.tileSize/2); // 120/5 = 24
|
||||||
graphics2d.fillRect(textX, textY, 24 * panel.se.volumeScale, panel.tileSize/2);
|
graphics2d.fillRect(textX, textY, 24 * panel.sfx.volumeScale, panel.tileSize/2);
|
||||||
|
|
||||||
|
panel.config.save();
|
||||||
}
|
}
|
||||||
public void optionsControls(int frameX, int frameY) {
|
private void optionsControls(int frameX, int frameY) {
|
||||||
int textX;
|
int textX;
|
||||||
int textY;
|
int textY;
|
||||||
|
|
||||||
@@ -443,7 +468,7 @@ public class UI {
|
|||||||
graphics2d.drawString(">", textX-25, textY);
|
graphics2d.drawString(">", textX-25, textY);
|
||||||
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
|
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 textX = frameX + panel.tileSize;
|
||||||
int textY = frameY + panel.tileSize*3;
|
int textY = frameY + panel.tileSize*3;
|
||||||
|
|
||||||
@@ -462,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 textX = frameX + panel.tileSize;
|
||||||
int textY = frameY + panel.tileSize*3;
|
int textY = frameY + panel.tileSize*3;
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ public enum GameState {
|
|||||||
DIALOGUE,
|
DIALOGUE,
|
||||||
TITLE,
|
TITLE,
|
||||||
CHARACTER,
|
CHARACTER,
|
||||||
|
GAMEOVER,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class KeyHandler implements KeyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// STATE SPECIFIC KEYBIND CONFIGURATION
|
// STATE SPECIFIC KEYBIND CONFIGURATION
|
||||||
public void handleTitle(int code) {
|
private void handleTitle(int code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case KeyEvent.VK_UP -> {
|
case KeyEvent.VK_UP -> {
|
||||||
if(panel.ui.commandNum != 0) panel.ui.commandNum--;
|
if(panel.ui.commandNum != 0) panel.ui.commandNum--;
|
||||||
@@ -42,7 +42,7 @@ public class KeyHandler implements KeyListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void handlePlay(int code) {
|
private void handlePlay(int code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
// CONTROLS
|
// CONTROLS
|
||||||
case KeyEvent.VK_W, KeyEvent.VK_UP -> upPressed = true;
|
case KeyEvent.VK_W, KeyEvent.VK_UP -> upPressed = true;
|
||||||
@@ -65,7 +65,7 @@ public class KeyHandler implements KeyListener {
|
|||||||
case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER;
|
case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void handlePause(int code) {
|
private void handlePause(int code) {
|
||||||
if(code == KeyEvent.VK_SPACE) spacePressed = true;
|
if(code == KeyEvent.VK_SPACE) spacePressed = true;
|
||||||
|
|
||||||
int maxCommandNum = 0;
|
int maxCommandNum = 0;
|
||||||
@@ -92,8 +92,8 @@ public class KeyHandler implements KeyListener {
|
|||||||
panel.music.volumeScale--;
|
panel.music.volumeScale--;
|
||||||
panel.music.checkVolume();
|
panel.music.checkVolume();
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
} else if(panel.ui.commandNum == 2 && panel.se.volumeScale > 0) {
|
} else if(panel.ui.commandNum == 2 && panel.sfx.volumeScale > 0) {
|
||||||
panel.se.volumeScale--;
|
panel.sfx.volumeScale--;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -103,8 +103,8 @@ public class KeyHandler implements KeyListener {
|
|||||||
panel.music.volumeScale++;
|
panel.music.volumeScale++;
|
||||||
panel.music.checkVolume();
|
panel.music.checkVolume();
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
} else if(panel.ui.commandNum == 2 && panel.se.volumeScale < 5) {
|
} else if(panel.ui.commandNum == 2 && panel.sfx.volumeScale < 5) {
|
||||||
panel.se.volumeScale++;
|
panel.sfx.volumeScale++;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,35 +115,35 @@ public class KeyHandler implements KeyListener {
|
|||||||
if(code == KeyEvent.VK_ESCAPE)
|
if(code == KeyEvent.VK_ESCAPE)
|
||||||
if(panel.ui.optionState == UI.OptionState.OVERVIEW) panel.gameState = GameState.PLAY; else panel.ui.optionState = UI.OptionState.OVERVIEW;
|
if(panel.ui.optionState == UI.OptionState.OVERVIEW) panel.gameState = GameState.PLAY; else panel.ui.optionState = UI.OptionState.OVERVIEW;
|
||||||
}
|
}
|
||||||
public void handleDialogue(int code) {
|
private void handleDialogue(int code) {
|
||||||
// EXIT STATE
|
// EXIT STATE
|
||||||
if (code == KeyEvent.VK_SPACE) {
|
if (code == KeyEvent.VK_SPACE) {
|
||||||
panel.gameState = GameState.PLAY;
|
panel.gameState = GameState.PLAY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void handleCharacter(int code) throws InterruptedException {
|
private void handleCharacter(int code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case KeyEvent.VK_UP:
|
case KeyEvent.VK_UP:
|
||||||
if(panel.ui.slotRow == 0) break;
|
if(panel.ui.slotRow == 0) break;
|
||||||
if(panel.se.clips[9].isRunning()) break;
|
if(panel.sfx.clips[9].isRunning()) break;
|
||||||
panel.ui.slotRow--;
|
panel.ui.slotRow--;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_DOWN:
|
case KeyEvent.VK_DOWN:
|
||||||
if(panel.ui.slotRow == 3) break;
|
if(panel.ui.slotRow == 3) break;
|
||||||
if(panel.se.clips[9].isRunning()) break;
|
if(panel.sfx.clips[9].isRunning()) break;
|
||||||
panel.ui.slotRow++;
|
panel.ui.slotRow++;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_LEFT:
|
case KeyEvent.VK_LEFT:
|
||||||
if(panel.ui.slotCol == 0) break;
|
if(panel.ui.slotCol == 0) break;
|
||||||
if(panel.se.clips[9].isRunning()) break;
|
if(panel.sfx.clips[9].isRunning()) break;
|
||||||
panel.ui.slotCol--;
|
panel.ui.slotCol--;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
break;
|
break;
|
||||||
case KeyEvent.VK_RIGHT:
|
case KeyEvent.VK_RIGHT:
|
||||||
if(panel.ui.slotCol == 4) break;
|
if(panel.ui.slotCol == 4) break;
|
||||||
if(panel.se.clips[9].isRunning()) break;
|
if(panel.sfx.clips[9].isRunning()) break;
|
||||||
panel.ui.slotCol++;
|
panel.ui.slotCol++;
|
||||||
panel.playSE(9);
|
panel.playSE(9);
|
||||||
break;
|
break;
|
||||||
@@ -157,6 +157,30 @@ public class KeyHandler implements KeyListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void handleGameOver(int code) {
|
||||||
|
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 >= 1) break;
|
||||||
|
panel.ui.commandNum++;
|
||||||
|
panel.playSE(9);
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_SPACE:
|
||||||
|
if(panel.ui.commandNum == 0) {
|
||||||
|
panel.gameState = GameState.PLAY;
|
||||||
|
panel.retry();
|
||||||
|
}
|
||||||
|
if(panel.ui.commandNum == 1) {
|
||||||
|
panel.gameState = GameState.TITLE;
|
||||||
|
panel.restart();
|
||||||
|
panel.stopMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// KEY-LISTENER
|
// KEY-LISTENER
|
||||||
@Override
|
@Override
|
||||||
@@ -165,25 +189,12 @@ public class KeyHandler implements KeyListener {
|
|||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
int code = e.getKeyCode();
|
int code = e.getKeyCode();
|
||||||
switch(panel.gameState) {
|
switch(panel.gameState) {
|
||||||
case PLAY:
|
case PLAY -> handlePlay(code);
|
||||||
handlePlay(code);
|
case DIALOGUE -> handleDialogue(code);
|
||||||
break;
|
case TITLE -> handleTitle(code);
|
||||||
case DIALOGUE:
|
case PAUSE -> handlePause(code);
|
||||||
handleDialogue(code);
|
case CHARACTER -> handleCharacter(code);
|
||||||
break;
|
case GAMEOVER -> handleGameOver(code);
|
||||||
case TITLE:
|
|
||||||
handleTitle(code);
|
|
||||||
break;
|
|
||||||
case PAUSE:
|
|
||||||
handlePause(code);
|
|
||||||
break;
|
|
||||||
case CHARACTER:
|
|
||||||
try {
|
|
||||||
handleCharacter(code);
|
|
||||||
} catch (InterruptedException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class Sound {
|
|||||||
load(9, "assets/sounds/cursor.wav");
|
load(9, "assets/sounds/cursor.wav");
|
||||||
load(10, "assets/sounds/burning.wav");
|
load(10, "assets/sounds/burning.wav");
|
||||||
load(11, "assets/sounds/cuttree.wav");
|
load(11, "assets/sounds/cuttree.wav");
|
||||||
|
load(12, "assets/sounds/gameover.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
@@ -125,6 +125,11 @@ public class Player extends Entity {
|
|||||||
invincible = false;
|
invincible = false;
|
||||||
invincibleCount = 0;
|
invincibleCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(life <= 0) {
|
||||||
|
panel.gameState = GameState.GAMEOVER;
|
||||||
|
panel.playSE(12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// INTERACTION
|
// INTERACTION
|
||||||
@@ -241,7 +246,7 @@ public class Player extends Entity {
|
|||||||
super.speak();
|
super.speak();
|
||||||
}
|
}
|
||||||
|
|
||||||
// BACKGROUND CHECKS
|
// BACKGROUND JOBS
|
||||||
public void checkLevelUp() {
|
public void checkLevelUp() {
|
||||||
if(exp < nextLevelExp) return;
|
if(exp < nextLevelExp) return;
|
||||||
level++;
|
level++;
|
||||||
@@ -274,6 +279,15 @@ public class Player extends Entity {
|
|||||||
inventory.remove(itemIndex);
|
inventory.remove(itemIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void setDefaultPositions() {
|
||||||
|
worldX = panel.tileSize * 23;
|
||||||
|
worldY = panel.tileSize * 21;
|
||||||
|
direction = Direction.DOWN;
|
||||||
|
}
|
||||||
|
public void restoreLife() {
|
||||||
|
life = maxLife;
|
||||||
|
invincible = false;
|
||||||
|
}
|
||||||
|
|
||||||
// SETTING THINGS UP
|
// SETTING THINGS UP
|
||||||
public void setDefaultValues() {
|
public void setDefaultValues() {
|
||||||
@@ -298,6 +312,7 @@ public class Player extends Entity {
|
|||||||
defense = getDefense();
|
defense = getDefense();
|
||||||
|
|
||||||
// INVENTORY
|
// INVENTORY
|
||||||
|
inventory.clear();
|
||||||
inventory.add(currentWeapon);
|
inventory.add(currentWeapon);
|
||||||
inventory.add(currentShield);
|
inventory.add(currentShield);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user