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

Adding sound

$
0
0

Hey there! So I have this code, it's a game and I would like to know how to add a sound whenever the ball falls, when it's game over. Thank you so much!

float posx = width;
float posy = height;
float velx = 5;
float vely = 2;
float baseh = 10;
float basew = 90;
int pont = 0;
int nivel = 1;

void setup() {
  size(800, 600);
  background(206, 234, 211);
}

void draw() {
  background(167, 167, 167);
  noStroke();
  posx += velx;
  posy += vely;
  fill(206, 234, 211);
  ellipse(posx, posy, 30, 30);
  fill(62, 62, 62);
  rect(mouseX, height-baseh, basew, baseh);
  textSize(15);
 textAlign(CENTER);
  fill(255);
  //text("jogos: " + score, width/2, height/4);
  fill(255);
  // text("NÍVEL " + nivel + "/3", width/2, height/2);


  if (posx>=width) {
    velx = -velx;

  } else if (posx<=0) {
    velx = +-velx;


  } else if (posy>=(height)-baseh && posx>=mouseX &&
    posx<mouseX + basew) {
    vely = -vely;

  }

  else if (posy>=height) {
    posx = width/2;
    posy = height/2;
    pont += 5;
    velx = 5;
    vely = 2;
    nivel = 1;

  }

  else if (posy<=0) {
    vely = +-vely * 2;
  }

  if (vely>=8) {

    nivel = 2;
  }

  else if (vely>=10) {
    nivel = 3;
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles