forked from dtschust/javapacman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameSounds.java
79 lines (66 loc) · 2.03 KB
/
GameSounds.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Sin modificar, todos los creditos a: */
/* Drew Schuster */
import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
/* This class controls all sound effects*/
public class GameSounds{
Clip nomNom;
Clip newGame;
Clip death;
/* Keeps track of whether or not the eating sound is playing*/
boolean stopped;
/* Initialize audio files */
public GameSounds(){
stopped=true;
URL url;
AudioInputStream audioIn;
try{
// Pacman eating sound
url = this.getClass().getClassLoader().getResource("sounds/nomnom.wav");
audioIn = AudioSystem.getAudioInputStream(url);
nomNom = AudioSystem.getClip();
nomNom.open(audioIn);
// newGame
url = this.getClass().getClassLoader().getResource("sounds/newGame.wav");
audioIn = AudioSystem.getAudioInputStream(url);
newGame = AudioSystem.getClip();
newGame.open(audioIn);
// death
url = this.getClass().getClassLoader().getResource("sounds/death.wav");
audioIn = AudioSystem.getAudioInputStream(url);
death = AudioSystem.getClip();
death.open(audioIn);
}catch(Exception e){
System.out.println("Mierda");
}
}
/* Play pacman eating sound */
public void nomNom(){
/* If it's already playing, don't start it playing again!*/
if (!stopped)
return;
stopped=false;
nomNom.stop();
nomNom.setFramePosition(0);
nomNom.loop(Clip.LOOP_CONTINUOUSLY);
}
/* Stop pacman eating sound */
public void nomNomStop(){
stopped=true;
nomNom.stop();
nomNom.setFramePosition(0);
}
/* Play new game sound */
public void newGame(){
newGame.stop();
newGame.setFramePosition(0);
newGame.start();
}
/* Play pacman death sound */
public void death(){
death.stop();
death.setFramePosition(0);
death.start();
}
}