Sky_Moonlight
New Coder
Hi I'm a beginner to JavaScript, so can someone please help me. I'm trying to make a game in which the player moves around a circle to catch falling circles. I've been trying to randomize the speed at which each ball falls after touching the bottom of the screen, but for some reason, after the second time, the ball falling doesn't come back to the top after touching the bottom. I'm using p5js to write my code. I've bolded the section I need help with. Thank you! If you need any clarifications, please tell me.
let meteorPosX = 250;
let meteorPosY = 0;
let width = 15;
let height = width;
let wCatcher = 35;
let hCatcher = wCatcher;
let speed = 5;
function setup() {
createCanvas(500, 500);
noStroke();
}
function draw() {
background(0,0,0);
//catcher
fill(245,556,0,)
ellipse(mouseX, mouseY, wCatcher, hCatcher);
//meteor
fill(230,0,0);
ellipse(meteorPosX, meteorPosY, width, height);
distance1 = dist(mouseX, mouseY, meteorPosX, meteorPosY);
distance2 = dist(meteorPosX, meteorPosY, meteorPosX, 500);
if(distance1<15 || distance2==0){
meteorPosY = 0;
meteorPosX=random(0,500);
width = random(10,20);
height = width;
speed = Math.random()*5;
}
meteorPosY = meteorPosY + speed;
}
let meteorPosX = 250;
let meteorPosY = 0;
let width = 15;
let height = width;
let wCatcher = 35;
let hCatcher = wCatcher;
let speed = 5;
function setup() {
createCanvas(500, 500);
noStroke();
}
function draw() {
background(0,0,0);
//catcher
fill(245,556,0,)
ellipse(mouseX, mouseY, wCatcher, hCatcher);
//meteor
fill(230,0,0);
ellipse(meteorPosX, meteorPosY, width, height);
distance1 = dist(mouseX, mouseY, meteorPosX, meteorPosY);
distance2 = dist(meteorPosX, meteorPosY, meteorPosX, 500);
if(distance1<15 || distance2==0){
meteorPosY = 0;
meteorPosX=random(0,500);
width = random(10,20);
height = width;
speed = Math.random()*5;
}
meteorPosY = meteorPosY + speed;
}