# Can't seem a way to make game menu for simple gun game

**URL:** <https://discourse.processing.org/t/cant-seem-a-way-to-make-game-menu-for-simple-gun-game/10588>\
**Category:** Coding Questions\
**Created:** [April 24, 2019, 1:38am UTC](https://discourse.processing.org/t/cant-seem-a-way-to-make-game-menu-for-simple-gun-game/10588 "2019-04-24T01:38:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Icecrem](https://avatars.discourse-cdn.com/v4/letter/i/71c47a/32.png) [@Icecrem](https://discourse.processing.org/u/Icecrem)\
**Post date:** [April 24, 2019, 1:38am UTC](https://discourse.processing.org/t/cant-seem-a-way-to-make-game-menu-for-simple-gun-game/10588/1 "2019-04-24T01:38:25Z")

</div>

```auto
boolean down=true;
boolean up=true;
boolean bullet=true;
float gunposition=350;//gun position
float bulletY=650;//bullet position
float bulletX=355;//bullet position
float alienX=350;//alien positon
float alienY=0;//alien position
float gravity=2;// gravity
PImage gun;
PImage bomb;
PImage spark;
boolean explosion=false;//no explosion yet

int count1=0;//score for terrorists (yourself)
int count2=0;//score for counter-terrorists(bot)
PFont font;

void setup() {
  size(700, 700);
  background(255);
  font=loadFont("MVBoli-22.vlw");
  bomb=loadImage("bomb.png");
   gun=loadImage("gun.png");
   spark=loadImage("fire.png");
   go=false;
}

void draw() {
  background(255);
  frameRate(60);
  fill(0, 0, 0);
  image(bomb,alienX,alienY,100,80);
  textFont(font);//font
  text("terrorists",50,50);
  text(count2,200,50);
  image(gun,gunposition,600,100,100);
  text("counter-terrorists",450,50);
  text(count1,670,50);
  bulletX=gunposition+70;
  alienY=alienY+gravity;
   rect(bulletX, bulletY, 10, 40);//bullet inside gun
  println(mouseX,mouseY);

 
 
   if (key==CODED==true) {
    if (keyCode==LEFT) {
      gunposition=gunposition-7;
    }
    if(gunposition>660){
      gunposition=660;}
     } 
  if (keyCode==RIGHT==true) {
    gunposition=gunposition+7;
  }
  if(gunposition<0){
  gunposition=0;
  }
  if(gunposition>600){
    gunposition=600;
}
  if (alienY<=650) {
    down=true;
  }
  if (alienY>650) {
    alienY=0;
    alienX= random(30, 670);//alien randomly spawn
    down=true;
    count1++;
  }
  if (keyPressed&&key==' '){
    up=true;
  }
  if (up==true) {//bullets going up
    bulletY=bulletY-10;
  }
  if (bulletY<10) {//reset
    bulletY=650;
    up=false;
   
  }
  if(bulletY<alienY+50&&bulletY>alienY-50&&bulletX<alienX+50&&bulletX>alienX-50){
    alienX=random(30,680);
    alienY=0;
    down=true;
    count2++;
}
if(explosion==true)//when hit explodes
{
  image(spark,gunposition,300,240,240);
  alienY=alienY-60;
}
if(explosion==true&&alienY<10){
  alienY=0;
  alienX=random(30,670);
  explosion=false;
  down=true;

}
}

```

---

<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:** [April 24, 2019, 4:54am UTC](https://discourse.processing.org/t/cant-seem-a-way-to-make-game-menu-for-simple-gun-game/10588/2 "2019-04-24T04:54:33Z")

</div>

For a menu please remember that you want to have **two** screens / major situations in draw() now: the game and the menu

You don’t want to mix them.

So start by saying `boolean menu = true;` before `setup()`.

In draw check

```auto
if(menu) {
    // show menu
    .......
    ......
}
// -----------
else {
   // show game, guns.... what you have in draw() now
   ..... 
   ...
}//else

```

Nothing outside these lines is allowed in `draw()` (because it wouldn’t know to which state it belongs) except `background()`.

The key checking: do it separately for both screens within the brackets `{...}`.

**Remark**

When you have more screens than 2, like with a _game over screen_, please make menu to an int named state which can be 0, 1, 2… so each state has a number.

Chrisir

---

<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:** [April 24, 2019, 5:05am UTC](https://discourse.processing.org/t/cant-seem-a-way-to-make-game-menu-for-simple-gun-game/10588/3 "2019-04-24T05:05:30Z")

</div>

As soon as user pressed a key in menu say `menu = false;`

Then you are in game mode

when you use keyPressed as a var, each key can be registered multiple times by processing. When you use a function keyPressed() and evaluate the key there, each key is registered only once. That would be better for the menu maybe.
