Olá! estou testando o código feito, mas acontece o erro:
Uncaught TypeError: Cannot read property 'loop' of undefined (sketch: line 39)
Já vi outras postagens, mas nada deu certo. Meu Código: (As variáveis estão em inglês, só para avisar)
let CirclePosX = 300;
let CirclePosY = 200;
let CircleVelocityX = 6;
let CircleVelocityY = 6;
let diameter = 13;
let Radius = diameter/2;
//Racket
let RacketPosX = 5;
let RacketPosY = 150;
let RacketLength = 10;
let RacketHeight = 90;
let Collided = false;
//Enemy
let EnemyRacketPosX = 585;
let EnemyRacketPosY = 150;
let EnemyCollided = false;
let EnemyVelocityY;
//Score
let PlayerScore = 0;
let EnemyScore = 0;
//Sounds
let RacketSound;
let ScoreSound;
let GameSong;
function preload() {
let GameSong = loadSound("song.mp3");
let ScoreSound = loadSound("score.mp3");
let RacketSound = loadSound("racket.mp3");
}
function setup() {
createCanvas(600, 400);
GameSong.loop();
}
function draw() {
background(0);
UpdateCircle();
MoveCircle();
CircleCollision();
//Player
UpdateRacket(RacketPosX, RacketPosY);
MoveRacket();
RacketCollisionLibrary(RacketPosX, RacketPosY);
//Enemy
MoveEnemyRacket();
UpdateRacket(EnemyRacketPosX, EnemyRacketPosY);
RacketCollisionLibrary(EnemyRacketPosX, EnemyRacketPosY);
//Score
DrawScore();
AddScore();
}
function UpdateCircle() {
circle(CirclePosX, CirclePosY, diameter);
}
function MoveCircle() {
CirclePosX += CircleVelocityX;
CirclePosY += CircleVelocityY;
}
function CircleCollision() {
if(CirclePosX + Radius > width || CirclePosX - Radius < 0) {
CircleVelocityX *= -1;
}
if(CirclePosY + Radius > height || CirclePosY - Radius < 0) {
CircleVelocityY *= -1;
}
}
function UpdateRacket(x, y) {
rect(x, y, RacketLength, RacketHeight);
}
function MoveRacket() {
if(keyIsDown(UP_ARROW)) {
RacketPosY-= 10;
}
if(keyIsDown(DOWN_ARROW)) {
RacketPosY += 10;
}
}
function RacketCollision() {
/*(xBolinha - raio < xRaquete + raqueteComprimento
&& yBolinha - raio < yRaquete + raqueteAltura
&& yBolinha + raio > yRaquete)*/
if(CirclePosX - Radius < RacketPosX + RacketLength && CirclePosY - Radius < RacketPosY + RacketHeight && CirclePosY + Radius > RacketPosY) {
CircleVelocityX *= -1;
}
}
function RacketCollisionLibrary(x, y) {
Collided = collideRectCircle(x, y, RacketLength, RacketHeight, CirclePosX, CirclePosY, Radius);
if(Collided) {
CircleVelocityX *= -1;
}
}
function MoveEnemyRacket() {
EnemyVelocityY = CirclePosY - EnemyRacketPosY - RacketLength / 2 - 30;
EnemyRacketPosY += EnemyVelocityY;
}
function DrawScore() {
stroke(255)
textAlign(CENTER)
textSize(20);
fill(color(255, 140, 0));
rect(150, 10, 40, 20)
fill(255);
text(PlayerScore, 170, 26);
fill(color(255, 140, 0));
rect(450, 10, 40, 20)
fill(255);
text(EnemyScore, 470, 26)
}
function AddScore() {
if(CirclePosX > 590) {
PlayerScore++;
}
if(CirclePosX < 10) {
EnemyScore++;
}
}