let xBall = 300;
let yBall = 200;
let diameter = 25;
let raio = diameter / 2;
let velocitXBall = 5;
let velocitYBall = 5;
let xPosRect = 10;
let yPosRect = 150;
let xRect = 10;
let yRect = 90;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0);
showBall();
//ballMotion();
verifyCorner();
showRect();
moveMyRect();
}
function showBall(){
circle(xBall,yBall, diameter);
}
function ballMotion(){
xBall = xBall + velocitXBall;
yBall = yBall + velocitYBall;
}
function verifyCorner(){
if(xBall + raio > width || xBall - raio < 0){
velocitXBall = velocitXBall * (-1);
}
if(yBall + raio > height || yBall - raio < 0){
velocitYBall = velocitYBall * (-1);
}
}
function showRect(){
rect(xPosRect, yPosRect, xRect, yRect);
}
function moveMyRect(){
if(keyIsDown(UP_ARROW)){
yPosRect = yPosRect - 10;
}
if(keyIsDown(DOWN_ARROW)){
yPosRect = yPosRect + 10;
}
}
O código está assim, do mesmo jeito da aula mas não consigo movimentar a minha raquete com ele.