O valor do meu "text" do oponente fica atras do meu "rect" do oponente
//variaveis da bolinha
let xBall = 100;
let yBall = 200;
let sizeBall = 15;
let radioBall = sizeBall / 2;
let speedx = 8;
let speedy = 8;
//variaveis da raquete do jogador
let xRacket = 5;
let yRacket = 150;
let widthRacket = 5;
let lengthRacket = 100;
//variaveis da raquete do oponente
let x2Racket = 590;
let y2Racket = 150;
let speedy2Racket;
//pontos
let PlayerPoints = 0;
let EnemyPoints = 0;
//funções principais
function draw() {
background(0);
viewBall();
movimentBall();
border();
viewRacket(xRacket, yRacket);
viewRacket(x2Racket, y2Racket);
movimentRacket();
//moviment2Racket();
collisionRacket();
collision2Racket();
pointsMark();
Victory();
pointsView();
}
function setup() {
createCanvas(600, 400);
}
//funções bolinha
function viewBall() {
fill (251); circle(xBall, yBall, sizeBall); }
function movimentBall() {
xBall += speedx;
yBall += speedy;
}
function border() {
if (xBall + radioBall > width || xBall - radioBall < 0) {
speedx *= -1;
}
if (yBall + radioBall > height || yBall - radioBall < 0) { speedy *= -1; }
}
//funções raquetes
function viewRacket(x, y) {
fill (251);
rect(x, y, widthRacket, lengthRacket);
}
function movimentRacket() {
if (keyIsDown(UP_ARROW)) {
yRacket -= 10;
}
if (keyIsDown(DOWN_ARROW)) {
yRacket += 10;
}
}
function moviment2Racket() {
speedy2Racket = yBall - y2Racket - lengthRacket / 2;
y2Racket += speedy2Racket
}
function collisionRacket() {
if (xBall - radioBall < xRacket + widthRacket && yBall - radioBall < yRacket + lengthRacket && yBall + radioBall > yRacket) {
speedx *= -1;
}
}
function collision2Racket() {
if (xBall + radioBall > x2Racket + widthRacket && yBall + radioBall > y2Racket && yBall + radioBall < y2Racket + lengthRacket) {
speedx *= -1;
}
}
function pointsMark() {
if (xBall > 589) { EnemyPoints += 1 }
if (xBall < 5) { PlayerPoints += 1 }
}
function Victory() {
fill (251);
if (EnemyPoints > 9)
text('Player Victory', 270, 200)
if (PlayerPoints > 9)
text('Enemy Victory', 270, 200)}
function pointsView() {
textAlign (CENTER);
textSize (16);
fill(251);
text(PlayerPoints, 350, 40);
fill(color (255, 140, 0));
rect(230, 10, 40, 20);
fill(251);
text(EnemyPoints, 250, 40;
fill (color (255, 140, 0));
rect(330, 10, 40, 20);
}