From 0f39c420069e94c01d37dcd7a2a8faf0a162c177 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 20 Jun 2022 11:32:02 -0400 Subject: [PATCH] Fix p, add loading screen --- src/GamePanel.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/GamePanel.java b/src/GamePanel.java index c8bc46d..874e1b1 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -37,6 +37,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ public static Font loreFont = new Font(Font.MONOSPACED, Font.ITALIC + Font.BOLD, 36); public static Color tutorialColor = Color.darkGray; public static Color loreColor = Color.lightGray; + public PauseMenu loadingMenu; public int bombCount; @@ -94,6 +95,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ public boolean isRunning; public ArrayList tutorialSign = new ArrayList(); public ArrayList loreSign = new ArrayList(); + public boolean isLoaded; public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException { @@ -107,6 +109,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ pauseMenuExitOne = new PauseMenu(GAME_HEIGHT/2, 0, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 24), "Press ENTER to return", true); pauseMenuExitTwo = new PauseMenu(GAME_HEIGHT/2, -20, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 24), "to the main menu", true); pauseMenuResume = new PauseMenu(GAME_HEIGHT/2, -50, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 18), "(or press ESC to resume)", true); + loadingMenu = new PauseMenu(GAME_HEIGHT/2, 0, GAME_WIDTH, GAME_HEIGHT, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 60), "Loading...", true); dialogueMenu = new DialogueMenu(GAME_HEIGHT-100, 200, new Font(Font.MONOSPACED, Font.BOLD, 20), narratorPortrait, true); try { // load player sprites from disk here @@ -355,6 +358,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ // throw new RuntimeException(e); } } + if (!isLoaded) { + loadingMenu.draw(g, Color.white, Color.black); + } } //call the move methods in other classes to update positions @@ -433,6 +439,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ } else { LevelManager.bombs = bombCount; } + isLoaded = true; //the CPU runs our game code too quickly - we need to slow it down! The following lines of code "force" the computer to get stuck in a loop for short intervals between calling other methods to update the screen. long lastTime = System.nanoTime(); double amountOfTicks = 60; @@ -564,7 +571,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ player.keyReleased(e); if(e.getKeyChar() == 'p'){ LevelManager.nextLevel(); - + try { + player.resetNoSound(); + } catch (IOException ex) { + ex.printStackTrace(); + } } }