GameGrid: Game programming with Java

Research project PHBern  
HomePrintJava-Online

Exercise 1: Move actors / Collisions in cells



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 walk through the whole grid and eat all pills on the way.

You can use the file PacmanEx1.java as template.

Edit PacmanEx1.java in the Online-Editor

Download (PacmanEx1.zip)

Step 1: Move pacman
Complete the act() method in the class Pacman so that the Pacman walks through all cells.

Step 2: Pacman swallows pills
Use the method getOneActorAt() that returns the first actor found at a specified location or null, if the location is empty. In the latter case can you remove the pill from the grid by calling hide() or removeSelf().

Step 3: Animate with multiple sprites
Use the two sprites named pacman_0.gif, pacman_1.gif to animate the pacman

 

 

A similar example: Collisions inside the grid (JGameEx12.java)