add MiniMap functionality and integrate map state handling

This commit is contained in:
2025-12-13 18:20:01 +01:00
parent 87aba81f32
commit 9263626ca2
8 changed files with 242 additions and 3 deletions

View File

@@ -0,0 +1,76 @@
035.png
true
026.png
true
019.png
true
018.png
true
000.png
false
009.png
false
037.png
false
007.png
false
034.png
false
028.png
true
008.png
false
001.png
false
036.png
false
005.png
false
021.png
true
013.png
false
023.png
true
032.png
true
029.png
true
031.png
true
033.png
true
014.png
false
025.png
true
016.png
true
003.png
false
024.png
true
030.png
true
004.png
false
010.png
false
027.png
true
012.png
false
006.png
false
015.png
false
020.png
true
017.png
false
011.png
false
022.png
true
002.png
false

View File

@@ -0,0 +1,50 @@
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 9 1 1 1 1 1 1 1 18 3 9 1 1 1 1 1 1 1 1 18 3 3 3 9 1 1 1 1 1 1 1 1 1 1 18 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 17 17 17 17 17 23 22 1 29 23 11 11 11 11 11 11 11 22 1 1 1 29 23 11 30 28 28 28 28 28 28 15 16 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 17 34 34 34 17 23 23 23 23 23 11 33 14 14 14 36 11 23 23 23 23 23 23 23 10 24 24 24 24 24 24 7 16 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 17 34 12 34 17 23 23 23 23 23 11 16 3 3 3 25 11 23 23 23 23 23 23 23 10 24 24 24 24 24 24 7 16 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 17 34 34 34 17 23 23 23 23 23 11 16 3 3 3 25 11 23 23 23 23 23 23 23 10 24 24 24 24 24 24 7 16 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 17 34 34 34 17 23 23 23 23 23 11 22 1 1 1 29 11 23 23 23 23 23 23 23 10 24 24 24 24 24 24 7 16 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 17 17 11 17 17 23 23 23 23 23 11 11 30 28 15 11 11 11 11 11 11 11 11 11 11 13 13 31 24 27 13 32 16 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 23 23 11 23 23 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 23 23 10 24 7 33 14 19 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 26 36 23 23 11 23 23 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 23 23 10 24 7 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 25 23 23 11 23 23 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 23 23 10 24 7 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 9 29 23 23 11 23 23 23 23 23 23 23 23 23 10 24 7 11 11 11 23 23 23 23 23 23 23 23 23 10 24 7 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 9 29 23 23 23 11 23 23 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 30 28 35 24 7 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 11 11 23 23 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 10 24 24 24 7 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 23 23 23 23 23 23 23 23 11 10 24 7 11 23 23 23 23 23 23 23 23 23 10 24 27 13 32 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 11 30 28 28 28 28 28 28 28 35 24 5 28 28 28 28 15 23 23 23 30 28 35 24 7 11 23 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 11 10 24 24 24 24 24 24 24 24 24 24 24 24 24 24 7 11 11 11 10 24 24 24 7 11 33 19 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 11 21 13 13 13 13 13 13 13 31 24 27 13 13 13 13 32 23 23 23 21 13 31 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 26 36 23 11 23 23 11 23 23 23 23 23 23 23 11 10 24 7 23 23 23 23 23 23 23 23 23 23 10 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 11 23 23 11 23 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 10 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 9 29 23 11 23 23 11 11 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 10 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 23 11 23 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 10 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 23 11 23 23 23 23 23 23 23 10 24 7 11 11 11 23 23 23 23 23 23 23 10 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 23 11 23 23 23 23 23 23 23 10 24 7 23 23 11 23 23 23 23 23 23 23 10 24 7 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 11 11 11 11 11 23 23 23 23 23 23 10 24 7 23 23 11 11 11 11 23 23 23 23 21 13 32 11 16 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 11 11 11 11 11 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 23 11 23 33 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 26 36 23 11 11 11 11 11 11 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 23 11 11 16 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 11 11 11 11 11 11 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 11 11 11 16 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 11 11 11 11 11 11 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 11 11 11 16 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 25 23 11 11 11 11 11 11 23 23 23 23 23 23 10 24 7 23 23 23 23 23 23 23 23 23 23 11 11 11 16 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 9 29 23 23 23 23 23 23 23 23 23 23 23 23 23 21 13 32 23 23 23 23 23 23 23 23 23 23 11 11 11 22 18 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 23 23 23 23 23 23 23 23 23 23 11 11 11 11 11 11 11 23 23 23 23 23 23 23 11 11 11 11 11 22 18 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 23 23 23 23 23 23 23 23 23 11 11 11 11 11 11 11 11 11 23 23 23 23 23 11 11 11 11 11 11 11 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 23 23 23 23 23 23 23 23 23 11 11 11 11 11 11 11 11 11 23 23 23 23 11 11 11 11 11 11 11 11 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 20 23 23 23 23 23 23 23 23 11 11 11 11 11 11 11 11 11 11 23 23 23 11 11 11 11 11 11 11 11 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 23 23 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 11 11 11 11 23 33 14 14 36 11 11 11 11 11 11 11 11 33 14 14 36 11 11 11 11 11 11 11 11 11 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 25 23 23 23 23 23 23 33 3 3 3 26 36 11 11 11 11 11 11 33 19 3 3 25 11 11 11 11 11 11 11 11 11 16 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 26 14 14 14 14 14 14 19 3 3 3 3 26 14 14 14 14 14 14 19 3 3 3 26 36 11 11 11 11 11 11 33 14 19 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 26 14 14 14 14 14 14 19 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

View File

@@ -7,6 +7,7 @@ import de.miaurizius.jgame2d.core.handlers.*;
import de.miaurizius.jgame2d.entity.Entity;
import de.miaurizius.jgame2d.entity.Player;
import de.miaurizius.jgame2d.environment.EnvironmentManager;
import de.miaurizius.jgame2d.tile.MiniMap;
import de.miaurizius.jgame2d.tile.TileManager;
import de.miaurizius.jgame2d.tile.interactive.InteractiveTile;
@@ -15,7 +16,6 @@ import javax.sound.sampled.FloatControl;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
@@ -60,6 +60,7 @@ public class GamePanel extends JPanel implements Runnable {
public Config config = new Config(this);
public PathFinder pFinder = new PathFinder(this);
public EnvironmentManager eManager = new EnvironmentManager(this);
public MiniMap mapMan = new MiniMap(this);
Thread gameThread;
// ENTITY AND OBJECT
@@ -167,6 +168,11 @@ public class GamePanel extends JPanel implements Runnable {
return;
}
if(gameState == GameState.MAP) {
mapMan.drawFullMapScreen(fg2);
return;
}
// GAME
tileM.draw(fg2);
for(Entity entity : iTile[currentMap.getIndex()]) if(entity != null) entity.draw(fg2);
@@ -185,6 +191,9 @@ public class GamePanel extends JPanel implements Runnable {
// ENVIRONMENT
eManager.draw(fg2);
// MINI MAP
mapMan.drawMiniMap(fg2);
// UI
ui.draw(fg2);

View File

@@ -17,10 +17,10 @@ public class UI {
GamePanel panel;
Graphics2D graphics2d;
Font font;
BufferedImage heart_full, heart_half, heart_blank, coin;
ArrayList<String> messages = new ArrayList<>();
ArrayList<Integer> messageCounter = new ArrayList<>();
public Font font;
public String currentDialogue;
public Entity tradingNPC;
public int commandNum;

View File

@@ -14,5 +14,6 @@ public enum GameState {
TRANSITION,
TRADE,
SLEEP,
MAP,
}

View File

@@ -3,7 +3,7 @@ package de.miaurizius.jgame2d.core.enums;
public enum Map {
OVERWORLD("worldmap", 0),
HUT("hut", 1);
HUT("worldmap", 1);
private final String name;
private final int index;

View File

@@ -53,6 +53,9 @@ public class KeyHandler implements KeyListener {
case KeyEvent.VK_SPACE -> spacePressed = true;
//case KeyEvent.VK_F -> shotKeyPressed = true;
// MINI MAP TOGGLE
case KeyEvent.VK_X -> panel.mapMan.miniMapOn = !panel.mapMan.miniMapOn;
// DEBUG OPTIONS
case KeyEvent.VK_T -> debug = !debug;
case KeyEvent.VK_R -> {for(Map m : Map.values()) panel.tileM.loadMap(m);}
@@ -64,6 +67,7 @@ public class KeyHandler implements KeyListener {
panel.ui.commandNum = 0;
}
case KeyEvent.VK_C -> panel.gameState = GameState.CHARACTER;
case KeyEvent.VK_M -> panel.gameState = GameState.MAP;
}
}
private void handlePause(int code) {
@@ -182,6 +186,12 @@ public class KeyHandler implements KeyListener {
if(code == KeyEvent.VK_ESCAPE) panel.ui.tradeState = UI.TradeState.SELECT;
}
}
private void handleMap(int code) {
switch (code) {
// EXIT STATE
case KeyEvent.VK_M, KeyEvent.VK_ESCAPE -> panel.gameState = GameState.PLAY;
}
}
// UTILITY
private void playerInventory(int code) {
@@ -255,6 +265,7 @@ public class KeyHandler implements KeyListener {
case CHARACTER -> handleCharacter(code);
case GAMEOVER -> handleGameOver(code);
case TRADE -> handleTrade(code);
case MAP -> handleMap(code);
}
}
@Override

View File

@@ -0,0 +1,92 @@
package de.miaurizius.jgame2d.tile;
import de.miaurizius.jgame2d.core.GamePanel;
import de.miaurizius.jgame2d.core.enums.Map;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class MiniMap extends TileManager {
GamePanel panel;
BufferedImage worldMap[];
public boolean miniMapOn;
public MiniMap(GamePanel panel) throws IOException {
super(panel);
this.panel = panel;
createWorldMap();
}
public void createWorldMap() {
worldMap = new BufferedImage[Map.values().length];
int worldMapWidth = panel.maxWorldCol * panel.tileSize;
int worldMapHeight = panel.maxWorldRow * panel.tileSize;
for (int i = 0; i < Map.values().length; i++) {
worldMap[i] = new BufferedImage(worldMapWidth, worldMapHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = worldMap[i].createGraphics();
int col = 0;
int row = 0;
while(col < panel.maxWorldCol && row < panel.maxWorldRow) {
int tileNum = mapTileNum[i][col][row];
int x = col * panel.tileSize;
int y = row * panel.tileSize;
g2.drawImage(panel.tileM.tile[tileNum].image, x, y, null);
col++;
if(col != panel.maxWorldCol) continue;
col = 0;
row++;
}
}
}
public void drawFullMapScreen(Graphics2D g2) {
// BACKGROUND
g2.setColor(Color.black);
g2.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
// DRAW MAP
int width = 500;
int height = 500;
int x = panel.screenWidth / 2 - width / 2;
int y = panel.screenHeight / 2 - height / 2;
g2.drawImage(worldMap[panel.currentMap.getIndex()], x, y, width, height, null);
// DRAW PLAYER
double scale = (double)(panel.tileSize * panel.maxWorldCol)/width;
int playerX = (int)(x + panel.player.worldX/scale);
int playerY = (int)(y + panel.player.worldY/scale);
int playerSize = (int)(panel.tileSize/scale);
g2.drawImage(panel.player.down1, playerX, playerY, playerSize, playerSize, null);
// HINT
g2.setFont(panel.ui.font.deriveFont(32F));
g2.setColor(Color.white);
g2.drawString("Press M to close", 750, 550);
}
public void drawMiniMap(Graphics2D g2) {
if(!miniMapOn) return;
// DRAW MAP
int width = 300;
int height = 300;
int x = panel.screenWidth - width - 50;
int y = 50;
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
g2.drawImage(worldMap[panel.currentMap.getIndex()], x, y, width, height, null);
// DRAW PLAYER
double scale = (double)(panel.tileSize * panel.maxWorldCol)/width;
int playerX = (int)(x + panel.player.worldX/scale);
int playerY = (int)(y + panel.player.worldY/scale);
int playerSize = (int)(panel.tileSize/3);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
g2.drawImage(panel.player.down1, playerX-6, playerY-6, playerSize, playerSize, null);
}
}