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.


11 comments:

  1. Would you please elaborate the code for Pacman.? Brief intro would be enough.

    ReplyDelete
    Replies
    1. hy can you tell me how i can make restriction of on wall i make pac man game but pac man eat the boundaries

      Delete
    2. answer me on my mail
      alihoney193@gmail.com

      Delete
  2. Sir, Iam getting errors like this...
    I compiled it using this command..
    gcc dino.c -lm -lglut -lGL -lGLU

    dino.c: In function ‘extrudeSolidFromPolygon’:
    dino.c:53:5: warning: passing argument 3 of ‘gluTessCallback’ from incompatible pointer type [enabled by default]
    gluTessCallback(tobj, GLU_BEGIN, glBegin);
    ^
    In file included from /usr/include/GL/freeglut_std.h:129:0,
    from /usr/include/GL/glut.h:17,
    from dino.c:7:
    /usr/include/GL/glu.h:340:23: note: expected ‘_GLUfuncptr’ but argument is of type ‘void (*)(GLenum)’
    GLAPI void GLAPIENTRY gluTessCallback (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc);
    ^
    dino.c:54:5: warning: passing argument 3 of ‘gluTessCallback’ from incompatible pointer type [enabled by default]
    gluTessCallback(tobj, GLU_VERTEX, glVertex2fv); /* semi-tricky */
    ^
    In file included from /usr/include/GL/freeglut_std.h:129:0,
    from /usr/include/GL/glut.h:17,
    from dino.c:7:
    /usr/include/GL/glu.h:340:23: note: expected ‘_GLUfuncptr’ but argument is of type ‘void (*)(const GLfloat *)’
    GLAPI void GLAPIENTRY gluTessCallback (GLUtesselator* tess, GLenum which, _GLUfuncptr CallBackFunc);
    ^
    dino.c: At top level:
    dino.c:443:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
    dino.c


    Please help me sir..

    ReplyDelete
  3. interesante tu codigo , buenos tips

    ReplyDelete
  4. i m not getting the output same as the snap it is not displaying points

    ReplyDelete
  5. Sir,how can I reduce the speed of ghosts?

    ReplyDelete
  6. Informative post !!! thanks for sharing it. BR Softech is a foremost mobile game development company, offering intuitive game development services across different platforms Android, iOS, Windows and Native.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete