GameGrid: Game programming with Java

Research project PHBern  
HomePrintJava-Online

Exercise 3: Pacman Game

 

Program a more sophisticated pacman game. Like in Exercise 2, the pacman can be moved using the cursor keys and must eat as many pills as possible.

Create a new character "Ghost". A fitting sprite is ghost.png, available in the image library of this page. Program different chasing strategies:

  1. The ghost wanders around aimlessly. In every step he changes to a random neighbouring cell. You can use:

    int randomNb = (int)(Math.random() * 8);
    setDirection(randomNb * 45);

  2. So Pacman gets caught quicker, you can use three such ghost.
  3. The ghost moves in the direction of the pacman.

A similar example: Chasing Actors (JGameEx15.java)

 

As a template, you can use the file PacmanEx3

Edit PacmanEx3.java in the Online-Editor

Download: (PacmanEx3.zip)