diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/ChestCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/ChestCell.java index 646a7d4..c871eae 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/ChestCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/ChestCell.java @@ -92,6 +92,22 @@ public class ChestCell extends InteractionCell { else if (data.equals("")) { putItemToInventory(); } + else if (data.contains("")) { + String[] voice = data.split(" "); + if (!voice[1].equals("null")) { + dialog.setVoiceover(true); + dialog.setVoice(voice[1]); + } + else { + dialog.setVoiceover(false); + } + readNextLine(); + } + else if (data.contains("")) { + String[] sound = data.split(" "); + dialog.getSoundManager().playSound(sound[1], Float.parseFloat(sound[2])); + readNextLine(); + } else { if (data.contains("
")) data = "" + data + ""; diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java index 676ba89..3a6bcc5 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/DoorCell.java @@ -11,12 +11,15 @@ public class DoorCell extends InteractionCell { private boolean isOpen; private boolean isLocked; private boolean directionVert; + private String sound; + private float volume; public DoorCell(int x, int y, boolean directionVert, String message, Dialog dialog, ImageCell imageCell, WindowOfFreeMove window) { super(x, y, message, dialog, imageCell, window, true); this.isOpen = false; this.isLocked = true; this.directionVert = directionVert; + setSound(); } public DoorCell(int x, int y, boolean directionVert, ImageCell imageCell, WindowOfFreeMove window) { @@ -24,6 +27,7 @@ public class DoorCell extends InteractionCell { this.isOpen = false; this.isLocked = false; this.directionVert = directionVert; + setSound(); } @Override @@ -37,15 +41,32 @@ public class DoorCell extends InteractionCell { @Override public void useItem(Item item) { isLocked = false; + setSound(); super.useItem(item); } + private void setSound() { + if (isOpen) { + sound = "qubodup-DoorOpen01-changed.wav"; + volume = -8.0f; + } + else if (!isOpen && !isLocked) { + sound = "qubodup-DoorClose02-changed.wav"; + volume = -8.0f; + } + else if (isLocked) { + sound = "doorLocked.wav"; + volume = -10.0f; + } + } + public boolean isOpen() { return isOpen; } public void setOpen(boolean open) { isOpen = open; + setSound(); } public boolean isLocked() { @@ -54,5 +75,10 @@ public class DoorCell extends InteractionCell { public void setLocked(boolean locked) { isLocked = locked; + setSound(); } + + public String getSound() { return sound; } + + public float getVolume() { return volume; } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java index 0fe054f..f6726ad 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/InteractionCell.java @@ -13,7 +13,6 @@ import java.awt.*; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; -import java.util.concurrent.TimeUnit; public class InteractionCell extends Cell { protected String message; @@ -78,6 +77,22 @@ public class InteractionCell extends Cell { } readNextLine(); } + else if (data.contains("")) { + String[] voice = data.split(" "); + if (!voice[1].equals("null")) { + dialog.setVoiceover(true); + dialog.setVoice(voice[1]); + } + else { + dialog.setVoiceover(false); + } + readNextLine(); + } + else if (data.contains("")) { + String[] sound = data.split(" "); + dialog.getSoundManager().playSound(sound[1], Float.parseFloat(sound[2])); + readNextLine(); + } else if (data.contains("")) { String[] cameraInfo = data.split(" "); window.getCamera().setCameraStart(); @@ -219,6 +234,7 @@ public class InteractionCell extends Cell { } else if (i == 11) { window.getMusicManager().playMusic(); + window.getMusicManager().fadeIn(10); timer.stop(); } } diff --git a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java index e600fd4..acb45a2 100644 --- a/src/main/java/ruscz/game/gameOfProd/Cells/Person.java +++ b/src/main/java/ruscz/game/gameOfProd/Cells/Person.java @@ -99,14 +99,19 @@ public class Person extends Cell { else if (isDoorInFront(x,y,directionSight)) { DoorCell door = map.findDoorByXY(x, y, directionSight); if (!door.isLocked() && !isInEvent) { - if (door.isOpen()) + if (door.isOpen()) { door.setOpen(false); - else + map.getSoundManager().playSound(door.getSound(), door.getVolume()); + } + else { door.setOpen(true); + map.getSoundManager().playSound(door.getSound(), door.getVolume()); + } } else if (!isInEvent) { isInEvent = true; door.startEvent(); + map.getSoundManager().playSound(door.getSound(), door.getVolume()); } else { door.readNextLine(); @@ -215,6 +220,9 @@ public class Person extends Cell { else { isMoving = false; } + if (!map.getName().equals("tutorial")){ + map.getSoundManager().playSoundRepeatedly("wood01.wav", 20, -7.0f); + } } else { distanceOfAnimation = getSize(); if (map.getName().equals("tutorial")) diff --git a/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java b/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java index 7c1d8e9..1f92af4 100644 --- a/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java +++ b/src/main/java/ruscz/game/gameOfProd/Dialog/Dialog.java @@ -1,6 +1,7 @@ package ruscz.game.gameOfProd.Dialog; import ruscz.game.gameOfProd.Image.ImageDialog; +import ruscz.game.gameOfProd.Sounds.SoundManager; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import javax.swing.*; @@ -16,6 +17,9 @@ public class Dialog { private DialogBar dialogBar; private int charNumber; private boolean timerIsRunning; + private SoundManager soundManager; + private String voice; + private boolean voiceover; Dialog(String text, DialogBar dialogBar) { this.text = text; @@ -35,6 +39,9 @@ public class Dialog { public Dialog(DialogBar dialogBar) { this.dialogBar = dialogBar; charNumber = 0; + soundManager = new SoundManager(); + voice = "voice1"; + voiceover = true; } @@ -80,9 +87,11 @@ public class Dialog { if (text.contains("")) charNumber = 6; dialogBar.setVisible(true); - timer = new Timer(20, new ActionListener() { + timer = new Timer(30, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { + if (voiceover) + soundManager.playSound(voice + ".wav", -20.0f); showByChar(); dialogBar.repaint(); timerIsRunning = timer.isRunning(); @@ -123,5 +132,11 @@ public class Dialog { public boolean getTimerIsRunning() { return timerIsRunning; } + + public void setVoice(String voice) { this.voice = voice; } + + public SoundManager getSoundManager() { return soundManager; } + + public void setVoiceover(boolean voiceover) { this.voiceover = voiceover; } } diff --git a/src/main/java/ruscz/game/gameOfProd/Map/Map.java b/src/main/java/ruscz/game/gameOfProd/Map/Map.java index fa5c5e0..d49f4eb 100644 --- a/src/main/java/ruscz/game/gameOfProd/Map/Map.java +++ b/src/main/java/ruscz/game/gameOfProd/Map/Map.java @@ -3,8 +3,7 @@ package ruscz.game.gameOfProd.Map; import ruscz.game.gameOfProd.Cells.*; import ruscz.game.gameOfProd.Dialog.Dialog; import ruscz.game.gameOfProd.Image.ImageCell; -import ruscz.game.gameOfProd.Inventory.Item; -import ruscz.game.gameOfProd.Inventory.ItemAction; +import ruscz.game.gameOfProd.Sounds.SoundManager; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; import java.io.File; @@ -26,6 +25,7 @@ public class Map { private int idExit; private ImageCell imageCell; private int[] canvasSize; + private SoundManager soundManager; private static Scanner scanner; @@ -42,6 +42,7 @@ public class Map { this.mapArray = mapArray; person = new Person(this); canvasSize = new int[2]; + soundManager = new SoundManager(); } public static Map findMapByName(String nameOfMap, WindowOfFreeMove window) { @@ -264,6 +265,7 @@ public class Map { public int[] getCanvasSize() { return canvasSize; } + public SoundManager getSoundManager() { return soundManager; } public boolean isBusyCell(int x, int y) { for (Block cell : block) { diff --git a/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java b/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java index 48631c0..2e76746 100644 --- a/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java +++ b/src/main/java/ruscz/game/gameOfProd/Sounds/MusicManager.java @@ -1,29 +1,37 @@ package ruscz.game.gameOfProd.Sounds; import javax.sound.sampled.*; +import javax.swing.*; import java.io.File; import java.io.IOException; public class MusicManager { private String musicName; + private float volume; + private float maxVolume; + private FloatControl gainControl; + private Timer timerIn; + private Timer timerOut; + private Clip clip; - public MusicManager(String name){ + public MusicManager(String name, float volume){ musicName = name; + this.maxVolume = volume; + this.volume = -40.0f; } public void playMusic(){ AudioInputStream audioIn; try { - audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/" + musicName)); - Clip clip; + audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/music/" + musicName)); clip = AudioSystem.getClip(); if (clip != null) { clip.open(audioIn); } if (clip != null) { - FloatControl gainControl = + gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); - gainControl.setValue(-25.0f); + gainControl.setValue(volume); clip.loop(1000); clip.start(); } @@ -31,4 +39,35 @@ public class MusicManager { e.printStackTrace(); } } + + public void stopMusic() { + timerOut.stop(); + clip.stop(); + volume = -40.0f; + } + + public void fadeIn(int delay) { + timerIn = new Timer(delay, actionEvent -> { + if (volume < maxVolume) { + volume += 0.1f; + gainControl.setValue(volume); + } + }); + timerIn.start(); + } + + public void fadeOut(int delay) { + timerOut = new Timer(delay, actionEvent -> { + if (volume > -79.0f) { + volume -= 0.1f; + gainControl.setValue(volume); + } + else { + stopMusic(); + } + System.out.println(volume); + }); + timerIn.stop(); + timerOut.start(); + } } diff --git a/src/main/java/ruscz/game/gameOfProd/Sounds/SoundManager.java b/src/main/java/ruscz/game/gameOfProd/Sounds/SoundManager.java new file mode 100644 index 0000000..885a12a --- /dev/null +++ b/src/main/java/ruscz/game/gameOfProd/Sounds/SoundManager.java @@ -0,0 +1,53 @@ +package ruscz.game.gameOfProd.Sounds; + +import javax.sound.sampled.*; +import java.io.File; +import java.io.IOException; + +public class SoundManager { + private FloatControl gainControl; + private Clip clip; + private int delay; + + public SoundManager() { + this.delay = 0; + } + + public void playSound(String name, float volume){ + AudioInputStream audioIn; + try { + audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/sounds/" + name)); + clip = AudioSystem.getClip(); + if (clip != null) { + clip.open(audioIn); + } + if (clip != null) { + gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); + gainControl.setValue(volume); + clip.start(); + } + } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { + e.printStackTrace(); + } + } + + public void playSoundRepeatedly(String name, int delay, float volume) { + if (this.delay == delay) { + AudioInputStream audioIn; + try { + audioIn = AudioSystem.getAudioInputStream(new File("src/main/resources/sounds/" + name)); + clip = AudioSystem.getClip(); + clip.open(audioIn); + gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); + gainControl.setValue(volume); + clip.start(); + } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { + e.printStackTrace(); + } + this.delay = 0; + } + else { + this.delay++; + } + } +} diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index eae4d24..542dca3 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -174,7 +174,7 @@ public class WindowOfFreeMove extends JLayeredPane { mapManager.createMap(); isReadyToPaint = true; - musicManager = new MusicManager("Town3.wav"); + musicManager = new MusicManager("Town3.wav", -25.0f); // musicManager.playMusic(); Timer timer = new Timer(10, actionEvent -> { diff --git a/src/main/resources/dialogs/dialog.txt b/src/main/resources/dialogs/dialog.txt index 75bb898..adff964 100644 --- a/src/main/resources/dialogs/dialog.txt +++ b/src/main/resources/dialogs/dialog.txt @@ -1,7 +1,10 @@ boy2-face.png + voice5 ... no, I've not heard anything from him. girl1-face.png -I mean he would't just vanish, right? + voice2 +I mean he wouldn't just vanish, right? boy2-face.png + voice5 Beats me. \ No newline at end of file diff --git a/src/main/resources/dialogs/minecraft.txt b/src/main/resources/dialogs/minecraft.txt index 009e3aa..fe1de74 100644 --- a/src/main/resources/dialogs/minecraft.txt +++ b/src/main/resources/dialogs/minecraft.txt @@ -1,3 +1,4 @@ boy3-face.png + voice3 *slaps rack*
this bad boy can fit so many minecraft servers \ No newline at end of file diff --git a/src/main/resources/dialogs/ohhimark.txt b/src/main/resources/dialogs/ohhimark.txt index e19a5db..18283c6 100644 --- a/src/main/resources/dialogs/ohhimark.txt +++ b/src/main/resources/dialogs/ohhimark.txt @@ -1,8 +1,9 @@ 100 0 35 boss-face.png + voice4 Oh, hi Mark. -I know, this is on very short notice
but as you've probably heard,
we kinda need someone on the ruscz.game.gameOfProd.Game of Prod. +I know, this is on very short notice
but as you've probably heard,
we kinda need someone on the Game of Prod. And that someone is gonna be,
you guessed it, you. You start by tomorrow. You can go now. Bye. diff --git a/src/main/resources/dialogs/trash.txt b/src/main/resources/dialogs/trash.txt index bdd0270..a774c23 100644 --- a/src/main/resources/dialogs/trash.txt +++ b/src/main/resources/dialogs/trash.txt @@ -1,3 +1,5 @@ + null + metalPot2.wav -10.0f Just like the trash you are.. \ No newline at end of file diff --git a/src/main/resources/Town1.wav b/src/main/resources/music/Town1.wav similarity index 100% rename from src/main/resources/Town1.wav rename to src/main/resources/music/Town1.wav diff --git a/src/main/resources/Town3.wav b/src/main/resources/music/Town3.wav similarity index 100% rename from src/main/resources/Town3.wav rename to src/main/resources/music/Town3.wav diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index e69de29..b0ed67f 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -0,0 +1,95 @@ + + m1 + + + + + m2 + + + 7 + 2 + true + + + + + m3 + + + 2 + 5 + true + + + + + m4 + + + 3 + 3 + true + + + + + m6 + + + 11 + 11 + true + + + + + tutorial + + + 11 + 6 + false + + + + + openspace + + + 7 + 4 + false + + + 15 + 7 + true + + + + + office + + + 1 + 9 + true + + + + + boss + + + 4 + 18 + false + + + + + treasure + + + diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index e69de29..f083d14 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -0,0 +1,6 @@ + + openspace + 8 + 15 + 3 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village.txt b/src/main/resources/save/savedGame/village.txt index e69de29..1b4bc7b 100644 --- a/src/main/resources/save/savedGame/village.txt +++ b/src/main/resources/save/savedGame/village.txt @@ -0,0 +1 @@ +TODO: Village \ No newline at end of file diff --git a/src/main/resources/sounds/doorLocked.wav b/src/main/resources/sounds/doorLocked.wav new file mode 100644 index 0000000..7094e91 Binary files /dev/null and b/src/main/resources/sounds/doorLocked.wav differ diff --git a/src/main/resources/sounds/metalPot2.wav b/src/main/resources/sounds/metalPot2.wav new file mode 100644 index 0000000..f651c08 Binary files /dev/null and b/src/main/resources/sounds/metalPot2.wav differ diff --git a/src/main/resources/sounds/qubodup-DoorClose02-changed.wav b/src/main/resources/sounds/qubodup-DoorClose02-changed.wav new file mode 100644 index 0000000..39b8c83 Binary files /dev/null and b/src/main/resources/sounds/qubodup-DoorClose02-changed.wav differ diff --git a/src/main/resources/sounds/qubodup-DoorOpen01-changed.wav b/src/main/resources/sounds/qubodup-DoorOpen01-changed.wav new file mode 100644 index 0000000..eed323c Binary files /dev/null and b/src/main/resources/sounds/qubodup-DoorOpen01-changed.wav differ diff --git a/src/main/resources/sounds/voice1.wav b/src/main/resources/sounds/voice1.wav new file mode 100644 index 0000000..84fe4cd Binary files /dev/null and b/src/main/resources/sounds/voice1.wav differ diff --git a/src/main/resources/sounds/voice2.wav b/src/main/resources/sounds/voice2.wav new file mode 100644 index 0000000..b5dc1ed Binary files /dev/null and b/src/main/resources/sounds/voice2.wav differ diff --git a/src/main/resources/sounds/voice3.wav b/src/main/resources/sounds/voice3.wav new file mode 100644 index 0000000..15590a2 Binary files /dev/null and b/src/main/resources/sounds/voice3.wav differ diff --git a/src/main/resources/sounds/voice4.wav b/src/main/resources/sounds/voice4.wav new file mode 100644 index 0000000..97a2ce3 Binary files /dev/null and b/src/main/resources/sounds/voice4.wav differ diff --git a/src/main/resources/sounds/voice5.wav b/src/main/resources/sounds/voice5.wav new file mode 100644 index 0000000..8324ff9 Binary files /dev/null and b/src/main/resources/sounds/voice5.wav differ diff --git a/src/main/resources/sounds/wood01.wav b/src/main/resources/sounds/wood01.wav new file mode 100644 index 0000000..30d5b9c Binary files /dev/null and b/src/main/resources/sounds/wood01.wav differ