Sound for when it hits or misses.
in
Core Library Questions
•
1 year ago
Hey, I'm trying to add the sound for when the 'alien' Hits or misses the bar.
I have the sound but it does not seem to work.. Anyone know why?
Thanks!
I have the sound but it does not seem to work.. Anyone know why?
Thanks!
float myAlienX =20;
float myAlienY = 20;
float speedX =5;
float speedY =0;
int hit = 0;
int miss = 0;
PImage img;
import ddf.minim.* ;
Minim minim;
AudioPlayer Hit;
AudioPlayer Miss;
void setup()
{
size (600,400);
minim = new Minim(this) ;
Hit = minim.loadFile("Boink.wav");
Miss = minim.loadFile("Bike_horn.wav");
}
img = loadImage("Alien.png"); //load the image
}
void draw ()
{
if(mousePressed) {hit = 0; miss = 0; }
float paddle = 1000/(hit+10);
if(myAlienX < 0 || myAlienX > width) speedX = -speedX ;
if( myAlienY > height ){
speedY = -speedY;
float distance = abs(mouseX-myAlienX);
if (distance < paddle) hit += 1;
else miss +=1;
} else speedY += 1;
myAlienX += speedX;
myAlienY += speedY;
background (100,200,500);
// fill(200,100,50);
fill (50,100,200);
rect(mouseX-paddle, height-10, 2*paddle,10);
image(img, myAlienX,myAlienY);
fill (0);
text ("hit : " + hit, 10 , 20);
text ("miss : " + miss, 10 , 40);
noLoop();
}
1