Im trying to code this catch game i p5, and i cant figure out how i can detect the falling objekt with the “basket” i’ve drawn…
hope you guys can help
let box1_x;
let box1_y;
let box1
let box2_x;
let box2_y;
let box2_w;
let box2;
let score;
function setup() {
createCanvas(800, 800);
box1_x = 400;
box1_y = 100;
box1 = box1_x*box1_y;
box2_x = mouseX;
box2_y = 700;
box2_w = 100;
box2 = box2_x*box2_y;
score = 0;
}
function draw() {
background(220);
//red
fill(255,0,0)
rectMode(CENTER)
rect(mouseX,box2_y,box2_w,50)
//green
fill(0,255,0)
rectMode(CENTER)
rect(box1_x,box1_y,25,50)
//the box is falling
box1_y += 5;
//get the box back up again
if (box1_y>box2_y){
box1_y=0;
}
if (box2_x>box1_x>box2_w){
score += 1;
print(score)
}
}