From 80e5b906038a581c6edddfc6c8ad3b28493f2a5e Mon Sep 17 00:00:00 2001 From: John Date: Sun, 19 Jun 2022 14:31:19 -0400 Subject: [PATCH] Add loading dialogue --- saves/Level1-dialogue.txt | 2 ++ saves/Level2-dialogue.txt | 2 ++ saves/Level3-dialogue.txt | 20 ++++++++++++++++++++ src/DialogueMenu.java | 7 ++++++- src/LevelManager.java | 13 +++++++++++++ src/MapReader.java | 6 ++++++ 6 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 saves/Level1-dialogue.txt create mode 100644 saves/Level2-dialogue.txt create mode 100644 saves/Level3-dialogue.txt diff --git a/saves/Level1-dialogue.txt b/saves/Level1-dialogue.txt new file mode 100644 index 0000000..2810ab3 --- /dev/null +++ b/saves/Level1-dialogue.txt @@ -0,0 +1,2 @@ +Have you heard of the tragedy of +Darth Charlie the Wise? \ No newline at end of file diff --git a/saves/Level2-dialogue.txt b/saves/Level2-dialogue.txt new file mode 100644 index 0000000..2810ab3 --- /dev/null +++ b/saves/Level2-dialogue.txt @@ -0,0 +1,2 @@ +Have you heard of the tragedy of +Darth Charlie the Wise? \ No newline at end of file diff --git a/saves/Level3-dialogue.txt b/saves/Level3-dialogue.txt new file mode 100644 index 0000000..b273a69 --- /dev/null +++ b/saves/Level3-dialogue.txt @@ -0,0 +1,20 @@ +$Villain +I am having a seizure. + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww \ No newline at end of file diff --git a/src/DialogueMenu.java b/src/DialogueMenu.java index ff8612f..c26a6bd 100644 --- a/src/DialogueMenu.java +++ b/src/DialogueMenu.java @@ -18,12 +18,16 @@ public class DialogueMenu extends TextBox implements Serializable { public DialogueMenu(int y, int yHeight, Font font, BufferedImageWrapper portrait, boolean isNarrator) { super(y, GamePanel.GAME_WIDTH - PORTRAIT_WIDTH - PADDING*3, yHeight, 0, font, null, null); PORTRAIT = portrait; + checkForNarrator(); + this.isNarrator = isNarrator; + } + + public void checkForNarrator() { if (isNarrator) { newX = PORTRAIT_WIDTH + PADDING*2; } else { newX = PADDING; } - this.isNarrator = isNarrator; } public void drawCenteredTextBox(Graphics g, String text, Color backgroundColor, Color textColor) { @@ -72,6 +76,7 @@ public class DialogueMenu extends TextBox implements Serializable { } public boolean draw(Graphics g, String text, Color backgroundColor, Color textColor) { + checkForNarrator(); if (frameCounter >= FREQUENCY) { frameCounter -= FREQUENCY; currentFrame += 1; diff --git a/src/LevelManager.java b/src/LevelManager.java index 1f135eb..688af19 100644 --- a/src/LevelManager.java +++ b/src/LevelManager.java @@ -1,7 +1,10 @@ +import javax.imageio.ImageIO; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import java.io.IOException; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; public class LevelManager implements Serializable { public static int level = 1; @@ -34,6 +37,16 @@ public class LevelManager implements Serializable { } try { MapReader.inputMap(filePath); + GameFrame.game.dialogueArray = new ArrayList(Arrays.asList(MapReader.inputDialogue(filePath))); + if (GameFrame.game.dialogueArray.get(0).contains("$Villain")) { + GameFrame.game.dialogueArray.remove(0); + GameFrame.game.dialogueMenu.isNarrator = false; + // TODO: move img path to GamePanel + GameFrame.game.dialogueMenu.PORTRAIT = new BufferedImageWrapper("img\\dialogue\\Bouncer.png"); + } + GameFrame.game.dialogueMenu.currentFrame = 0; + GameFrame.game.dialogueMenu.frameCounter = 0; + GameFrame.game.isDialogue = true; } catch (IOException | SpriteException | UnsupportedAudioFileException | LineUnavailableException e) { throw new RuntimeException(e); } diff --git a/src/MapReader.java b/src/MapReader.java index 762d0eb..6107da2 100644 --- a/src/MapReader.java +++ b/src/MapReader.java @@ -109,6 +109,12 @@ public class MapReader implements Serializable { x+=1; } } + + public static String[] inputDialogue(String mapFilePath) throws IOException { + String filePath = mapFilePath.replace(".txt", "-dialogue.txt"); + return FileManager.readFile(filePath).split("\n"); + } + public static void newTile(String filePath) throws IOException, SpriteException { GameFrame.game.map[x][y]=(new SingleTile(TileX,TileY, new BufferedImageWrapper((filePath)))); }