-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSoundEffect.java
More file actions
210 lines (178 loc) · 5.98 KB
/
SoundEffect.java
File metadata and controls
210 lines (178 loc) · 5.98 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package engine;
import java.io.File;
import java.util.TimerTask;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.AudioInputStream;
import java.util.Timer;
public class SoundEffect {
File shipshootingsound = new File("sound/soundEffect/Shipshooting.wav");
File shipdestructionsound = new File("sound/soundEffect/Shipdestruction.wav");
File shipcollisionsound = new File("sound/soundEffect/Shipcollision.wav");
File enemydestructionsound = new File("sound/soundEffect/Enemydestruction.wav");
File enemyshootingsound = new File("sound/soundEffect/Enemyshooting.wav");
File buttonclicksound = new File("sound/soundEffect/ButtonClick.wav");
File spacebuttonsound = new File("sound/soundEffect/SpaceButton.wav");
File stagechangesound = new File("sound/soundEffect/StageChange.wav");
File initialStartSound = new File("sound/soundEffect/initialStart.wav");
File startSound = new File("sound/soundEffect/start.wav");
/**
* Play ship's shooting sound
*/
public void playStageChangeSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(stagechangesound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Stage change sound does not played."); }
}
public void playShipShootingSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(shipshootingsound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Missile shooting sound does not played."); }
}
/**
* Play ship's destruction sound
*/
public void playShipDestructionSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(shipdestructionsound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Ship's destroyed sound does not played."); }
}
/**
* Play ship's collision sound
*/
public void playShipCollisionSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(shipcollisionsound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Ship's attacked sound does not played."); }
}
/**
* Play enemy's destruction sound
*/
public void playEnemyDestructionSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(enemydestructionsound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Enemy's destroyed sound does not played."); }
}
/**
* Play enemy's shooting sound
*/
public void playEnemyShootingSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(enemyshootingsound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Enemy's bullet sound does not played."); }
}
// sound for button moving sound
public void playButtonClickSound() {
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(buttonclicksound));
clip.start();
Thread.sleep(1);
}
catch(Exception e) { System.err.println("SOUND ERROR: Button Click sound error."); }
}
// sound for spacebar key
public void playSpaceButtonSound() {
try {
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(spacebuttonsound));
clip.start();
Thread.sleep(1);
} catch (Exception e) {
System.err.println("SOUND ERROR: Space Key sound error.");
}
}
public void SoundEffect_play(){
}
public void SoundEffect_stop(){
}
/**
* Play initial game start sound
*
*
*/
public void initialStartSound() {
try {
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(initialStartSound));
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Play game start sound
*
*
*/
public void startSound() {
try {
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(startSound));
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void playInitialStartSoundWithDelay() {
Timer timer = new Timer();
timer.schedule(new InitialStartSoundTask(), 2000); // 2000ms = 2 sec
}
class InitialStartSoundTask extends TimerTask {
@Override
public void run() {
initialStartSound();
}
}
/**
* Play Enemyshipspecial's destruction sound
*/
public void enemyshipspecialDestructionSound(){
try {
String soundFilePath = "sound/soundEffect/enemyshipspecialdestructionsound.wav";
File soundFile = new File(soundFilePath).getAbsoluteFile();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile.getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
// public void play() {
// if (clip != null) {
// clip.setFramePosition(0);
// clip.start();
// }
// }
//
// public void stop() {
// if (clip != null) {
// clip.stop();
// }
// }
}