2
respostas

[Dúvida] minha bolinha nao mexe no eixo y

eu acho q ta td paz soq n vai, ela fica bugada girando em torno dela msm https://streamable.com/awnk63 < video do bug

//circle's variables let xCircle = 300; let yCircle = 200; let diameter = 30;

//speed variables let speedxCircle = 5; let speedyCircle = 5; let ray = diameter/ 2;

//racket variables let xRacket = 5; let yRacket = 150; let length = 10; let height = 90;

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

function draw() { background(0); showscircle(); movescircle(); verifycolisionedge(); showsracket(); movesracket(); }

function showscircle(){ circle(xCircle, yCircle, diameter); }

function movescircle(){ xCircle += speedxCircle; yCircle += speedyCircle; }

function verifycolisionedge(){ if (xCircle +ray > width || xCircle -ray < 0){ speedxCircle *= -1; } if (yCircle +ray > height || yCircle -ray < 0); speedyCircle *= -1; //i fking spent 10min this part cuz i tried to do alone without my teacher lol and i pressed INSERT idk why this exist }

function showsracket(){ rect(xRacket, yRacket, length, height); }

function movesracket(){ if (keyIsDown(UP_ARROW)){ yRacket -= 10; } if (keyIsDown(DOWN_ARROW)){ yRacket += 10; } }

(eu nao sei pq fiz em ingles mas ta paz p entender) pf me ajd

2 respostas

Oi, Gerson

O variável "height" está em conflito

  • Renomei a variável:
    • "height" para "heightRacket"
    • "length" para "lengthRacket"

// Variáveis do círculo
let xCircle = 300;
let yCircle = 200;
let diameter = 30;

// Variáveis de velocidade
let speedxCircle = 5;
let speedyCircle = 5;
let ray = diameter / 2;

// Variáveis da raquete
let xRacket = 5;
let yRacket = 150;
let lengthRacket = 10;
let heightRacket = 90;

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

function draw() {
  background(0);
  showCircle();
  moveCircle();
  verifyCollisionEdge();
  showRacket();
  moveRacket();
}

function showCircle() {
  circle(xCircle, yCircle, diameter);
}

function moveCircle() {
  xCircle += speedxCircle;
  yCircle += speedyCircle;
}

function verifyCollisionEdge() {
  if (xCircle + ray > width || xCircle - ray < 0) {
    speedxCircle *= -1;
  }
  if (yCircle + ray > height || yCircle - ray < 0) {
    console.log(yCircle + ray, height);
    speedyCircle *= -1;
  }
}

function showRacket() {
  rect(xRacket, yRacket, lengthRacket, heightRacket);
}

function moveRacket() {
  if (keyIsDown(UP_ARROW)) {
    yRacket -= 10;
  }
  if (keyIsDown(DOWN_ARROW)) {
    yRacket += 10;
  }
}

obg amg