Now the game don’t block, but I became the same message in the console and I don’t know how I can’t put the soundfile1.play(); and the soundfile2.play(); in the void draw.
void setup(){
positions_array = new float [blur_anzahl][2];
spieler_x = 20;
spieler_y = 353;
ball_x = 450;
ball_y = 350;
ball_geschwindigkeit_x = - 4;
ball_geschwindigkeit_y = 0;
runde = 0;
size (900, 700);
rectMode(CENTER);
bg = loadImage("pong_bg.png"); //Hintergrundbild
noStroke();
schrift = loadFont("burbank30.vlw");
textFont(schrift);
//Sound
soundfile1 = new SoundFile(this, "plop.mp3");
soundfile2 = new SoundFile(this, "game_over.mp3");
}
void draw(){
background(bg);
rect(spieler_x, spieler_y, 20, 100);
rect(ball_x, ball_y, 10 ,10);
//Blur-Effekt
for(int i = (blur_anzahl - 1); i > 0; i--){
fill(255, 0, 0, 255/(i*2));
positions_array[i][0] = positions_array[i-1][0];
positions_array[i][1] = positions_array[i-1][1];
rect(positions_array[i][0], positions_array[i][1], 10 ,10);
}
positions_array[0][0] = ball_x;
positions_array[0][1] = ball_y;
fill(200, 0, 0, 255);
if(keyPressed){
if(keyCode == DOWN){
if(spieler_y < 650){
spieler_y = spieler_y + 5;
}
}
if(keyCode == UP){
if(spieler_y > 50){
spieler_y = spieler_y - 5;
}
}
}
ball_x = ball_x + ball_geschwindigkeit_x;
ball_y = ball_y + ball_geschwindigkeit_y;
//This is when then ball touches the player
if(ball_x < 30){
if(ball_y < (spieler_y + 55) && ball_y > (spieler_y - 55)){
soundfile1.play(); //Sound
ball_geschwindigkeit_x = (-ball_geschwindigkeit_x) + 1;
ball_geschwindigkeit_y = ball_geschwindigkeit_y - (spieler_y - ball_y) * 0.1;
runde = runde + 1;
}else{
soundfile2.play(); //Sound
ball_x = 450;
ball_y = 350;
ball_geschwindigkeit_x = - 4;
ball_geschwindigkeit_y = 0;
runde = 0;
spieler_y = 353;