Why aren't my Game States working?

Hi All,

I'm working on an Assignment and for some reason when the program runs, it skips over my rules() Game State. Please help.

PImage nurse; PImage stretcher; PImage bg;

PImage[] playerFrames = new PImage[14];

int INTRO = 0; int RULES = 1; int RUN_GAME = 2; int GAME_OVER = 3;

int gameState = INTRO;

int q = 0;

int r =0;

Player player;

void setup() { size(1081, 841); imageMode(CENTER);

//Player(int a, int b){ //this.a = a; //this.b = b; //}

// load player animation for (int i=0; i < playerFrames.length; i++) { String filename = "Player" + i + ".png"; playerFrames[i] = loadImage(filename); println("Loading" + filename); }

player = new Player(); bg = loadImage("bg2.jpg"); }

void draw() { // background (obg); /* switch(gameState) { case INTRO: println("intro"); break;

case RULES: println("rules"); break;

case RUN_GAME: println("rungame"); break;

case GAME_OVER: println("gaveover"); break; } */

if (gameState == INTRO) intro(); else if (gameState == RULES) rules(); else if (gameState == RUN_GAME) runGame(); else if (gameState == GAME_OVER) gameOver();

}

////////////////////////////////////////////////////////////////////// // INTRO STATE void intro() { background(bg); textSize(50); textAlign(CENTER, BOTTOM); text("Welcome to!", width/2, height/2); text("Williams Nursing Home!", width/2, 450); text("Press Spacebar for Instructions!", width/2, 500); }

////////////////////////////////////////////////////////////////////// // RULES

void rules() { background(bg); text("Step 1: PRESS THE 'R' KEY TO ROLL THE DICE", width/2, 450); text("Step 2: USE THE RIGHT ARROW TO MOVE YOUR PLAYER HOWEVER MANY SPACES YOU ROLLED.", width/2, 500); }

////////////////////////////////////////////////////////////////////// // RUN GAME -- this is where the actual game happens void runGame() { background(245, 241, 222); for (int i=0; i < 20; i+=2) { line(i60, 0, i60, height); //lines for the board line(width, i60, 0, i60);

}

player.move();
player.display();

if (keyPressed) {

if (key == 'r') {
  for (int k = 0; k < 1; k++) {
    r = int(random(0, 12));
    println(r);
  }
}

}

textSize(24); fill(255, 0, 0); text(r, 15, 30);

if (keyPressed && (key == CODED)) { if (keyCode == RIGHT){ q += 4;} else if (keyCode == LEFT){ q += -4;
} player.display( , ); } }

////////////////////////////////////////////////////////////////////// // GAME OVER -- this is what happens we we are game over void gameOver() { background(bg); text("GAME OVER.", width/2, height/2); }

void keyPressed() { if (gameState == INTRO || gameState == GAME_OVER) { gameState = RUN_GAME; //dice = 0; // remember to reset the score } }

Tagged:

Answers

  • Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.

    Kf

Sign In or Register to comment.