Pacman

Pacman with Bitmaps Single player no ghosts Single player with ghosts

Making a Pacman Maze

Images.

First create your Pacman images and place them in a folder low in the directory structure.
Make sure that all filenames 8 letters or less long and don't contain wierd symbols.
The images must be bitmaps; bmp files.

Making the Maze.

This code generates a very basic maze.

to mazemaker
make "maze (ARRAY 120 0)
for [ x 0 11 1][
for [ y 0 9 1][
setitem :x+:y*12 :maze 5
]]
repeat 12 [
setitem repcount-1 :maze 10]
repeat 12 [ setitem (repcount-1)+108 :maze 10]
repeat 10 [ setitem (repcount-1)*12 :maze 10]
repeat 10 [ setitem (repcount-1)*12+11 :maze 10]
setitem 61 :maze 20
for [ x 0 11 1][
for [ y 0 9 1][
if (item :x+:y*12 :maze)=10 [
pu setxy (:x-6)*50 (:y-5)*50 pd
bitload "C:\\gameim\\wall.bmp]
if (item :x+:y*12 :maze)=5 [
pu setxy (:x-6)*50 (:y-5)*50 pd
bitload "C:\\gameim\\fruit.bmp]
if (item :x+:y*12 :maze)=20 [
pu setxy (:x-6)*50 (:y-5)*50 pd
bitload "C:\\gameim\\pacr.bmp]
]]
end

  1. Our maze will be made from a grid of tiles. The tiles are 50px square and we will have 12 across and 10 down.
  2. The contents of each tile are represented in an array of 120 numbers.
  3. Every tile at first is given the value 5 which stands for fruit.
  4. Logo can't generate 2D arrays so the y values are multiplied by 12 and added to the x values.
  5. We then draw the rock walls of the outsides of the maze. These are given by value 10.
  6. The pacman is inserted on tile 61 with value 20 for a right facing pacman.
  7. We then work through the array drawing the correct tile at each location. This is done by using a set of if statements for each tile type.
  8. This completes the start up for a game.
  9. To make this into a full game you need to be able to move the pacman around go to Input/Output to find out how to do this.
  10. It will help if you think about how you might remember where the pacman came from and how to keep score etc.
  11. To keep score you need to be able to write labels onto the screen. See logowords1 for advice on how to do this.

Single player no ghosts

Source code only
pacman.lgo

Last updated 8th July 2010