xxxxxxxxxx
//////////////////////////////////////////
// //
// Map of sounds of ilmpark //
// //
//////////////////////////////////////////
import ddf.minim.*;
Minim minim;
int n = 2;
AudioPlayer[] players = new AudioPlayer[n];
int[][] locations = {
{313, 154, 20},
{393, 202, 20}
};
int activeLocation = -1;
PImage img;
void setup() {
size(550, 500);
// init minim
minim = new Minim(this);
// load background image
img = loadImage("ilmpark.png");
// load all soundplayers
for (int i = 0; i < n; i++) {
players[i] = minim.loadFile("Hoehle" + (i + 1) + ".wav");
}
}
void draw() {
println (mouseX +"," + mouseY);
image(img, 0, 0);
fill(130, 75, 96);
// set dummy value for the active location
activeLocation = -1;
for(int i = 0; i < locations.length; i ++) {
// get location triple
int[] loc = locations[i];
// assign variables
int x = loc[0];
int y = loc[1];
int r = loc[2];
// check if we are at the i'th location
if(atLocation(x, y, r)) {
// set active location to the current location
activeLocation = i;
// hilight the location
ellipse(x, y, r, r);
}
}
}
// check if the mouse is within radius r of location(x, y)
boolean atLocation(int x, int y, int r) {
return mouseX > (x - r) && mouseX < (x + r) && mouseY > (y - r) && mouseY < (y + r);
}
void mousePressed() {
// is the mouse hovering over one of the locations?
if(activeLocation != -1) {
// pause all players
for (int i = 0; i < n; i++) {
players[i].pause();
}
// play the sound associated with the current location
println("Sound number " + (activeLocation + 1));
players[activeLocation].rewind();
players[activeLocation].play();
}
}
void keyPressed() {
for (int i = 0; i < n; i++) {
players[i].pause();
}
// get position of digit pressed ( '1' = 0, '2' = 1 ... '9' = 8 )
int i = (key - '1');
// check if we are in the valid range
if (i >= 0 && i < n) {
// play the respective sample
println("Sound number " + (i + 1));
players[i].rewind();
players[i].play();
}
}