let there be sound
This commit is contained in:
parent
25a20341ea
commit
489ddd6f28
@ -92,6 +92,22 @@ public class ChestCell extends InteractionCell {
|
||||
else if (data.equals("<item>")) {
|
||||
putItemToInventory();
|
||||
}
|
||||
else if (data.contains("<voice>")) {
|
||||
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("<sound>")) {
|
||||
String[] sound = data.split(" ");
|
||||
dialog.getSoundManager().playSound(sound[1], Float.parseFloat(sound[2]));
|
||||
readNextLine();
|
||||
}
|
||||
else {
|
||||
if (data.contains("<br/>"))
|
||||
data = "<html>" + data + "</html>";
|
||||
|
||||
@ -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; }
|
||||
}
|
||||
|
||||
@ -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("<voice>")) {
|
||||
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("<sound>")) {
|
||||
String[] sound = data.split(" ");
|
||||
dialog.getSoundManager().playSound(sound[1], Float.parseFloat(sound[2]));
|
||||
readNextLine();
|
||||
}
|
||||
else if (data.contains("<cameraFree>")) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"))
|
||||
|
||||
@ -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("<html>"))
|
||||
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; }
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
53
src/main/java/ruscz/game/gameOfProd/Sounds/SoundManager.java
Normal file
53
src/main/java/ruscz/game/gameOfProd/Sounds/SoundManager.java
Normal file
@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 -> {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
<image> boy2-face.png
|
||||
<voice> voice5
|
||||
... no, I've not heard anything from him.
|
||||
<image> girl1-face.png
|
||||
I mean he would't just vanish, right?
|
||||
<voice> voice2
|
||||
I mean he wouldn't just vanish, right?
|
||||
<image> boy2-face.png
|
||||
<voice> voice5
|
||||
Beats me.
|
||||
<end>
|
||||
@ -1,3 +1,4 @@
|
||||
<image> boy3-face.png
|
||||
<voice> voice3
|
||||
*slaps rack*<br/>this bad boy can fit so many minecraft servers
|
||||
<end>
|
||||
@ -1,8 +1,9 @@
|
||||
<cameraFree> 100 0 35
|
||||
<wait>
|
||||
<image> boss-face.png
|
||||
<voice> voice4
|
||||
Oh, hi Mark.
|
||||
I know, this is on very short notice<br/>but as you've probably heard,<br/>we kinda need someone on the ruscz.game.gameOfProd.Game of Prod.
|
||||
I know, this is on very short notice<br/>but as you've probably heard,<br/>we kinda need someone on the Game of Prod.
|
||||
And that someone is gonna be,<br/>you guessed it, you. You start by tomorrow.
|
||||
You can go now.
|
||||
Bye.
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
<voice> null
|
||||
<sound> metalPot2.wav -10.0f
|
||||
Just like the trash you are..
|
||||
<item>
|
||||
<end>
|
||||
@ -0,0 +1,95 @@
|
||||
<map>
|
||||
<mapName>m1</mapName>
|
||||
<events>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m2</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>7</x>
|
||||
<y>2</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m3</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>2</x>
|
||||
<y>5</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m4</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>3</x>
|
||||
<y>3</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>m6</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>11</x>
|
||||
<y>11</y>
|
||||
<active>true</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>tutorial</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>11</x>
|
||||
<y>6</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>openspace</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>7</x>
|
||||
<y>4</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
<chest>
|
||||
<x>15</x>
|
||||
<y>7</y>
|
||||
<active>true</active>
|
||||
</chest>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>office</mapName>
|
||||
<events>
|
||||
<chest>
|
||||
<x>1</x>
|
||||
<y>9</y>
|
||||
<active>true</active>
|
||||
</chest>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>boss</mapName>
|
||||
<events>
|
||||
<trigger>
|
||||
<x>4</x>
|
||||
<y>18</y>
|
||||
<active>false</active>
|
||||
</trigger>
|
||||
</events>
|
||||
</map>
|
||||
<map>
|
||||
<mapName>treasure</mapName>
|
||||
<events>
|
||||
</events>
|
||||
</map>
|
||||
@ -0,0 +1,6 @@
|
||||
<location>
|
||||
<map>openspace</map>
|
||||
<x>8</x>
|
||||
<y>15</y>
|
||||
<direction>3</direction>
|
||||
</location>
|
||||
@ -0,0 +1 @@
|
||||
TODO: Village
|
||||
BIN
src/main/resources/sounds/doorLocked.wav
Normal file
BIN
src/main/resources/sounds/doorLocked.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/metalPot2.wav
Normal file
BIN
src/main/resources/sounds/metalPot2.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/qubodup-DoorClose02-changed.wav
Normal file
BIN
src/main/resources/sounds/qubodup-DoorClose02-changed.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/qubodup-DoorOpen01-changed.wav
Normal file
BIN
src/main/resources/sounds/qubodup-DoorOpen01-changed.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/voice1.wav
Normal file
BIN
src/main/resources/sounds/voice1.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/voice2.wav
Normal file
BIN
src/main/resources/sounds/voice2.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/voice3.wav
Normal file
BIN
src/main/resources/sounds/voice3.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/voice4.wav
Normal file
BIN
src/main/resources/sounds/voice4.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/voice5.wav
Normal file
BIN
src/main/resources/sounds/voice5.wav
Normal file
Binary file not shown.
BIN
src/main/resources/sounds/wood01.wav
Normal file
BIN
src/main/resources/sounds/wood01.wav
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user