2
respostas

pong project-gustavo

//variables let xBall = 300 let yBall = 200 let ballDiameter = 15 //ball velocity variables let xBallspeed = 6 let yBallspeed = 6

function setup() { createCanvas(600, 400); }

function draw() { background(0); showBall(); ballMovement(); verifyingBordercollision(); }

function showBall(){ circle(xBall, yBall, ballDiameter); }

function ballMovement(){ xBall += xBallspeed; yBall += yBallspeed; }

function verifyingBordercollision(){ if (xBall + ballDiameter/2 > width || xBall - ballDiameter/2 < 0) {xBallspeed *= -1;} if (yBall + ballDiameter/2 > height || yBall - ballDiameter/2 < 0) {yBallspeed *= -1;} }

2 respostas

Olá, Gustavo! Como vai você, tudo bem?

Parabéns pelo projeto, ficou excelente e a mudança da nomenclatura de variáveis e funções ficou no nível profissional!

Gostaria de deixar apenas uma dica para suas futuras postagens. Você pode utilizar a funcionalidade "Inserir bloco de código" que está na barra de formatação dos posts. Ao utilizar essa opção, o seu código aparecerá formatado e bem indentado para todos que visualizarem a postagem. Ele ficará dessa forma:

//variables 
let xBall = 300 
let yBall = 200 
let ballDiameter = 15 

//ball velocity variables 
let xBallspeed = 6 
let yBallspeed = 6

function setup() { 
  createCanvas(600, 400);
}

function draw() { 
  background(0); 
  showBall(); 
  ballMovement(); 
  verifyingBordercollision(); 
}

function showBall(){ 
  circle(xBall, yBall, ballDiameter); 
}

function ballMovement(){ 
  xBall += xBallspeed; yBall += yBallspeed; 
}

function verifyingBordercollision(){ 
    if (xBall + ballDiameter/2 > width || xBall - ballDiameter/2 < 0) 
  {
    xBallspeed *= -1;
  } 
    if (yBall + ballDiameter/2 > height || yBall - ballDiameter/2 < 0) 
  {
    yBallspeed *= -1;
  } 

}

Facilita bastante na leitura, né?

Vou deixar um link para um passo a passo sobre a utilização da opção "Inserir bloco de código": Tópico passo a passo da opção Inserir bloco de código

Parabéns pelo seu desempenho, continue compartilhando seu progresso conosco e, em caso de dúvidas, estamos à disposição!!

Um abraço e bons estudos!

Muitíssimo obrigado e perdão, não sabia desse campo de inserção de código rs.