Edit: Deu certo, acho que era alguma coisa de cache
https://editor.p5js.org/felipesen/sketches/X4OWPVGTr
Ele carrega a trilha mas os outros sons apresentam erro
//Ball initial position and properties
let xBall = 300;
let yBall = 200;
let dBall = 13;
let radiusBall = dBall/2;
//Ball & Racket speed
let xspeedBall = 6;
let yspeedBall = 6;
let yspeedCPURacket;
//Racket Sizes
let lengthRacket = 10;
let heightRacket = 90;
//Player Racket variables
let xRacket = 5;
let yRacket = 150;
//CPU Racket Variables
let xCPURacket = 585;
let yCPURacket = 150;
//hit variable from Lib
let hit = false
//scoreboard
let playerPoints = 0;
let cpuPoints = 0;
//sounds
let soundHit;
let soundPoint;
let soundTrack;
function preload () {
soundTrack = loadSound("trilha.mp3");
soundHit = loadSound("raquetada.mp3");
soundPoint = loadSound("ponto.mp3");
}
//function to create the scenario
function setup() {
createCanvas(600, 400); //parameters = (w, h) w,h width,height;
soundTrack.loop();
}
//GAME
function draw() {
background(0); //color
showBall();
moveBall();
collisionBorders();
showRacket(xRacket, yRacket); //Player Racket]
moveRacket();
collisionRacketLib(xRacket, yRacket);
//collisionRackets();
showRacket(xCPURacket, yCPURacket); //CPU Racket
moveCPURacket();
collisionRacketLib(xCPURacket, yCPURacket);
showScore();
addScore();
}
//function to create the ball
function showBall() {
circle(xBall, yBall, dBall); //parameters = circle(x,y,d) x,y coordinates; d diameter
}
//function to move ball
function moveBall() {
xBall += xspeedBall // xBall = xBall + xspeedBall
yBall += yspeedBall
}
//function to ball detect borders
function collisionBorders() {
if((xBall + radiusBall) > width
|| (xBall - radiusBall) < 0){
xspeedBall *= -1;
}
if((yBall + radiusBall) > height
|| (yBall - radiusBall) < 0){
yspeedBall *= -1;
}
}
//function to create the Racket
function showRacket (x,y) {
rect(x, y, lengthRacket, heightRacket)
}
//function to move Player Racket
function moveRacket () {
if (keyIsDown(UP_ARROW)){
yRacket -= 10;
}
if (keyIsDown(DOWN_ARROW)){
yRacket += 10;
}
}
//function to move CPU Racket
function moveCPURacket () {
yspeedCPURacket = yBall - yCPURacket - lengthRacket/2 - 30;
yCPURacket += yspeedCPURacket;
}
/*
function collisionRackets () {
if ((xBall - radiusBall) < (xRacket + lengthRacket)
&& (yBall - radiusBall) < (yRacket + heightRacket)
&& (yBall + radiusBall) > (yRacket))
{
xspeedBall *= -1;
soundHit.play();
}
}
*/
//function hit Libraries
function collisionRacketLib (x,y) {
hit = collideRectCircle(x, y, lengthRacket, heightRacket, xBall, yBall, dBall)
if (hit) {
xspeedBall *= -1;
soundHit.play();
}
}
//function to show scores
function showScore () {
textAlign(CENTER);
textSize(16);
fill(color(255,140,0));
rect(150,10,40,20)
fill(255);
text(playerPoints, 170, 26);
fill(color(255,140,0));
rect(450,10,40,20)
fill(255);
text(cpuPoints, 470, 26)
}
//function to add scores
function addScore() {
if (xBall > 590) {
playerPoints += 1;
soundPoint.play();
}
if (xBall < 10) {
cpuPoints += 1;
soundPoint.play();
}
}