refactored reset game

This commit is contained in:
2025-12-16 13:57:52 +01:00
parent ce3f590715
commit 54a2ee3022
5 changed files with 20 additions and 10 deletions

View File

@@ -263,18 +263,16 @@ 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() { public void resetGame(boolean restart) {
player.setDefaultPositions(); player.setDefaultPositions();
player.restoreLife(); player.restoreStatus();
assetSetter.setNPC(); assetSetter.setNPC();
assetSetter.setMonster(); assetSetter.setMonster();
}
public void restart() { if(!restart) return;
player.setDefaultValues(); player.setDefaultValues();
assetSetter.setObject(); assetSetter.setObject();
assetSetter.setNPC();
assetSetter.setMonster();
assetSetter.setITiles(); assetSetter.setITiles();
eManager.lighting.resetDay();
} }
} }

View File

@@ -736,6 +736,7 @@ public class UI {
if(commandNum == 1) { if(commandNum == 1) {
graphics2d.drawString(">", textX-25, textY); graphics2d.drawString(">", textX-25, textY);
if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW; if(panel.keyH.spacePressed) optionState = OptionState.OVERVIEW;
panel.resetGame(true);
} }
} }

View File

@@ -152,12 +152,12 @@ public class KeyHandler implements KeyListener {
if(panel.ui.commandNum == 0) { if(panel.ui.commandNum == 0) {
panel.gameState = GameState.PLAY; panel.gameState = GameState.PLAY;
panel.playMusic(0); panel.playMusic(0);
panel.retry(); panel.resetGame(false);
} }
if(panel.ui.commandNum == 1) { if(panel.ui.commandNum == 1) {
panel.gameState = GameState.TITLE; panel.gameState = GameState.TITLE;
panel.ui.commandNum = 0; panel.ui.commandNum = 0;
panel.restart(); panel.resetGame(true);
panel.stopMusic(); panel.stopMusic();
} }
} }

View File

@@ -311,9 +311,14 @@ public class Player extends Entity {
worldY = panel.tileSize * 21; worldY = panel.tileSize * 21;
direction = Direction.DOWN; direction = Direction.DOWN;
} }
public void restoreLife() { public void restoreStatus() {
life = maxLife; life = maxLife;
invincible = false; invincible = false;
transparent = false;
attacking = false;
guarding = false;
knockback = false;
lightUpdated = true;
} }
public void getSleepingImage(BufferedImage image) { public void getSleepingImage(BufferedImage image) {
down1 = image; down1 = image;
@@ -346,6 +351,7 @@ public class Player extends Entity {
coins = 500; coins = 500;
currentWeapon = new SwordNormalObj(panel); currentWeapon = new SwordNormalObj(panel);
currentShield = new ShieldWoodObj(panel); currentShield = new ShieldWoodObj(panel);
currentLight = null;
projectile = new FireballObj(panel); projectile = new FireballObj(panel);
attack = getAttack(); attack = getAttack();
defense = getDefense(); defense = getDefense();

View File

@@ -75,6 +75,11 @@ public class Lighting {
} }
} }
} }
public void resetDay() {
dayState = DayState.DAY;
filterAlpha = 0f;
dayCount = 0;
}
// ... // ...
public void setLightSource() { public void setLightSource() {