0% found this document useful (0 votes)
32 views7 pages

Player Class:: Methods: 1

This class contains and manages data for players (Pac-Man) and enemies. It includes methods to initialize their positions, update attributes, draw them, define movement and paths, calculate timing, and manage interactions like eating coins. The player methods initialize Pac-Man's starting position, get pixel positions, calculate movement time, check if movement is allowed, update position and eating coins. The enemy methods initialize positions, update targets/positions, get pixel positions, calculate movement time, draw enemies, define personalities/colors/speeds, set targets, determine movement paths using breadth-first search, and find the next cell to search.

Uploaded by

Abid Ineha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views7 pages

Player Class:: Methods: 1

This class contains and manages data for players (Pac-Man) and enemies. It includes methods to initialize their positions, update attributes, draw them, define movement and paths, calculate timing, and manage interactions like eating coins. The player methods initialize Pac-Man's starting position, get pixel positions, calculate movement time, check if movement is allowed, update position and eating coins. The enemy methods initialize positions, update targets/positions, get pixel positions, calculate movement time, draw enemies, define personalities/colors/speeds, set targets, determine movement paths using breadth-first search, and find the next cell to search.

Uploaded by

Abid Ineha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PLAYER CLASS: This class contains and manage data of player(pacman).

It consists of
methods which initialize, update the player’s attribute. Further more it has method which draws
player, make player eat coin, defines pixel position, shows time taken to move and tell the extent up
to which player can move(walls).

METHODS:

1.

This method initializes starting position of pacman with reference to axes, grid position, pixel
position, direction of pacman and then store in a stored direction variable, allows the movement of
pacman in able to move variable and further more sets the score, speed and live.

2.

It is used to get the pixel position.

3.

This method calculates the time taken by player to move. This calculation of time is used in a
method which is representing the position.

4.

The can move is defining that whether the pacman can move in a particular direction. If pacman is
moving towards wall it will not allow it.

5.

It first checks if pacman is able to move than it update it’s position , direction and grid position with
respect to pix position. It checks if there is any coin on the way it calls eat coin function which make
pacman eat coin.
6.

This method draw the structure of pacman defining its place,color,size and draw player lives.

7.

On coin method checks whether there is coin on the grid or not , if there are any then it calls eat coin
method which after pacman has eaten coin removes that coin from the grid and updates the score
by +1.

ENEMY CLASS: This class contains data about enemies and manage them. It
consists of methods which draw enemies and define their personalities, create pathway for
them, define target and some basic functions like enemies’ speed, pixel position and time to
move.

METHODS:
1.DEFAULT CONSTRUCTOR

This method initializes starting position of enemies with reference to axes, grid
position(here cells are present ), direction(initial direction is at 0,0 of grid) ,
personality(it is defined in another function in which 4 personalities are there),
speed(are also according to their personality), color of enemies.
2.UPDATE
It defines the target to enemies, sets pixel position and grid position. Here if
target is not at the grid than it updates the pixel position by adding direction
w.r.t speed. The grid position on x-axis is set by width and on y-axis its set by
height.

3.GET_PIX_POS

It is used to get the pixel position. Vector class from pygame is used here, by
using grid position and the cells’ width and height we are getting pixel position.
Pixel position on x and y axis is set by width and height respectively and top
bottom buffer.
4.TIME_TO_MOVE
This method calculates the time taken by player to move. This calculation of
time is used in a method which is representing the position.
5.DRAW

This method is simply drawing enemies and defining their attributes.

6.SET_PERSONALITY

This method will be defining what type of personality our enemy may have, as there are 4
Enemies. A number is given to each type of enemy to describe it’s personality.
7.SET_COLOR
The set color method will have each enemy a different color according to their number.
8.SET_SPEED

This method will set the speed of enemies w.r.t their personality.

9.SET_TARGET

If the personality of enemy is as defined in this method than it will take that pathway which
will lead it to the pacman.

10.MOVE
In this method it is defined which enemy will choose which path.

11.GET_RANDOM_DIRECTION

It is the direction defined for the enemy which has scared personality , so that enemy will take
random directions.

12.GET_PATH_DIRECTION

It is simply providing the path direction of target(pacman) to enemy which is following pacman.

13.BFS(BREADTH FIRST SEARCH)


Here, BFS stands for breadth first search,the enemies are searching for pacman in grid. Enemies are
defined as neighbours in this metho and there co-ordinate are defined. And the current word
defines the present state of enemies.

14.FIND_NEXT_CELL_IN_PATH

The thing defined here is that ,If the enemies could not find us in one cell then they will search for us
in next cell(A grid contains so many cells).

You might also like