Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Play sound

$
0
0

Hey guys, how exactly do I play the sound file only when the ball hits the base (the rect)? Because all I'm doing is to make it play whenever it hits the whole bottom ..

Thank you

import ddf.minim.*;

Minim minim;
AudioPlayer certo;

void setup()
{
  size(1250,650);
 minim = new Minim(this);
 certo = minim.loadFile("FGBS(9).wav");
}

float bolaX = 200;
float bolaY = 100;
float velX = 10;
float velY = 0;
int hit = 0;
int miss = 0;


void draw()
{
  if(mousePressed) { hit = 0; miss = 0; }
  float base = 1000/ (hit+10);
  if(bolaX < 0 || bolaX > width) velX = -velX;
  if(bolaY > height){
    velY = -velY;
    float distancia = abs(mouseX - bolaX);
certo.play();
      certo.rewind();

    if (distancia < base) hit+=1;
    else miss += 1;
  } else velY += 1;



  bolaX += velX;
  bolaY += velY;

  noStroke();
  background(177, 195, 224);
  fill(252,252,252);
  ellipse(bolaX, bolaY, 50, 50);
  fill(33,33,33);
  rect(mouseX-base, height-15, 2*base, 15);

  textSize(20);
  fill(33,33,33);

  text("H I T: " + hit, 50, 50);
  text("M I S S: " + miss, 50, 100);


}

Viewing all articles
Browse latest Browse all 2896

Trending Articles