added transition effect to map change

This commit is contained in:
2025-12-12 14:57:47 +01:00
parent d546d302c6
commit 484abf4f9b
3 changed files with 28 additions and 9 deletions

View File

@@ -23,6 +23,7 @@ public class UI {
public String currentDialogue; public String currentDialogue;
public int commandNum; public int commandNum;
public int slotCol, slotRow; public int slotCol, slotRow;
private int transCounter;
public UI(GamePanel panel) { public UI(GamePanel panel) {
this.panel = panel; this.panel = panel;
@@ -47,12 +48,13 @@ public class UI {
if(panel.gameState == null) return; if(panel.gameState == null) return;
switch (panel.gameState) { switch (panel.gameState) {
case GameState.PLAY -> drawPlayScreen(); case PLAY -> drawPlayScreen();
case GameState.PAUSE -> drawPauseScreen(); case PAUSE -> drawPauseScreen();
case GameState.DIALOGUE -> drawDialogueScreen(); case DIALOGUE -> drawDialogueScreen();
case TITLE -> drawTitleScreen(); case TITLE -> drawTitleScreen();
case CHARACTER -> drawCharacterScreen(); case CHARACTER -> drawCharacterScreen();
case GAMEOVER -> drawGameOverScreen(); case GAMEOVER -> drawGameOverScreen();
case TRANSITION -> drawTransitionScreen();
} }
} }
@@ -327,6 +329,19 @@ public class UI {
graphics2d.drawString(text, x, y); graphics2d.drawString(text, x, y);
if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y); if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y);
} }
private void drawTransitionScreen() {
transCounter++;
graphics2d.setColor(new Color(0,0,0, transCounter*5));
graphics2d.fillRect(0, 0, panel.screenWidth, panel.screenHeight);
if(transCounter != 50) return;
transCounter = 0;
panel.gameState = GameState.PLAY;
panel.currentMap = panel.eventH.tempMap;
panel.player.worldX = panel.tileSize * panel.eventH.tempCol;
panel.player.worldY = panel.tileSize * panel.eventH.tempRow;
panel.eventH.prevEventX = panel.player.worldX;
panel.eventH.prevEventY = panel.player.worldY;
}
// UTILITY // UTILITY
private void drawSubWindow(int x, int y, int width, int height) { private void drawSubWindow(int x, int y, int width, int height) {

View File

@@ -8,5 +8,6 @@ public enum GameState {
TITLE, TITLE,
CHARACTER, CHARACTER,
GAMEOVER, GAMEOVER,
TRANSITION,
} }

View File

@@ -11,9 +11,13 @@ public class EventHandler {
GamePanel panel; GamePanel panel;
EventRect[][][] eventRect; EventRect[][][] eventRect;
int prevEventX, prevEventY; public int prevEventX, prevEventY;
boolean canTouchEvent = true; boolean canTouchEvent = true;
// TMP VARS FOR TRANSITION
public int tempCol, tempRow;
public Map tempMap;
public EventHandler(GamePanel panel) { public EventHandler(GamePanel panel) {
this.panel = panel; this.panel = panel;
eventRect = new EventRect[Map.values().length][panel.maxWorldCol][panel.maxWorldRow]; eventRect = new EventRect[Map.values().length][panel.maxWorldCol][panel.maxWorldRow];
@@ -100,11 +104,10 @@ public class EventHandler {
panel.assetSetter.setMonster(); panel.assetSetter.setMonster();
} }
public void changeMap(Map map, int col, int row) { public void changeMap(Map map, int col, int row) {
panel.currentMap = map; panel.gameState = GameState.TRANSITION;
panel.player.worldX = panel.tileSize*col; tempMap = map;
panel.player.worldY = panel.tileSize*row; tempCol = col;
prevEventX = panel.player.worldX; tempRow = row;
prevEventY = panel.player.worldY;
canTouchEvent = false; canTouchEvent = false;
panel.playSE(13); panel.playSE(13);
} }