|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
IntroductionIn order to play, you need a Pocket PC enabled device with the .NET Compact Framework 1.1 installed. To install, simply copy the mypacman.exe file to a new folder on your device. There is apparently no need for any companion files because the three Wav sound files and two GIF image files are incorporated into the executable as "embedded resources". To start playing the game, press Enter, and then use the direction keys to guide the Pacman. The object of the game is not to be eaten by the red ghosts. There are four purple "yummies" that when eaten, convert the vile red ghosts into gentle blue ones which can then be eaten. This "free time" is limited and its extension is portrayed by a color bar that appears below the scores and starts getting smaller. You have three lives. Once you eat all the dots, you enter a new level in which the "scared" ghosts time gets reduced. Starting the second level, the red ghosts start "tracking" the Pacman (as opposed to randomly switching direction), and you got to be extra careful! Once you lose all your lives, the game enters a demo mode, flashing a screen and ghosts moving around. To start playing again, simply press Enter.
The current game has only one maze design, so as an improvement, you people can design new mazes for different levels and also design new types of rewards and "villains". Using the codeThis project contains 7 classes in seven source files: GameForm.cs, GhostsManager.cs, PacmanManager.cs, Sound.cs, Sprite.cs, StopWatch.cs, and GameFont.cs. The first three are the important classes; I will describe their functionality briefly. The code is fairly well commented so you can gather conclusions from there too. The main class of the project is private byte[] LEVEL1DATA =
{
19,26,18,26,26,26,22,7,19,26,26,26,18,26,22,
37,7,21,3,10,14,21,13,21,11,10,6,21,7,37,
.....
.....
25,26,26,26,26,26,24,26,24,26,26,26,26,26,28
};
The playing ground dimensions are defined by the following constants: The game playing area is composed by The bit values in every byte of the array decide if the associated block has or has-not (starting with the LSB) a left maze wall, upper maze roof, right maze wall, lower maze floor, dot, and yummy. There are two bits left which are not used and can be used to add more features to the maze in a future enhancement. Double buffering is used to avoid flickering. At the start of the game, the whole maze is loaded onto a public void DotConsumed(int arraypos, Sprite pacman)
//callback function invoked by pacManager
//notifying that dot has been consumed
{
...
if ((ch&16)!=0) // you just ate a dot!
{
...
mazeGraphics.FillRectangle(brush,
pacman.x+BLOCKSIZE/2,pacman.y+BLOCKSIZE/2,3,3);
// clear bits 16 and 32 (no dot or yummy)
screendata[arraypos]=(byte)(ch&15);
score++;
}
if ((ch&32)!=0) // just ate a yummy
{
...
mazeGraphics.FillRectangle(brush,
pacman.x+BLOCKSIZE/3,
pacman.y+BLOCKSIZE/3,BLOCKSIZE/3,BLOCKSIZE/3);
screendata[arraypos]=(byte)(ch&15);
score+=5;
}
}
and private void DrawMaze()
{
offScreenGraphics.DrawImage(mazeBitmap, 0, 0,
this.ClientRectangle, GraphicsUnit.Pixel);
}
The other two important classes are
public void MovePacMan(GameForm form)
{
byte ch;
if (reqdx==-pacman.dx && reqdy==-pacman.dy)
//this is when it reverses direction
{
pacman.dx=reqdx;
pacman.dy=reqdy;
viewdx=pacman.dx;
viewdy=pacman.dy;
}
else if (pacman.x%GameForm.BLOCKSIZE==0 &&
pacman.y%GameForm.BLOCKSIZE==0) //its in the middle of a block
{
arraypos=pacman.x/GameForm.BLOCKSIZE +
GameForm.NROFBLOCKS*(pacman.y/GameForm.BLOCKSIZE);
ch = form.screendata[arraypos];
....
....
OnDotConsumed(arraypos, pacman);
//notify parent that yummy or dot has been
//consumed so as to update maze
}
DrawPacMan();
}
private int[] VALIDSPEEDS = { 1,2,4,8 };
// all these are factors of BLOCKSIZE
Points of InterestA point of interest is the event handler method //In GameForm() constructor:
pacManager.OnDotConsumed += new PacmanManager.DotConsumedHandler(this.DotConsumed);
//In PacManager.cs:
public delegate void DotConsumedHandler(int arraypos, Sprite pacman);
public event DotConsumedHandler OnDotConsumed;
Another point of interest is the tracking algorithm (a simple form of Artificial Intelligence) the ghosts use after the first level of play is done. When possible, it will only consider directions of movement in which the ghost reduces the x-y distances between itself and the Pacman: if(form.pacManager.pacman.y<ghosts[i].y || goRandom)
{
dx[count]=0;
dy[count]=-1;
count++;
}
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||