Combine different projects

Hello, this is my first post, and my english maybe it’s bad.
But i need help
I have 3 different projects that I’m working, but i have to create a menu to go to all of them, like they are levels, and also, go from one level to another
Problems: the different levels have different physics
Some help?

you can try a Button menu
-a- a main menu for select what to show
-b- in each can have different ?parameter? menu
-c- common is the way " Pan Tilde Zoom " 3D show of the main objects
like

1 Like

A variable state could tell in which program you are in.

In this example, you need to move your old draws in the handleState0 / 1 / 2 functions

  • With Esc key you can return to menu

  • use + to move on

  • please note that in draw() a switch section distinguish between the states. Nothing is allowed in draw outside this switch

  • switch is also used in keyPressed so different keys apply or could apply in the different states.

  • in mousePressed, mouseReleased you would also use switch

  • bring your variables in before setup(), make sure, they have different names. Bring your setups together in the new setup(). And the old draws in handleState0 / 1 / 2 functions

Chrisir



//
final int stateMenu = 1000; 
// current page:
int state = stateMenu; 

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

void setup() {
  // init (runs only once)
  size(800, 600);
} // func 

void draw() { 
  // draw() runs on and on 

  switch (state) {

  case 0: 
    // 
    handleState0();
    break; 

  case 1:
    // 
    handleState1(); 
    break;

  case stateMenu: 
    background(0);
    fill(255); // red 
    text ("Menu\n0 program \n1 program ", 210, 313);
    break; 

  default:
    // error
    println("Error number 939; unknown state : " 
      + state + ".");
    exit();
    break;
  } // switch
  //
} // func 

// ------------------------------------------------
// functions for states - called from draw() 

void handleState0() {
  // 0
  background(11);
  fill(244, 3, 3); // red 
  text ("This is Program 1 ....\nHit Esc to go back\n Hit + to go on  ", 210, 313);
} // func 

void handleState1() {
  // 
  background(255);
  fill(2, 223, 3); // green 
  text ("This is Program 2 ....\n  Hit Esc to go back\n Hit + to go on  ", 210, 313);
} // func 

// -----------------------------------------------------------------------
// keyboard input 

void keyPressed() {

  switch (state) {

  case 0: 
    // state 0
    keyPressedForState0(); 
    break; 

  case 1:
    // state 1
    keyPressedForState1();
    break;

  case stateMenu:
    keyPressedForStateMenu();
    break; 

  default:
    // error
    println("Error number 1039; unknown state : " 
      + state + ".");
    exit();
    break;
  } // switch
} // func 

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

void keyPressedForStateMenu() {
  switch(key) {
  case ESC:
    key=0; // kill ESC
    break; 
  case '0':
    state=0;
    break; 
  case '1':
    state=1;
    break;
  } // switch
}

void keyPressedForState0() {
  switch(key) {

  case ESC:
    state=stateMenu;
    key=0; // kill ESC
    break;

  case '+':
    state++;
    break;

  default:
    //ignore   
    break;
  } // switch
}

void keyPressedForState1() {
  switch(key) {

  case ESC:
    state=stateMenu;
    key=0; // kill ESC
    break; 

  case '+':
    // state++; // ????
    state=stateMenu;
    break;

  default:
    //ignore   
    break;
  } // switch
}
// 

2 Likes