Game programming with Java
HomeAufgabennPrintJava-Online

Excercise 2: Pacman und Key-Events



A 10x10 Gamegrid, with a pacman at the location (0,0) and 20 pills at random locations, is given. In this example, the pacman is supposed to be controlled using the cursor keys and to swallow pills when passing them.

As a template, you can use the file PacmanEx2.java.

 

Download: PacmanEx2.zip

A similar example: Key Events (JGameEx17.java)

Also Count the number of remaining pills. After the pacman has swallowed all pills, the game is over. To show this, create a new Actor with the following line:

gameGrid.addActor(new Actor("sprites/you_win.gif"), new Location(10, 8));