Merge remote-tracking branch 'origin/master'

master
bob 2022-06-17 13:28:48 -04:00
commit 4213b1f4c4
2 changed files with 13 additions and 9 deletions

BIN
img/dialogue/Bouncer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

View File

@ -42,7 +42,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
public int playerFrame, enemyFrame; public int playerFrame, enemyFrame;
// keeps track of how many ticks has elapsed since last frame change // keeps track of how many ticks has elapsed since last frame change
public int playerFrameCounter = 0; public int playerFrameCounter = 0;
public int enemyFrameCounter = 0; public int timeSinceLastSave = 0;
public boolean isPaused, isDialogue, waitForDialogue, mouseAlreadyTranslated; public boolean isPaused, isDialogue, waitForDialogue, mouseAlreadyTranslated;
public PauseMenu pauseMenu; public PauseMenu pauseMenu;
public DialogueMenu dialogueMenu; public DialogueMenu dialogueMenu;
@ -388,14 +388,18 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
playerFrameCounter -= 5; playerFrameCounter -= 5;
} }
} }
// a new save is made every tick // a new save is made every 100 ticks
bombCount = LevelManager.bombs; timeSinceLastSave++;
try { if (timeSinceLastSave >= 100) {
// atomic save to prevent EOF errors timeSinceLastSave -= 100;
FileManager.writeObjectToFile("local\\temp_state.dat", this); bombCount = LevelManager.bombs;
Files.move(Path.of("local", "temp_state.dat"), Path.of("local", "game_state.dat"), ATOMIC_MOVE); try {
} catch (IOException | ConcurrentModificationException e) { // atomic save to prevent EOF errors
e.printStackTrace(); FileManager.writeObjectToFile("local\\temp_state.dat", this);
Files.move(Path.of("local", "temp_state.dat"), Path.of("local", "game_state.dat"), ATOMIC_MOVE);
} catch (IOException | ConcurrentModificationException e) {
e.printStackTrace();
}
} }
repaint(); repaint();
delta--; delta--;