# Gaming Questions (levels and states/screens)

**URL:** <https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201>\
**Category:** Project Guidance\
**Created:** [December 20, 2021, 12:29am UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201 "2021-12-20T00:29:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lily186](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lily186](https://discourse.processing.org/u/lily186)\
**Post date:** [December 20, 2021, 12:29am UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201/1 "2021-12-20T00:29:50Z")

</div>

Hi I was wondering how someone can create levels for a game in processing??  
,Thank you!

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [December 20, 2021, 1:53am UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201/2 "2021-12-20T01:53:28Z")

</div>

Yes, you can make different levels for games in Processing.

Here’s a game I once made that has different levels, as well as a built-in level editor: [Amanda's Birthday Quest](http://www.tfguy44.com/BirthdayQuest/)

Here’s the source so you can see how it works:  
[http://www.tfguy44.com/BirthdayQuest/BirthdayQuest.pde](http://www.tfguy44.com/BirthdayQuest/BirthdayQuest.pde)

---

<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:** [December 20, 2021, 10:15am UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201/3 "2021-12-20T10:15:42Z")

</div>

it’s hard to describe without seeing your code and knowing what game it is

show some code

There is no inbuilt function for levels. You have to program it yourself.

**Example**

for example make an int variable levelNum (`int levelNum;`) and increase it when your level is finished (in a maze: player reaches target; in breakout: all bricks are gone).

levelNum++;

Check it against new variable maxLevel (`final int maxLevel = 4;`) and then display a “You won. You finished all levels.” Screen.

in draw() you can draw the maze (or whatever content the levels have) depending on `levelNum`:

```auto
switch (levelNum) {
 case 0:
  // show level 0
  // ... 
  break; 

 case 1:
  // show level 1
  // ...
  break; 

// ...

case maxLevel : 
  //display a "You won. You finished all levels." Screen.
  break; 

default: 
  // Error 
  break; 
} // end of switch

```

**Remark**

when your maze is in a data structure you can make an array of it which is more elegant like

`displayMaze(maze[levelNum]);`

then you don’t need the `switch()`

Chrisir

---

<div class="post-metadata">

**Author:** ![lily186](https://avatars.discourse-cdn.com/v4/letter/l/7c8e57/32.png) [@lily186](https://discourse.processing.org/u/lily186)\
**Post date:** [December 20, 2021, 10:56pm UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201/4 "2021-12-20T22:56:03Z")

</div>

Here is my code, so what i want to do is allow the user to click on a like start button and take them to a  
different screen where there are game modes this works but the issue that keeps arising is that like the buttons on the various screens overlap so they both like happen at the same time, what can i do so that the screens function separately, thank you! sorry if this is a little confusing.

---

<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:** [December 20, 2021, 11:28pm UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201/5 "2021-12-20T23:28:45Z")

</div>

> [@lily186](#):
>
> the issue that keeps arising is that like the buttons on the various screens overlap so they both like happen at the same time

Distinguish between mousePressed as a variable as you have in draw() and mousePressed() as a function that you already have.

Move the mouse functionality from draw into the mousePressed () function. This will help you because a mouse press here gets registered only once and not many times.

Additionally you can remake the if system that distinguishes the screens in mousePressed () function so only the relevant buttons for the screen are evaluated

---

<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:** [December 21, 2021, 8:27pm UTC](https://discourse.processing.org/t/gaming-questions-levels-and-states-screens/34201/6 "2021-12-21T20:27:50Z")

</div>

here is an example of such a screen / state management

Within the game section you can have of course Levels as shown above.

**Full Sketch**

```auto
// screen / state
int state=0; 
final int maxState = 2; 

//-----

void setup() {
  size (600, 600);
  background(0);
}

void draw() {

  background(0);

  switch (state) {
  case 0:  
    // show state 0 / Start Menu for example
    text("screen 0", 120, 120); 
    break; 

  case 1:
    // show state 1 / Game for example
    text("screen 1", 120, 120); 
    break; 

  case maxState: 
    //display a "You won. You finished all levels." Screen.
    text("screen 2", 120, 120);
    break; 

  default: 
    // Error 
    break;
  } // end of switch
}//draw

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

void mousePressed() {

  switch (state) {
  case 0:
    // show 0
    state=1;  
    break; 

  case 1:
    // show 1
    state=2; 
    break; 

  case maxState: 
    //ignore
    break; 

  default: 
    // Error 
    break;
  } // end of switch
}
//

```
