Defining zones in a game

Hi,

I would like to define zones in a game (a range of x and y) in which events could occur. If possible, I would also like to set the background color for that zone. I am using the Fisica library. It would have the structure:

if the object is in the zone + if it touches a body of the same class = remove the two bodies and display a text count of the bodies matched (positive count).

if the object is in the zone + if it touches a body of another class = remove the two bodies and display a text count of the bodies matched (negative points).

Here is my script just in case you want to see how my game works:

import fisica.*;
FWorld world;
FCircle circle1;
FCircle circle2;
FCircle circle3;
FCircle circleButton1;
FCircle circleButton2;
FCircle circleButton3;
FBox rectangle1;
FBox rectangle2;
FBox rectangle3;
FBox rectangle4;
FBox rectangle5; 
FBox boundary;
boolean numberReached;
PFont f;

int gx = 0; // horizontal gravity;
int gy= 0; // vertical gravity;

ArrayList<FBox> rectangles = new ArrayList<FBox>();
ArrayList<FCircle> circles1 = new ArrayList<FCircle>();
ArrayList<FCircle> circles2 = new ArrayList<FCircle>();
ArrayList<FCircle> circles3 = new ArrayList<FCircle>();
ArrayList<FCircle> circles = new ArrayList<FCircle>();

//--------------------------------------------------------

void setup() {
  size(1500, 2000); 
  smooth();
  f=createFont("Arial", 16, true);

  Fisica.init(this);
  world = new FWorld ();
  world.setEdges();      
  numberReached = false;
  
//---rectangles-------------------------------------------

  rectangle1 = new FBox (800, 50);
  rectangle1.setPosition(750, 700);
  rectangle1.setVelocity(random(50, 250), random(50, 250));
  rectangle1.setRestitution(1);
  rectangle1.setDamping(0.0);
  rectangle1.setStatic(true);
  rectangle1.setGrabbable(false);
  rectangle1.setStrokeWeight(3);
  rectangle1.setFill(0);
  rectangle1.setStroke(0);
  rectangles.add(rectangle1);
  world.add(rectangle1);

  rectangle2 = new FBox (400, 100);
  rectangle2.setPosition(200, height-400);
  rectangle2.setVelocity(random(50, 250), random(50, 250));
  rectangle2.setRestitution(1);
  rectangle2.setDamping(0.0);
  rectangle2.setStatic(true);
  rectangle2.setGrabbable(false);
  rectangle2.setStrokeWeight(3);
  rectangle2.setFill(0);
  rectangle2.setStroke(0);
  rectangles.add(rectangle2);
  world.add(rectangle2);

  rectangle3 = new FBox (550, 100);
  rectangle3.setPosition(725, height-400);
  rectangle3.setVelocity(random(50, 250), random(50, 250));
  rectangle3.setRestitution(1);
  rectangle3.setDamping(0.0);
  rectangle3.setStatic(true);
  rectangle3.setGrabbable(false);
  rectangle3.setStrokeWeight(3);
  rectangle3.setFill(0);;
  rectangle3.setStroke(0);
  rectangles.add(rectangle3);
  world.add(rectangle3);

  rectangle4 = new FBox (300, 30);
  rectangle4.setPosition(850, height-800);
  rectangle4.setVelocity(random(50, 250), random(50, 250));
  rectangle4.setRestitution(1);
  rectangle4.setDamping(0.0);
  rectangle4.setStatic(true);
  rectangle4.setGrabbable(false);
  rectangle4.setStrokeWeight(3);
  rectangle4.setFill(0);
  rectangle4.setStroke(0);
  rectangles.add(rectangle4);
  world.add(rectangle4);

  rectangle5 = new FBox (250, 30);
  rectangle5.setPosition(850, height-1000);
  rectangle5.setVelocity(random(50, 250), random(50, 250));
  rectangle5.setRestitution(1);
  rectangle5.setDamping(0.0);
  rectangle5.setStatic(true);
  rectangle5.setGrabbable(false);
  rectangle5.setStrokeWeight(3);
  rectangle5.setFill(0);
  rectangle5.setStroke(0);
  rectangles.add(rectangle5);
  world.add(rectangle5);

//------circle buttons----------------------------------------

  circleButton1 = new FCircle(50);
  circleButton1.setPosition(1000/6, height-1800);
  circleButton1.setStatic(true);
  circleButton1.setGrabbable(false);
  circleButton1.setNoFill();
  circleButton1.setStroke(0);
  circleButton1.setGrabbable(false);
  circleButton1.setStrokeWeight(3);
  world.add(circleButton1);

  circleButton2 = new FCircle(50);
  circleButton2.setPosition(1000/2, height-1800);
  circleButton2.setStatic(true);
  circleButton2.setGrabbable(false);
  circleButton2.setNoFill();
  circleButton2.setStroke(0);
  circleButton2.setStrokeWeight(3);
  circleButton2.setGrabbable(false);
  world.add(circleButton2);

  circleButton3 = new FCircle(50);
  circleButton3.setPosition(1000 - 1000/6, height-1800);
  circleButton3.setStatic(true);
  circleButton3.setGrabbable(false);
  circleButton3.setNoFill();
  circleButton3.setStroke(0);
  circleButton3.setStrokeWeight(3);
  circleButton3.setGrabbable(false);
  world.add(circleButton3);

  //----------separation---text---------------------------------
  FBox boundary = new FBox(500, 2000);
  boundary.setPosition(1250,1000);
  boundary.setStatic(true);
  boundary.setFill(0);
  boundary.setStroke(0);
  world.add(boundary);
}

//-----------------------------------------------------------
void draw() {
  background(255);
  world.setGravity(gx,gy);
  
  if (keyPressed == true) {
    if (key == 'a'){
        gx = (-400); 
        gy = (100);
      }
   
     if (key == 'd'){
        gx = (400); 
        gy = (100);
      }
      
      if (key == 's'){
        gx = (0); 
        gy = (400);
      }
      
      if (key == 'w'){
        gx = (0); 
        gy = (-400);
      }
  }
  
//add circles automatically
  if (frameCount % 200 == 0) {
    FCircle circle1 = new FCircle(30);
    circle1.setPosition(1000/6, height-1800);
    circle1.setRotation(random(TWO_PI));
    circle1.setVelocity(0, random(200, 500));
    circle1.setNoFill();
    circle1.setStroke(0);
    circle1.setGrabbable(false);
    circle1.setStrokeWeight(2);
    circles1.add(circle1);
    world.add(circle1);

    FCircle circle2 = new FCircle(80);
    circle2.setPosition(1000/2, height-1800);
    circle2.setRotation(random(TWO_PI));
    circle2.setVelocity(0, random(200, 500));
    circle2.setNoFill();
    circle2.setStroke(0);
    circle2.setStrokeWeight(2);
    circle2.setGrabbable(false);
    circles2.add(circle2);
    world.add(circle2);

    FCircle circle3 = new FCircle(20);
    circle3.setPosition(1000 - 1000/6, height-1800);
    circle3.setRotation(random(TWO_PI));
    circle3.setVelocity(0, random(200, 500));
    circle3.setNoFill();
    circle3.setStroke(3);
    circle3.setStrokeWeight(6);
    rectangle1.setGrabbable(false);
    world.add(circle3);
  }
  world.draw();
  world.step();
}

//----------------------------------------------------

void mousePressed() {
  
  //add circles manually
  FBody pressed = world.getBody(mouseX, mouseY);
  if (pressed == circleButton1) {
    FCircle circle1 = new FCircle(30);
    circle1.setPosition(1000/6, height-1800);
    circle1.setRotation(random(TWO_PI));
    circle1.setVelocity(0, random(200, 500));
    circle1.setNoFill();
    circle1.setStroke(0);
    circle1.setGrabbable(false);
    circle1.setStrokeWeight(2);
    circles1.add(circle1);
    world.add(circle1);
  }

  if (pressed == circleButton2) {
    FCircle circle2 = new FCircle(80);
    circle2.setPosition(1000/2, height-1800);
    circle2.setRotation(random(TWO_PI));
    circle2.setVelocity(0, random(200, 500));
    circle2.setNoFill();
    circle2.setStroke(0);
    circle2.setStrokeWeight(2);
    circle2.setGrabbable(false);
    circles2.add(circle2);
    world.add(circle2);
  }
  
    if (pressed == circleButton3) {
    FCircle circle3 = new FCircle(20);
    circle3.setPosition(1000 - 1000/6, height-1800);
    circle3.setRotation(random(TWO_PI));
    circle3.setVelocity(0, random(200, 500));
    circle3.setNoFill();
    circle3.setStroke(3);
    circle3.setStrokeWeight(6);
    rectangle1.setGrabbable(false);
    world.add(circle3);
  }
  
  //scale rectangles
  if (pressed == rectangle5) {
  if (mouseButton == LEFT ){
  rectangle5.setWidth(rectangle5.getWidth()*1.1);
  }
  if (mouseButton == RIGHT ){
  rectangle5.setWidth(rectangle5.getWidth()*0.9);
  }
  }
    if (pressed == rectangle4) {
  if (mouseButton == LEFT ){
  rectangle4.setWidth(rectangle4.getWidth()*1.1);
  }
  if (mouseButton == RIGHT ){
  rectangle4.setWidth(rectangle4.getWidth()*0.9);
  }
  }
  
  if (pressed == rectangle3) {
  if (mouseButton == LEFT ){
  rectangle3.setWidth(rectangle3.getWidth()*1.1);
  }
  if (mouseButton == RIGHT ){
  rectangle3.setWidth(rectangle3.getWidth()*0.9);
  }
  }
  if (pressed == rectangle2) {
  if (mouseButton == LEFT ){
  rectangle2.setWidth(rectangle2.getWidth()*1.1);
  }
  if (mouseButton == RIGHT ){
  rectangle2.setWidth(rectangle2.getWidth()*0.9);
  }
  }
  
  if (pressed == rectangle1) {
  if (mouseButton == LEFT ){
  rectangle1.setWidth(rectangle1.getWidth()*1.1);
  }
  if (mouseButton == RIGHT ){
  rectangle1.setWidth(rectangle1.getWidth()*0.9);
  }
  }
  
}```