Fiz algumas modificações na cor do placar também para ficar roxo e coloquei tudo em inglês para ficar "universal", a questão é os comentários deveriam ficar em inglês também?
O que acharam dos nomes? Muito ruim ou bom ?
//Variaveis da Bolinha let xBall = 300; let yBall = 200; let diameter = 15; let radius = diameter / 2;
//Variaveis da Raquete Jogador let xRacket = 5; let yRacket = 150; let lenghtRacket = 10; let heightRacket = 90;
//Variaveis da Raquete do Oponente let xRacketPC = 585; let yRacketPC = 150; let lenghtRacketPC = 10; let heightRacketPC = 90; let speedYRacketPC; let speedXRacketPC;
let collided = false; let chanceOfMistake = 0;
//Variaveis da Velocidade da Bolinha let speedXBall = 6; let speedYBall = 6;
//Placar do Jogo let myPoints = 0; let pcPoints = 0;
//Sons do Jogo let volley; let winPoint; let soundtrack;
function preload(){ soundtrack = loadSound("soundtrack.mp3"); winPoint = loadSound("winPoint.mp3"); volley = loadSound("volley.mp3"); }
function setup(){ createCanvas(600, 400); soundtrack.loop(); }
function draw(){ background(0); viewBall(); movementBall(); verifyCollisionEdge(); viewRacket(xRacket, yRacket); viewRacket(xRacketPC, yRacketPC); movementRacket(); movementRacketPC(); verifyCollisionRacket(xRacket, yRacket); verifyCollisionRacket(xRacketPC, yRacketPC); includeScoreboard(); markPoint();
}
function viewBall(){ circle(xBall, yBall, diameter);}
function movementBall(){ xBall += speedXBall; yBall += speedYBall; }
function verifyCollisionEdge(){ if (xBall + radius > width || xBall - radius < 0){ speedXBall *= -1; } if (yBall + radius > height || yBall - radius < 0){ speedYBall *= -1; } }
function viewRacket(x,y){ rect(x, y, lenghtRacket, heightRacket); }
function movementRacket(){ if (keyIsDown(UP_ARROW)){ yRacket -= 10; } if (keyIsDown(DOWN_ARROW)){ yRacket += 10; } }
function movementRacketPC(){ speedYRacketPC = yBall - yRacketPC - lenghtRacket / 2 -30; yRacketPC += speedYRacketPC + chanceOfMistake calculateChanceOfMistake() }
function calculateChanceOfMistake(){ if (pcPoints >= myPoints){ chanceOfMistake += 1 if( chanceOfMistake >= 39){ chanceOfMistake = 40 } } else { chanceOfMistake -= 1 if (chanceOfMistake <= 35){ chanceOfMistake = 35 } } }
function verifyCollisionRacket(x,y){ collided = collideRectCircle(x,y,lenghtRacket,heightRacket,xBall,yBall,radius); if(collided){ speedXBall *= -1; volley.play(); } }
function includeScoreboard (){ stroke(255); textAlign(CENTER); textSize(20); fill(color(76, 0, 153)); rect(150, 10, 40, 20); fill(255); text(myPoints, 170, 26); fill(color(76, 0, 153)); rect(450, 10, 40, 20); fill(255); text(pcPoints, 470, 26);
}
function markPoint(){ if (xBall > 590){ myPoints += 1; winPoint.play() } if (xBall < 10){ pcPoints += 1; winPoint.play() } }