Implemented background music
This commit is contained in:
parent
a17de768eb
commit
c75c277403
@ -1,14 +1,19 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Display extends JPanel{
|
||||
private List<Drawer> visuals;
|
||||
private Clip clip;
|
||||
|
||||
public Display() {
|
||||
visuals = new ArrayList<>();
|
||||
@ -25,6 +30,22 @@ public class Display extends JPanel{
|
||||
repaint();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void startMusic() {
|
||||
try(AudioInputStream ais =
|
||||
AudioSystem.getAudioInputStream(new File("tomboy2.wav"))) {
|
||||
clip = AudioSystem.getClip();
|
||||
clip.open(ais);
|
||||
clip.start();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopMusic() {
|
||||
clip.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
|
@ -74,6 +74,8 @@ public class Game {
|
||||
display.addVisual(new PlayerDrawer(jaffa));
|
||||
display.addVisual(new PlayerBaseDrawer(replicator));
|
||||
|
||||
display.startMusic();
|
||||
|
||||
flowoftime = new FlowOfTime();
|
||||
flowoftime.start(dungeon.getTimeLimit());
|
||||
}
|
||||
@ -101,6 +103,8 @@ public class Game {
|
||||
Application.frameInstance.backToMapSelection();
|
||||
break;
|
||||
}
|
||||
|
||||
display.stopMusic();
|
||||
}
|
||||
|
||||
public void moveONeill(Direction direction) {
|
||||
|
BIN
tomboy2.wav
Normal file
BIN
tomboy2.wav
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user