I am wanting to create a sketch where a rectangle from arrayList A will remove itself from the list when it collides with a rectangle from arrayList B. I am so puzzled on how to do this.
Here is my class code from which I make the arrayLists:
class Ghost {
float x;
float y;
int xSpeed = -1;
int r = 50;
Ghost(float x, float y) {
this.x = x;
this.y = y;
}
void display() {
fill(200, 0, 0);
stroke(255);
rect(x, y, r, r);
x = x + xSpeed;
}
void finished() {
////This is the part I'm trying to figure out//////////
///collision
if (x < knights.get(x)+knights.get(r) && y < knights.get(y) + knights.get(r) && y+r > knights.get(y)) {
///remove the ghost
ghosts.remove(this);
}
}
}
The other arraylist is the exact same, aside from it moving in the opposite direction, and without the collision code.
As for my sketch,
It simply draws them while I add them in with keyPressed.