I am confused on why my code won't work

int mode = 0;
int INTRO = 0;
int levelone = 1;
int GAME_OVER = 2;
int fontcolor;
float speed = 3;

void setup () {
  background(0);
  size(1440, 900);
  fontcolor = color( 0, 225, 149);
}

void draw () {
  if (mode == INTRO) {
    doINTROmode();
  } else if (mode == levelone) {
    dolevelone();
  } else if (mode == GAME_OVER) {
    doGAME_OVER();
  }
}             //Void DRAW!!!!

public void doINTROmode () {
  textSize(90);
  fill(fontcolor);
  text("Welcome!Press Space to start", 100, 450);
  if (keyPressed) {
    if (key == 'd') {
      INTRO = INTRO + 1;
    }
  }
}

public void dolevelone () {
  background(0, 34, 93);
}

public void doGAME_OVER () {
  textSize(90);
  fill(fontcolor);
  text("Game Over!!!", 100, 450);
}

Instead try mode=levelone;

Welcome to the forum!

1 Like

In this example you have to press Space Bar, not ā€œdā€

I use the keyword ā€œfinalā€ to make some variables (the names of the modes) constants

Chrisir



// current mode 
int mode = 0;
// modes (constants - keyword final)
final int INTRO = 0;
final int levelone = 1;
final int GAME_OVER = 2;

// other 
int fontcolor;
float speed = 3;

void setup () {
  background(0);
  size(1440, 900);
  fontcolor = color( 0, 225, 149);
}//function setup()

void draw () {
  if (mode == INTRO) {
    doINTROmode();
  } else if (mode == levelone) {
    dolevelone();
  } else if (mode == GAME_OVER) {
    doGAME_OVER();
  }
} //function draw()

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

public void doINTROmode () {
  textSize(90);
  fill(fontcolor);
  text("Welcome!\nPress Space to start", 
    100, 450);
  if (keyPressed) {
    if (key == ' ') {
      mode=levelone; //INTRO = INTRO + 1;
    }
  }
}

public void dolevelone () {
  background(0, 34, 93);
}

public void doGAME_OVER () {
  textSize(90);
  fill(fontcolor);
  text("Game Over!!!", 100, 450);
}
//
1 Like