[RESOLVED] A game menu with three levels

As has been said already, we can’t help with code we can’t see. Even then, we’re not going to edit it for you.

You have, however, described your goal sufficiently enough to warrant at least a little help when it comes to structuring your code. I suggest the following format:

int state = 0;
int mode = 0;

void setup() {
  fullScreen();
  reset();
}

void reset() {
  state = 0;
  mode = 1;
}

void draw() {
  background(255, 0, 255);
  switch(state) {
  case 0:
    draw_menu();
    break;
  case 1:
    draw_stage_one();
    break;
  case 2:
    draw_stage_two();
    break;
  case 3:
    draw_stage_three();
    break;
  }
}

void mousePressed() {
  switch(state) {
  case 0:
    if ( over_play_all() ) {
      mode = 1;
      begin_stage(1);
      return;
    }
    if ( over_play_one() ) {
      mode = 0;
      begin_stage(1);
      return;
    }
    if ( over_play_two() ) {
      mode = 0;
      begin_stage(2);
      return;
    }
    if ( over_play_three() ) {
      mode = 0;
      begin_stage(3);
      return;
    }
    break;
  case 1:
    mousePressed_stage_one();
    break;
  case 2:
    mousePressed_stage_two();
    break;
  case 3:
    mousePressed_stage_three();
    break;
  }
}

void begin_stage(int stage) {
  switch(stage) {
  case 1:
    setup_stage_one();
    state = 1;
    return;
  case 2:
    setup_stage_two();
    state = 1;
    return;
  case 3:
    setup_stage_three();
    state = 1;
    return;
  }
}

void setup_stage_one() {
}
void setup_stage_two() {
}
void setup_stage_three() {
}
void draw_menu() {
}
void draw_stage_one() {
}
void draw_stage_two() {
}
void draw_stage_three() {
}
void mousePressed_stage_one() {
}
void mousePressed_stage_two() {
}
void mousePressed_stage_three() {
}
boolean over_play_all() {
  return(false);
}
boolean over_play_one() {
  return(false);
}
boolean over_play_two() {
  return(false);
}
boolean over_play_three() {
  return(false);
}

void on_stage_finished(boolean won) {
  if ( won && mode == 1 ) {
    state++;
    state%=4;
  } else {
    state = 0;
  }
}

If you try running this, you will see that it kicks out nothing more than a full screen, blank purple sketch. As far as being a game goes, that isn’t helpful. Your goal instead is to understand the structure this code is providing, and fill in its gaps with your own game logic.

4 Likes