Merge remote-tracking branch 'origin/master'
commit
ca00976a96
|
@ -1,4 +1,3 @@
|
|||
$Villain
|
||||
Oh you made it past the first real level
|
||||
Feeling acomplished aren't you...
|
||||
|
||||
|
|
BIN
sound/pen.wav
BIN
sound/pen.wav
Binary file not shown.
|
@ -19,6 +19,7 @@ public class DialogueMenu extends TextBox implements Serializable {
|
|||
public int currentFrame = 0;
|
||||
public int frameCounter = 0;
|
||||
public boolean isNarrator;
|
||||
public SoundWrapper currentSound;
|
||||
|
||||
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);
|
||||
|
@ -104,13 +105,15 @@ public class DialogueMenu extends TextBox implements Serializable {
|
|||
if (frameCounter >= FREQUENCY) {
|
||||
frameCounter -= FREQUENCY;
|
||||
currentFrame += 1;
|
||||
// play dialogue sound
|
||||
// play dialogue sound if it is not already playing
|
||||
if (currentSound == null || !currentSound.sound.clip.isOpen()) {
|
||||
try {
|
||||
UtilityFunction.playSound("sound/pen.wav");
|
||||
currentSound = UtilityFunction.playSound("sound/pen.wav");
|
||||
} catch (UnsupportedAudioFileException | LineUnavailableException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// set font of string to be drawn
|
||||
g.setFont(font);
|
||||
drawCenteredTextBox(g, text, backgroundColor, textColor);
|
||||
|
@ -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 (currentFrame >= text.length()) {
|
||||
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;
|
||||
} else { // otherwise, return false
|
||||
return false;
|
||||
|
|
|
@ -44,14 +44,15 @@ public final class UtilityFunction {
|
|||
}
|
||||
|
||||
// start playing a sound that is located at filePath
|
||||
public static void playSound(String filePath) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||
Sound sound = new Sound(filePath);
|
||||
sound.clip.addLineListener(e -> {
|
||||
public static SoundWrapper playSound(String filePath) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||
SoundWrapper sound = new SoundWrapper(filePath);
|
||||
sound.sound.clip.addLineListener(e -> {
|
||||
// close clip after sound is done playing
|
||||
if (e.getType() == LineEvent.Type.STOP) {
|
||||
sound.close();
|
||||
sound.sound.close();
|
||||
}
|
||||
});
|
||||
sound.start();
|
||||
sound.sound.start();
|
||||
return sound;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue