I have a problem with the menu of my game

Hi guys, I’m a beginner with processing and others languages. I started to do a Snake game for my exam but I have a problem with my code. When I’m in the menu, I can select to play (pic.1) or to go in the setting(pic.2) and I don’t have any problems. The problem is that when I play and pause to open the settings, the setting menu is bugged and I don’t understand why. I can’t exit the menu like I can do when the game is not start and the color of some thing are not correct. I commented on the necessary line of code. I hope I’ve been clear, I apologize if it’s not. I’m not really used to using this kind of forum.
I also added a link to my complete code if u want to test and see the problem.



void draw()
{
  menu(); // start the menu
}

void menu()
{
  if (playgame == false) // show the menu (pic. 1)
  {
    image(movie, 0, 0);
    play();
    setting(); // open  the setting
  } else
  {
    game();
  }
}

void setting()
{
  textAlign(CORNER, RIGHT);
  if (mouseX>310 && mouseX<380 && mouseY > 10 && mouseY < 30)
  {
    textSize(22);
    if (mousePressed)
    {
      setting = true;
    }
  } else
  {
    textSize(18);
  }
  fill(0);
  text("Settings", 310, 25);
  stroke(1);
  if (setting)
  {
    stroke(1);
    if (general) // if general is chosen, the  shape where " general "  is writen becomes dark
    {
      fill(0, 50);
    } else
    {
      fill(255);
    }
    beginShape(); // the form where "general" is writen
    vertex(0, 50);
    vertex(25, 20);
    vertex(75, 20);
    vertex(100, 50);
    endShape(CLOSE);
    if (general) // same but for " Key "
    {
      fill(255);
    } else
    {
      fill(0, 50);
    }
    beginShape(); // same but for " Key"
    vertex(100, 50);
    vertex(125, 20);
    vertex(175, 20);
    vertex(200, 50);
    endShape(CLOSE);
    fill(255);
    stroke(1);
    rectMode(CORNER);
    rect(0, 50, 400, 400);
    if (mousePressed)
    {
      if (mouseX>0 && mouseX< 100 && mouseY > 20 && mouseY < 50)
      {
        general = true;
      }
      if (mouseX>100 && mouseX< 200 && mouseY > 20 && mouseY < 50)
      {
        general = false;
      }
    }
    fill(0);
    textSize(14);
    textAlign(CENTER);
    text("General", 50, 40);
    text("Keys", 150, 40);
    if (general)
    {
      colorS();
      difficulty();
      song();
      volumeM();
      volumeE();
    } else
    {
      chooseKey();
    }
    fill(0);
    textAlign(LEFT);
    text("Save and exit", 300, 440);
    if (mouseX>295 && mouseX<390 && mouseY > 425 && mouseY < 440) // if u click on the text " save and exit", setting closes
    {
      rectMode(CORNER);
      fill(0, 0);
      rect(295, 425, 100, 20);
      if (mousePressed)
      {
        setting = false;
      }
    }
  }
}

void game()
{
  if(settingIngame == false)
  {
    rectMode(CORNER);
    background();
    score();
    snake();
    eye();
    food();
    dead();
    if(x.size() == 480)
    {
      win = true;
    }
    if(win)
    {
      speed = new PVector(0, 0);
      textAlign(CENTER);
      textSize(50);
      fill(0);
      text("YOU WIN", wR/2, hR/2);
      winSound.play();
    }
    else if(lose)
    {
      gameOver();
    }
  }
  else // pauses the game and allows access to the setting while it is on pause
  {
    rectMode(CORNER); //  this rect hide the excess text (  "setting " is writen a lot of time,  I guess it’s the same problem but I only understand now)
    noStroke();
    fill(255);
    rect(300,0, 200,45);
    setting(); // start the setting again
  }
}
1 Like

1/2 a gig for this file…

yes sorry, it’s because there’s music in the code

what library are you using for the gui?

I don’t use a library for that, just that line of code :
import static javax.swing.JOptionPane.*;

I found the problem, my setting menu do that because he is always called, I just need to use a background(255) when I call setting()

2 Likes