-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusic.java
More file actions
112 lines (90 loc) · 2.78 KB
/
Music.java
File metadata and controls
112 lines (90 loc) · 2.78 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
package game;
import javafx.scene.media.AudioClip;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
/**
* our music and sound effects
*
* @author FerrariHD
*
*/
public class Music {
static MediaPlayer mediaplayer;
static MediaPlayer mediaplayer2;
static MediaPlayer engineSound;
static AudioClip enterSound;
static AudioClip returnSound;
static AudioClip shot;
static AudioClip wallhit;
static AudioClip tankhit;
static AudioClip tankexplosion;
public void initSound() {
Media gameMusicFile = new Media(
getClass().getResource("AnOrangePlanet(loop).wav").toString());
Media musicMainMenuFile = new Media(
getClass().getResource("AnOrangePlanet-Percussion.wav").toString());
Media engineOneFile =
new Media(getClass().getResource("engine.wav").toString());
mediaplayer = new MediaPlayer(musicMainMenuFile);
mediaplayer.setVolume(0.7);
mediaplayer.setCycleCount(MediaPlayer.INDEFINITE);
mediaplayer2 = new MediaPlayer(gameMusicFile);
mediaplayer2.setVolume(0.7);
mediaplayer2.setCycleCount(MediaPlayer.INDEFINITE);
engineSound = new MediaPlayer(engineOneFile);
engineSound.setVolume(1);
engineSound.setCycleCount(MediaPlayer.INDEFINITE);
enterSound = new AudioClip(getClass().getResource("enter.wav").toString());
enterSound.setVolume(0.3);
returnSound = new AudioClip(getClass().getResource("esc.wav").toString());
returnSound.setVolume(0.3);
shot = new AudioClip(getClass().getResource("shot.wav").toString());
shot.setVolume(1);
wallhit = new AudioClip(getClass().getResource("wallHit2.wav").toString());
wallhit.setVolume(0.5);
tankhit = new AudioClip(getClass().getResource("tankHit.wav").toString());
tankhit.setVolume(0.8);
tankexplosion =
new AudioClip(getClass().getResource("tankExplosion.wav").toString());
tankexplosion.setVolume(0.5);
}
public static void chooseMusic(int number) {
switch (number) {
case 0:
mediaplayer.play();
break;
case 1:
mediaplayer.stop();
mediaplayer2.play();
break;
}
}
public static void enterSound() {
enterSound.play();
}
/**
* when we click "back"
*/
public static void returnSound() {
returnSound.play();
}
public static void shot() {
shot.play();
}
public static void wallHit() {
wallhit.play();
}
public static void tankHit() {
tankhit.play();
}
public static void tankExplosion() {
tankexplosion.play();
}
public static void activateEngineSound(boolean status) {
if (status == true) {
engineSound.play();
} else {
engineSound.stop();
}
}
}