ReferenceError: velocidadeYOponente is not defined
p5.js says: There's an error due to "velocidadeYOponente" not being defined in the current scope (on line 22 in sketch.js [/sketch.js:22:1]).
If you have defined it in your code, you should check its scope, spelling, and letter-casing (JavaScript is case-sensitive). For more: https://p5js.org/examples/data-variable-scope.html https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/Not_Defined#What_went_wrong
// Variáveis da Bolinha let xBolinha = 300; let yBolinha = 200; let diametro = 15;
// Velocidade da Bolinha let = velocidadeXBolinha = 6; let = velocidadeYBolinha = 6; let raio = diametro / 2 ;
// Comprimento da Raquete let = raqueteComprimento = 10 let = raqueteAltura = 90
// Varíaveis da Raquete let = xRaquete = 5; let = yRaquete = 150;
// Varíaveis da Oponente let = xRaqueteOponente = 585; let = yRaqueteOponente = 150; let = velocidadeYOponente;
function setup() { createCanvas(600, 400); }
function draw() { background(0); mostraBolinha(); movimentaBolinha(); verificaColisaoBorda(); mostraRaquete(xRaquete, yRaquete); movimentaMinhaRaquete(); verificaColisaoRaquete(); mostraRaqueteOponente(xRaqueteOponente, yRaqueteOponente); movimentaRaqueteOponente(); }
function mostraBolinha(){ circle(xBolinha, yBolinha, diametro); }
function movimentaBolinha(){ xBolinha +=velocidadeXBolinha; yBolinha +=velocidadeYBolinha; }
function verificaColisaoBorda(){ if (xBolinha + raio > width || xBolinha - raio < 0){ velocidadeXBolinha *= -1; } if (yBolinha + raio > height|| yBolinha - raio < 0){ velocidadeYBolinha *= -1; } }
function mostraRaquete(x,y){ rect(x, y, raqueteComprimento, raqueteAltura); }
function mostraRaqueteOponente(x,y){ rect(x, y, raqueteComprimento, raqueteAltura); }
function movimentaMinhaRaquete(){ if (keyIsDown(UP_ARROW)){ yRaquete -= 10; } if (keyIsDown(DOWN_ARROW)){ yRaquete += 10; } }
function verificaColisaoRaquete(){ if (xBolinha - raio < xRaquete + raqueteComprimento && yBolinha - raio < yRaquete + raqueteAltura && yBolinha + raio > yRaquete){ velocidadeXBolinha *= -1; } }
function movimentaRaqueteOponente(){ velocidadeYOponente = yBolinha - yRaqueteOponente - raqueteComprimento / 2 - 30; yRaqueteOponente += velocidadeYOponente }