Pac-Man Game

edited February 2017 in Questions about Code

Hello again, everyone,

I am trying to make a pacman game and am running into errors that I am unfamiliar with. I am trying to get pacman controllable with the keyboard.

Here is my code:

int mv = 60;

void setup( ) {
  size(500, 200);
  background(0);
  stroke(0);
  smooth();
  fill(255);
  for (int i = 0; i < 16; i++) {
    ellipse(100 + 25 * i, 100, 15, 15);
  }
}

void draw( ) {
  fill(0);
  arc(mv, 100, 80, 80, radians(50 - 2 * (1 + mv % 25)), radians(310 + 2 * (1 + mv % 25)));
  mv++;
  fill(255, 255, 0);
  arc(mv, 100, 80, 80, radians(50 - 2 * (1 + mv % 25)), radians(310 + 2 * (1 + mv % 25)));
}

void keyPresses() {
  if (key == CODED) {   // Get key pressed
    if (keyCode == RIGHT) {
      pDirX = pSpeed;  // set packman X to increase (+1)
      pDirY = 0;  // only move in x direction 
    } else if (keyCode == LEFT) {
      pDirX = -pSpeed;  // set Pacman X to decrease (-1)
      pDirY = 0;  // only move in X dir=ection
    } else if (keyCode == UP) {
      pDirY = -pSpeed;  //set pacman Y to decrease (-1)
      pDirY = 0;  //only move in y direction
    } else if (keyCode == DOWN) {
      pDirY = +pSpeed; // set pacman X to increase (+1)
      pDirX = 0;  //only move in Y direction
    }
  }
}

And this is the error message I am getting: http://i346.photobucket.com/albums/p405/Griff-500/Screen Shot 2017-02-14 at 1.32.44 PM_zpsocj4lget.png

Tagged:

Answers

  • The error is because pDirX and pDirY and pSpeed are missing in the code that you provided and it seems it is also missing in your code.

    Kf

  • They are missing in my code? What exactly do you mean?

  • line 25 (and others) says pDirX = pSpeed

    but where is the definition of pDirX or pSpeed?

  • Is this really the entire code?

  • @Griff --

    The errors tab in Processing will highlight places with errors (like the line that koogs points out) and give you some indication of what is wrong with them.

    If you got that keyPressed code from another sketch, that original sketch probably had lines at the top that declared pDirX and pSpeed as either int or float.

    You may also want to search the forum for previous pacman examples:

Sign In or Register to comment.