boolean ismenu = true;
boolean isgame = false;
PVector pos = new PVector(220, 50);

void setup() {
  size(800,800);
}

https://forum.processing.org/two/discussion/19925/rotating-an-object-and-making-it-move-with-a-variable.html
void draw() {
  // debug();

  if (ismenu) {
    mainMenu();
  } else if (isgame) {
    play();
  }
}

int rotation;
void play() {
  background(255);

  rotate(radians(rotation));
  translate(pos.x, pos.y);
  rect(0, 0, 20, 20);
}

void mainMenu() {
  background(246, 244, 235);

  fill(116, 155, 194);
  textSize(128);
  textAlign(CENTER);
  text("p4dash", width/2, height/2 - 100);
  // go to game
  fill(70, 130, 169);
  if (drawRectWithMouseColission(width/2, height/2, 300, 100)) {
    if (mousePressed) {
      ismenu = false;
      isgame = true;
    }
  }
  fill(0);
  textSize(40);
  text("Play", width/2, height/2);
  // go to editor
  fill(70, 130, 169);
  if (drawRectWithMouseColission(width/2, height/2+200, 300, 100)) {
    if (mousePressed) {
      ismenu = false;
    }
  }
  fill(0);
  textSize(40);
  text("Editor", width/2, height/2+200);
  fill(145, 200, 228);
  // exit game
  if (drawRectWithMouseColission(50, 100, 80, 40)) {
    if (mousePressed) {
      exit();
    }
  }
  fill(0);
  textSize(40);
  textAlign(CENTER);
  text("Exit", 50, 110);
}

// Rectangle with editor colission
boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) {
  // Draw A Rect
  rectMode(CENTER);
  rect(x, y, rectwidth, rectheight);

  // Check it for collission
  if((mouseX > x - rectwidth/2 && mouseX < x + rectwidth/2) && (mouseY > y - rectheight/2 && mouseY < y + rectheight/2)) {
    return true;
  } else {
    return false;
  }
}

void keyPressed() {
  if (ismenu) {
  } else if (isgame) {
    if (key == CODED) {
      if (keyCode == UP) {
        pos.x = pos.x + 1;
      } else if (keyCode == DOWN) {
        pos.x = pos.x - 1;
      } else if (keyCode == LEFT) {
        rotation = rotation +1;
      } else if (keyCode == RIGHT) {
        rotation = rotation -1;
      }
    }
  }
}
