# Combine different projects

**URL:** https://discourse.processing.org/t/combine-different-projects/13422
**Category:** Coding Questions
**Created:** [August 16, 2019, 7:43pm UTC](https://discourse.processing.org/t/combine-different-projects/13422 "2019-08-16T19:43:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![joakox98](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@joakox98](https://discourse.processing.org/u/joakox98)
#### Post date: [August 16, 2019, 7:43pm UTC](https://discourse.processing.org/t/combine-different-projects/13422/1 "2019-08-16T19:43:07Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [August 16, 2019, 8:29pm UTC](https://discourse.processing.org/t/combine-different-projects/13422/2 "2019-08-16T20:29:24Z")

</div>

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

 ![button_menu](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/68dd7e7b84de29ce4b64be016f7df238c086b047.png)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [August 16, 2019, 8:33pm UTC](https://discourse.processing.org/t/combine-different-projects/13422/3 "2019-08-16T20:33:28Z")

</div>

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 `setup`s together in the new `setup()`. And the old `draw`s in handleState0 / 1 / 2 functions

Chrisir

```auto

//
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
}
// 

```
