Thursday, July 25, 2013

PacMan Game

The two games are not my own creation and these are regularly submitted by students of every batch. I have modified some portions of the code where, in leaping lizards i have made it to rotate and in the pacman version that i got initially the pacman was not turning at turns.
In pac-man(in light blue/aqua) even though it looks like a 2D image it is actually a 3D pacman. It is drawn as a sphere and even the ghosts are spheres. The bugs in the code include the following:
1) In level 2 if pacman dies the lives counter starts decrementing and never stops. It should decrement by one and a new game started.
2) Pacman should look like eating the food. This may be difficult with a 3D sphere so modifying the pac-man drawing code to 2D image of a circle may help.
3) In power mode when the pacman can eat a ghost it does not kill it but just passes through.

Here is how pac-man looks like...


And here is the source code for that(Its a C++ project in OpenGL, Eclipse).
On a cursory glance of the code i can make out there are two arrays... board_array and pebble_array each of 31x28 size.
In the board_array a zero value indicates a blank space in which the pacman and the ghosts can move.
In the pebble_array a 1 indicates a pebble/food which can be eaten by the pacman.
Ghost is a class which can move the Ghost and make it behave differently in different situations. OO concept has been made use of here to define a variety of methods for this class.
move() function is used to move the pacman. animate and angle are set to true and the angle at which it moves respectively.
glutSolidSphere(0.5,15,10); inside pac() function is used to draw the pacman in blue/aqua color.
The methods inside Ghost class such as
      void Move(); //Move the Monster
      void Update(void);  //Update Monster State
      void Chase(double, double, bool*);  //Chase Pacman
      bool Catch(double, double); //collision detection
      void Reinit(void);
      void Vulnerable(void);
      void Draw(void);   //Draw the Monster
      void game_over(void);
Serve obvious purposes as their names suggest. 
tp_restore() function is used to restore the pebbles in the board.
special_down() function handles the down press of the arrow keys.
RenderScene() is the display function for this program.
Draw() function splits the board into two parts to draw half of the scene at a time in the display function.(God only knows what the problem with depth here means)
Draw() is called from RenderScene as long as the game does not end.
Most of these games have a logic where they do somethings at the start, something else during play and during end they ask user to replay or not.