Implemented background music

This commit is contained in:
Bokros Bálint 2016-05-14 00:14:49 +02:00
parent a17de768eb
commit c75c277403
3 changed files with 25 additions and 0 deletions

View File

@ -1,14 +1,19 @@
package cicaprojekt; package cicaprojekt;
import java.awt.Graphics; import java.awt.Graphics;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JPanel; import javax.swing.JPanel;
public class Display extends JPanel{ public class Display extends JPanel{
private List<Drawer> visuals; private List<Drawer> visuals;
private Clip clip;
public Display() { public Display() {
visuals = new ArrayList<>(); visuals = new ArrayList<>();
@ -26,6 +31,22 @@ public class Display extends JPanel{
setVisible(true); 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 @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);

View File

@ -74,6 +74,8 @@ public class Game {
display.addVisual(new PlayerDrawer(jaffa)); display.addVisual(new PlayerDrawer(jaffa));
display.addVisual(new PlayerBaseDrawer(replicator)); display.addVisual(new PlayerBaseDrawer(replicator));
display.startMusic();
flowoftime = new FlowOfTime(); flowoftime = new FlowOfTime();
flowoftime.start(dungeon.getTimeLimit()); flowoftime.start(dungeon.getTimeLimit());
} }
@ -101,6 +103,8 @@ public class Game {
Application.frameInstance.backToMapSelection(); Application.frameInstance.backToMapSelection();
break; break;
} }
display.stopMusic();
} }
public void moveONeill(Direction direction) { public void moveONeill(Direction direction) {

BIN
tomboy2.wav Normal file

Binary file not shown.