//variavel do placar
let meuP = 0;
let pO = 0;
//variaveis da bolinha
let xB = 300;
let yB = 200
let dia = 30
let r = dia / 2
//velocidade da bolinha
let vXB = 6
let vYB = 6
//variaveis da raquete E
let xR = 5
let yR = 150
let copR = 10
let hR = 90
//variaveis da raquete D
let xRD = 580
let yRD =150
let vYRD
//variavel de colisão
let coli = false;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0);
mostraB();
movB ();
colB ();
mostraR(xRD, yRD);
mostraR(xR, yR);
movRE();
movRD();
//colRE ();
colREB (xR, yR);
colREB (xRD, yRD);
pontos ();
parametro ();
}
function mostraB () {circle(xB,yB,dia);}
function movB () {
xB += vXB;
yB += vYB;}
function colB () {
if (xB + r > width || xB - r < 0){vXB *= -1}
if (yB + r > height || yB - r < 0){vYB *= -1}
}
function mostraR (x, y){
rect (x, y, copR, hR)}
function movRE () {
if (keyIsDown(UP_ARROW)){
yR -=10;
}
if (keyIsDown(DOWN_ARROW)){
yR +=10;
}
}
function colRE (){
if (xB < xR + copR
&& yB - r < yR + hR
&& yB + r > yR){
vXB *= -1}
}
function colREB (x, y) {
coli = collideRectCircle(x, y, copR, hR, xB, yB, r);
if (coli){vXB *= -1}}
function movRD (){
vYRD = yB -yRD -copR/2 -30;
yRD += vYRD;
}
function pontos (){
fill (255)
text (meuP, 278, 26)
text (pO, 321, 26)
}
function parametro (){
if (xB > 585){
meuP += 1;
if (xB < 15){
pO += 1;
}
}
}