Merge remote-tracking branch 'origin/master'

master
Chara1236 2022-06-20 21:22:53 -04:00
commit ca00976a96
4 changed files with 19 additions and 11 deletions

View File

@ -1,4 +1,3 @@
$Villain
Oh you made it past the first real level Oh you made it past the first real level
Feeling acomplished aren't you... Feeling acomplished aren't you...

Binary file not shown.

View File

@ -19,6 +19,7 @@ public class DialogueMenu extends TextBox implements Serializable {
public int currentFrame = 0; public int currentFrame = 0;
public int frameCounter = 0; public int frameCounter = 0;
public boolean isNarrator; public boolean isNarrator;
public SoundWrapper currentSound;
public DialogueMenu(int y, int yHeight, Font font, BufferedImageWrapper portrait, boolean isNarrator) { 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); super(y, GamePanel.GAME_WIDTH - PORTRAIT_WIDTH - PADDING*3, yHeight, 0, font, null, null);
@ -104,11 +105,13 @@ public class DialogueMenu extends TextBox implements Serializable {
if (frameCounter >= FREQUENCY) { if (frameCounter >= FREQUENCY) {
frameCounter -= FREQUENCY; frameCounter -= FREQUENCY;
currentFrame += 1; currentFrame += 1;
// play dialogue sound // play dialogue sound if it is not already playing
try { if (currentSound == null || !currentSound.sound.clip.isOpen()) {
UtilityFunction.playSound("sound/pen.wav"); try {
} catch (UnsupportedAudioFileException | LineUnavailableException | IOException e) { currentSound = UtilityFunction.playSound("sound/pen.wav");
throw new RuntimeException(e); } catch (UnsupportedAudioFileException | LineUnavailableException | IOException e) {
throw new RuntimeException(e);
}
} }
} }
// set font of string to be drawn // set font of string to be drawn
@ -119,6 +122,11 @@ public class DialogueMenu extends TextBox implements Serializable {
// if the text has been completely drawn (nothing left to animate), return true // if the text has been completely drawn (nothing left to animate), return true
if (currentFrame >= text.length()) { if (currentFrame >= text.length()) {
currentFrame = 0; currentFrame = 0;
// if the text is not being animated, there is no reason to play the sound either, so it is closed and then dereferenced
if (currentSound != null) {
currentSound.sound.close();
currentSound = null;
}
return true; return true;
} else { // otherwise, return false } else { // otherwise, return false
return false; return false;

View File

@ -44,14 +44,15 @@ public final class UtilityFunction {
} }
// start playing a sound that is located at filePath // start playing a sound that is located at filePath
public static void playSound(String filePath) throws UnsupportedAudioFileException, LineUnavailableException, IOException { public static SoundWrapper playSound(String filePath) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
Sound sound = new Sound(filePath); SoundWrapper sound = new SoundWrapper(filePath);
sound.clip.addLineListener(e -> { sound.sound.clip.addLineListener(e -> {
// close clip after sound is done playing // close clip after sound is done playing
if (e.getType() == LineEvent.Type.STOP) { if (e.getType() == LineEvent.Type.STOP) {
sound.close(); sound.sound.close();
} }
}); });
sound.start(); sound.sound.start();
return sound;
} }
} }