add MiniMap functionality and integrate map state handling
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -14,5 +14,6 @@ public enum GameState {
|
||||
TRANSITION,
|
||||
TRADE,
|
||||
SLEEP,
|
||||
MAP,
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user