forked from dtschust/javapacman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameSounds.java
More file actions
69 lines (58 loc) · 1.82 KB
/
GameSounds.java
File metadata and controls
69 lines (58 loc) · 1.82 KB
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
/* Drew Schuster */
import java.net.URL;
import javax.sound.sampled.*;
public class GameSounds{
Clip nomNom;
Clip newGame;
Clip death;
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){}
}
/* Eating sound */
public void nomNom(){
if (!stopped) return;
stopped=false;
nomNom.stop();
nomNom.setFramePosition(0);
nomNom.loop(Clip.LOOP_CONTINUOUSLY);
}
/* Stop eating sound */
public void nomNomStop(){
stopped=true;
nomNom.stop();
nomNom.setFramePosition(0);
}
/* New Game sound */
public void newGame(){
newGame.stop();
newGame.setFramePosition(0);
newGame.start();
}
/* Pacman death sound */
public void death(){
death.stop();
death.setFramePosition(0);
death.start();
}
}