I can’t figure out why my intercept function is not working… It isn’t being ignored completely, just going off in the wrong spot and consistently, not just when it intersects. No code please.
Basket gold;
Basket pink;
Stars test;
float y;
float x=random(0,width);
float speedy;
void setup(){
fullScreen();
gold=new Basket(10,100,mouseX,mouseY, 255,215,0);
pink=new Basket(10,100,width-100,height-20,255,192,203);
test=new Stars(y,speedy,random(20,40),x);
}
void draw(){
background(255);
test.intercept();
test.display();
test.move();
gold.moveGold();
gold.display();
pink.movePink();
pink.display();
}
class Basket{
float h;
float w;
float x;
float y;
float r;
float g;
float b;
float score=0;
Basket(float h1, float w1, float x1, float y1, float r1, float g1,
float b1){
h=h1;
w=w1;
x=x1;
y=y1;
r=r1;
g=g1;
b=b1;
}
void moveGold(){
x=mouseX;
y=constrain(mouseY,height-20,height-10);
}
void movePink(){
if (keyPressed){
if (key==CODED){
if (keyCode==RIGHT){
x=x+5;
}else if (keyCode==LEFT){
x=x-5;
}
}
}
}
void display(){
fill(r,g,b);
rect(x,y,w,h);
}
}
class Stars {
float y=0;
float speedy;
float r = 30;
float p;
Stars(float tempy, float tempSpeed, float tempr, float tempp) {
y=tempy;
speedy=tempSpeed;
r=tempr;
p=tempp;
}
void move() {
if (y<=height) {
speedy=random(1, 10);
y=speedy+y;
} else {
clear();
background(255);
}
}
void display() {
ellipse(p, y, r, r);
}
void intercept() {
if (y==gold.y && gold.x+gold.w>x && x>gold.x) {
clear();
background(255);
gold.score++;
print(gold.score);
} else if (y==pink.y && pink.x+pink.w>x && x>pink.x) {
clear();
background(255);
pink.score++;
print(pink.score);
} else {
background(255);
}
}
}