import ddf.minim.*;
Minim minim = new Minim(this);
AudioSample bounce;
boolean hit = false;
float x = random(80) + 10;
float y = random(80) + 10;
float w = 10;
float xv = 1.1;
float yv = 1.2;
void setup() {
bounce = minim.loadSample("bounce.wav");
}
void draw() {
x += xv;
y += yv;
if(x<w/2 || x>100-w/2) {
xv *= -1;
bounce.trigger();
hit = true;
}
if(y<w/2 || y>100-w/2) {
yv *= -1;
if (!hit) bounce.trigger();
}
background(255);
ellipse(x, y, w, w);
hit = false;
}
void stop()
{
// always close Minim audio classes when you are done with them
bounce.close();
minim.stop();
super.stop();
}