-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundManager.java
executable file
·108 lines (95 loc) · 2.57 KB
/
SoundManager.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
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class SoundManager here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class SoundManager
{
//todo - make a message Queue?
//Todo turn into an ENUM
private static boolean SoundOk = false;
private static GreenfootSound GlassPing[];
private static GreenfootSound GlassBreak[];
private static int pingIndex = 0;
private static int breakIndex = 0;
static{
SoundOk = true;
try{
GlassBreak = new GreenfootSound[2];
GlassBreak[0] = new GreenfootSound("glass-break.wav");
GlassBreak[1] = new GreenfootSound("glass-break.wav");
GlassPing = new GreenfootSound[5];
GlassPing[0] = new GreenfootSound("17__anton__glass-a-pp.wav");
GlassPing[1] = new GreenfootSound("17__anton__glass-a-pp.wav");
GlassPing[2] = new GreenfootSound("17__anton__glass-a-pp.wav");
GlassPing[3] = new GreenfootSound("17__anton__glass-a-pp.wav");
GlassPing[4] = new GreenfootSound("17__anton__glass-a-pp.wav");
GlassPing[0].play();
}
catch(Exception e)
{
SoundOk = false;
System.out.println(e.getMessage());
e.printStackTrace();
}
}
public static void playPing()
{
if(!SoundOk)
{
return;
}
pingIndex = (pingIndex + 1) % GlassPing.length;
int nextPing = (pingIndex + 1) % GlassPing.length;
/*
if(GlassPing[nextPing].isPlaying())
{
GlassPing[nextPing].stop();
}
GlassPing[pingIndex].play();
*/
try{
GlassPing[nextPing].stop();
}
catch(Exception e)
{
}
try{
GlassPing[pingIndex].play();
}
catch(Exception e)
{
}
}
public static void playBreak()
{
if(!SoundOk)
{
return;
}
breakIndex = (breakIndex + 1) % GlassBreak.length;
int nextBreak = (pingIndex + 1) % GlassBreak.length;
/*
if(GlassBreak[nextBreak].isPlaying())
{
GlassBreak[nextBreak].stop();
}
GlassBreak[breakIndex].play();
*/
try{
GlassBreak[nextBreak].stop();
}
catch(Exception e)
{
}
try
{
GlassBreak[breakIndex].play();
}
catch (Exception e)
{
}
}
}