blob: 89c7f62705d64afa676c7a1b89243c71dfac7259 (
plain)
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
|
package uk.ac.open.punchingbag.examples;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import uk.ac.open.punchingbag.ButtonListener;
import uk.ac.open.punchingbag.Contact;
import uk.ac.open.punchingbag.PunchingBag;
public class Giggle implements ButtonListener {
PunchingBag bag = PunchingBag.getBag();
String soundDir = System.getProperty("user.dir")
+ System.getProperty("file.separator");
File[] laughs = { new File(soundDir + "G4.wav"),
new File(soundDir + "C5.wav"), new File(soundDir + "D5.wav"),
new File(soundDir + "E5.wav"), new File(soundDir + "F5.wav"),
new File(soundDir + "G5.wav") };
public static void main(String[] args) {
new Giggle();
}
Giggle() {
bag.addButtonListener(this);
bag.connectToArduinos();
}
@Override
public void buttonPressed(int x, int y) {
// TODO Auto-generated method stub
}
@Override
public void contact(Contact c) {
System.out.println(c);
bag.circleExpand(c.x, c.y, 16);
if (c.force > 520) {
//int laugh = c.force
}
}
void laugh(int laugh) {
try {
AudioInputStream sound = AudioSystem.getAudioInputStream(laughs[laugh]);
DataLine.Info dataLine = new DataLine.Info(Clip.class,
sound.getFormat());
Clip clip = (Clip) AudioSystem.getLine(dataLine);
clip.open(sound);
clip.start();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|