OOPM Mini Project Report
PACMAN
Submitted in partial fulfilment of the requirements
of the S. E Semester III in degree of
Bachelor of Computer Engineering
BY
Name of Group Members
KRIMISH RATHOD (34)
MANAS RAJGOLE (33)
SANDEEP PAL (21 )
VAIBHAV PATIL (28)
Guide
Prof.
Department Of Computer Engineering
Shree L. R. Tiwari College Of Engineering
Kanakia Park, Mira Road (E), Thane -401 107, Maharashtra.
October 2022
Table of Contents
1. Introduction
2. System Architecture (If any)
3. Implementation
4. Results
5. Conclusion
6. References
[Link]
Our version of Pac-Man will have several modifications
to the original game. Enemy units will be configured to
attack and defend human players. Our game is based
upon a point system. In a one-person game, if the player
gobbles up a designated number of pellets in the game,
then the player wins. Our game will host a maximum of
two human players competing head to head. When the
game is in two- player mode, a win condition is given to
the highest scoring human player, regardless of AI
effect. Additionally, our game state will contain “Magic
Pellets” which will offer players special powers such as
attack capability, invincibility, wall smashing...etc.
The objective of the game is to eat all of the
dots placed in the maze while avoiding four
colored ghosts — Blinky (red), Pinky (pink),
Inky (cyan), and Clyde (orange) — that pursue
Pac-Man. When Pac-Man eats all of the dots, the
player advances to the next level.
2. System Architecture/Block Diagram
Explanation of Each Modulation
CODE:
try:
import pygame_sdl2
pygame_sdl2.import_as_pygame()
except ImportError:
pass
import pygame
black = (0,0,0)
white = (255,255,255)
blue = (0,0,255)
green = (0,255,0)
red = (255,0,0)
purple = (255,0,255)
yellow = ( 255, 255,0)
Trollicon=[Link]('images/[Link]')
[Link].set_icon(Trollicon)
# This class represents the bar at the bottom that the player controls
class Wall([Link]):
# Constructor function
def __init__(self,x,y,width,height, color):
# Call the parent's constructor
[Link].__init__(self)
# Make a blue wall, of the size specified in the parameters
[Link] = [Link]([width, height])
[Link](color)
# Make our top-left corner the passed-in location.
[Link] = [Link].get_rect()
[Link] = y
[Link] = x
# This creates all the walls in room 1
def setupRoomOne(all_sprites_list):
# Make the walls. (x_pos, y_pos, width, height)
wall_list=[Link]()
# This is a list of walls. Each is in the form [x, y, width,
height]
walls = [ [0,0,6,600],
[0,0,600,6],
[0,600,606,6],
[600,0,6,606],
[300,0,6,66],
[60,60,186,6],
[360,60,186,6],
[60,120,66,6],
[60,120,6,126],
[180,120,246,6],
[300,120,6,66],
[480,120,66,6],
[540,120,6,126],
[120,180,126,6],
[120,180,6,126],
[360,180,126,6],
[480,180,6,126],
[180,240,6,126],
[180,360,246,6],
[420,240,6,126],
[240,240,42,6],
[324,240,42,6],
[240,240,6,66],
[240,300,126,6],
[360,240,6,66],
[0,300,66,6],
[540,300,66,6],
[60,360,66,6],
[60,360,6,186],
[480,360,66,6],
[540,360,6,186],
[120,420,366,6],
[120,420,6,66],
[480,420,6,66],
[180,480,246,6],
[300,480,6,66],
[120,540,126,6],
[360,540,126,6]
]
# Loop through the list. Create the wall, add it to the list
for item in walls:
wall=Wall(item[0],item[1],item[2],item[3],blue)
wall_list.add(wall)
all_sprites_list.add(wall)
# return our new list
return wall_list
def setupGate(all_sprites_list):
gate = [Link]()
[Link](Wall(282,242,42,2,white))
all_sprites_list.add(gate)
return gate
# This class represents the ball
# It derives from the "Sprite" class in Pygame
class Block([Link]):
# Constructor. Pass in the color of the block,
# and its x and y position
def __init__(self, color, width, height):
# Call the parent class (Sprite) constructor
[Link].__init__(self)
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
[Link] = [Link]([width, height])
[Link](white)
[Link].set_colorkey(white)
[Link]([Link],color,[0,0,width,height])
# Fetch the rectangle object that has the dimensions of the
image
# image.
# Update the position of this object by setting the values
# of rect.x and rect.y
[Link] = [Link].get_rect()
# This class represents the bar at the bottom that the player controls
class Player([Link]):
# Set speed vector
change_x=0
change_y=0
# Constructor function
def __init__(self,x,y, filename):
# Call the parent's constructor
[Link].__init__(self)
# Set height, width
[Link] = [Link](filename).convert()
# Make our top-left corner the passed-in location.
[Link] = [Link].get_rect()
[Link] = y
[Link] = x
self.prev_x = x
self.prev_y = y
# Clear the speed of the player
def prevdirection(self):
self.prev_x = self.change_x
self.prev_y = self.change_y
# Change the speed of the player
def changespeed(self,x,y):
self.change_x+=x
self.change_y+=y
# Find a new position for the player
def update(self,walls,gate):
# Get the old position, in case we need to go back to it
old_x=[Link]
new_x=old_x+self.change_x
prev_x=old_x+self.prev_x
[Link] = new_x
old_y=[Link]
new_y=old_y+self.change_y
prev_y=old_y+self.prev_y
# Did this update cause us to hit a wall?
x_collide = [Link](self, walls, False)
if x_collide:
# Whoops, hit a wall. Go back to the old position
[Link]=old_x
# [Link]=prev_y
# y_collide = [Link](self, walls,
False)
# if y_collide:
# # Whoops, hit a wall. Go back to the old position
# [Link]=old_y
# print('a')
else:
[Link] = new_y
# Did this update cause us to hit a wall?
y_collide = [Link](self, walls,
False)
if y_collide:
# Whoops, hit a wall. Go back to the old position
[Link]=old_y
# [Link]=prev_x
# x_collide = [Link](self, walls,
False)
# if x_collide:
# # Whoops, hit a wall. Go back to the old
position
# [Link]=old_x
# print('b')
if gate != False:
gate_hit = [Link](self, gate, False)
if gate_hit:
[Link]=old_x
[Link]=old_y
#Inheritime Player klassist
class Ghost(Player):
# Change the speed of the ghost
def changespeed(self,list,ghost,turn,steps,l):
try:
z=list[turn][2]
if steps < z:
self.change_x=list[turn][0]
self.change_y=list[turn][1]
steps+=1
else:
if turn < l:
turn+=1
elif ghost == "clyde":
turn = 2
else:
turn = 0
self.change_x=list[turn][0]
self.change_y=list[turn][1]
steps = 0
return [turn,steps]
except IndexError:
return [0,0]
Pinky_directions = [
[0,-30,4],
[15,0,9],
[0,15,11],
[-15,0,23],
[0,15,7],
[15,0,3],
[0,-15,3],
[15,0,19],
[0,15,3],
[15,0,3],
[0,15,3],
[15,0,3],
[0,-15,15],
[-15,0,7],
[0,15,3],
[-15,0,19],
[0,-15,11],
[15,0,9]
]
Blinky_directions = [
[0,-15,4],
[15,0,9],
[0,15,11],
[15,0,3],
[0,15,7],
[-15,0,11],
[0,15,3],
[15,0,15],
[0,-15,15],
[15,0,3],
[0,-15,11],
[-15,0,3],
[0,-15,11],
[-15,0,3],
[0,-15,3],
[-15,0,7],
[0,-15,3],
[15,0,15],
[0,15,15],
[-15,0,3],
[0,15,3],
[-15,0,3],
[0,-15,7],
[-15,0,3],
[0,15,7],
[-15,0,11],
[0,-15,7],
[15,0,5]
]
Inky_directions = [
[30,0,2],
[0,-15,4],
[15,0,10],
[0,15,7],
[15,0,3],
[0,-15,3],
[15,0,3],
[0,-15,15],
[-15,0,15],
[0,15,3],
[15,0,15],
[0,15,11],
[-15,0,3],
[0,-15,7],
[-15,0,11],
[0,15,3],
[-15,0,11],
[0,15,7],
[-15,0,3],
[0,-15,3],
[-15,0,3],
[0,-15,15],
[15,0,15],
[0,15,3],
[-15,0,15],
[0,15,11],
[15,0,3],
[0,-15,11],
[15,0,11],
[0,15,3],
[15,0,1],
]
Clyde_directions = [
[-30,0,2],
[0,-15,4],
[15,0,5],
[0,15,7],
[-15,0,11],
[0,-15,7],
[-15,0,3],
[0,15,7],
[-15,0,7],
[0,15,15],
[15,0,15],
[0,-15,3],
[-15,0,11],
[0,-15,7],
[15,0,3],
[0,-15,11],
[15,0,9],
]
pl = len(Pinky_directions)-1
bl = len(Blinky_directions)-1
il = len(Inky_directions)-1
cl = len(Clyde_directions)-1
# Call this function so the Pygame library can initialize itself
[Link]()
# Create an 606x606 sized screen
screen = [Link].set_mode([606, 606])
# This is a list of 'sprites.' Each block in the program is
# added to this list. The list is managed by a class called
'RenderPlain.'
# Set the title of the window
[Link].set_caption('Pacman')
# Create a surface we can draw on
background = [Link](screen.get_size())
# Used for converting color maps and such
background = [Link]()
# Fill the screen with a black background
[Link](black)
clock = [Link]()
[Link]()
font = [Link]("[Link]", 24)
#default locations for Pacman and monstas
w = 303-16 #Width
p_h = (7*60)+19 #Pacman height
m_h = (4*60)+19 #Monster height
b_h = (3*60)+19 #Binky height
i_w = 303-16-32 #Inky width
c_w = 303+(32-16) #Clyde width
def startGame():
all_sprites_list = [Link]()
block_list = [Link]()
monsta_list = [Link]()
pacman_collide = [Link]()
wall_list = setupRoomOne(all_sprites_list)
gate = setupGate(all_sprites_list)
p_turn = 0
p_steps = 0
b_turn = 0
b_steps = 0
i_turn = 0
i_steps = 0
c_turn = 0
c_steps = 0
# Create the player paddle object
Pacman = Player( w, p_h, "images/[Link]" )
all_sprites_list.add(Pacman)
pacman_collide.add(Pacman)
Blinky=Ghost( w, b_h, "images/[Link]" )
monsta_list.add(Blinky)
all_sprites_list.add(Blinky)
Pinky=Ghost( w, m_h, "images/[Link]" )
monsta_list.add(Pinky)
all_sprites_list.add(Pinky)
Inky=Ghost( i_w, m_h, "images/[Link]" )
monsta_list.add(Inky)
all_sprites_list.add(Inky)
Clyde=Ghost( c_w, m_h, "images/[Link]" )
monsta_list.add(Clyde)
all_sprites_list.add(Clyde)
# Draw the grid
for row in range(19):
for column in range(19):
if (row == 7 or row == 8) and (column == 8 or column == 9 or
column == 10):
continue
else:
block = Block(yellow, 4, 4)
# Set a random location for the block
[Link].x = (30*column+6)+26
[Link].y = (30*row+6)+26
b_collide = [Link](block, wall_list,
False)
p_collide = [Link](block,
pacman_collide, False)
if b_collide:
continue
elif p_collide:
continue
else:
# Add the block to the list of objects
block_list.add(block)
all_sprites_list.add(block)
bll = len(block_list)
score = 0
done = False
i = 0
while done == False:
# ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
for event in [Link]():
if [Link] == [Link]:
done=True
if [Link] == [Link]:
if [Link] == pygame.K_LEFT:
[Link](-30,0)
if [Link] == pygame.K_RIGHT:
[Link](30,0)
if [Link] == pygame.K_UP:
[Link](0,-30)
if [Link] == pygame.K_DOWN:
[Link](0,30)
if [Link] == [Link]:
if [Link] == pygame.K_LEFT:
[Link](30,0)
if [Link] == pygame.K_RIGHT:
[Link](-30,0)
if [Link] == pygame.K_UP:
[Link](0,30)
if [Link] == pygame.K_DOWN:
[Link](0,-30)
# ALL EVENT PROCESSING SHOULD GO ABOVE THIS COMMENT
# ALL GAME LOGIC SHOULD GO BELOW THIS COMMENT
[Link](wall_list,gate)
returned =
[Link](Pinky_directions,False,p_turn,p_steps,pl)
p_turn = returned[0]
p_steps = returned[1]
[Link](Pinky_directions,False,p_turn,p_steps,pl)
[Link](wall_list,False)
returned =
[Link](Blinky_directions,False,b_turn,b_steps,bl)
b_turn = returned[0]
b_steps = returned[1]
[Link](Blinky_directions,False,b_turn,b_steps,bl)
[Link](wall_list,False)
returned =
[Link](Inky_directions,False,i_turn,i_steps,il)
i_turn = returned[0]
i_steps = returned[1]
[Link](Inky_directions,False,i_turn,i_steps,il)
[Link](wall_list,False)
returned =
[Link](Clyde_directions,"clyde",c_turn,c_steps,cl)
c_turn = returned[0]
c_steps = returned[1]
[Link](Clyde_directions,"clyde",c_turn,c_steps,cl)
[Link](wall_list,False)
# See if the Pacman block has collided with anything.
blocks_hit_list = [Link](Pacman,
block_list, True)
# Check the list of collisions.
if len(blocks_hit_list) > 0:
score +=len(blocks_hit_list)
# ALL GAME LOGIC SHOULD GO ABOVE THIS COMMENT
# ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT
[Link](black)
wall_list.draw(screen)
[Link](screen)
all_sprites_list.draw(screen)
monsta_list.draw(screen)
text=[Link]("Score: "+str(score)+"/"+str(bll), True, red)
[Link](text, [10, 10])
if score == bll:
doNext("Congratulations, you
won!",145,all_sprites_list,block_list,monsta_list,pacman_collide,wall_
list,gate)
monsta_hit_list = [Link](Pacman,
monsta_list, False)
if monsta_hit_list:
doNext("Game
Over",235,all_sprites_list,block_list,monsta_list,pacman_collide,wall_
list,gate)
# ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT
[Link]()
[Link](10)
def
doNext(message,left,all_sprites_list,block_list,monsta_list,pacman_col
lide,wall_list,gate):
while True:
# ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
for event in [Link]():
if [Link] == [Link]:
[Link]()
if [Link] == [Link]:
if [Link] == pygame.K_ESCAPE:
[Link]()
if [Link] == pygame.K_RETURN:
del all_sprites_list
del block_list
del monsta_list
del pacman_collide
del wall_list
del gate
startGame()
#Grey background
w = [Link]((400,200)) # the size of your rect
w.set_alpha(10) # alpha level
[Link]((128,128,128)) # this fills the entire surface
[Link](w, (100,200)) # (0,0) are the top-left
coordinates
#Won or lost
text1=[Link](message, True, white)
[Link](text1, [left, 233])
text2=[Link]("To play again, press ENTER.", True, white)
[Link](text2, [135, 303])
text3=[Link]("To quit, press ESCAPE.", True, white)
[Link](text3, [165, 333])
[Link]()
[Link](10)
startGame()
[Link]()
Technologies Used
Programming Portion/Software: We learned that it is best to plan out sub-modular
components of the game-engine in detail before actually beginning to code. Although
these segments of code serve fairly trivial functions, such as score-keeping or
refreshing the display, they did take a disproportionate amount of time to
implement due to insufficient prior planning. Although these small segments of code
usually do not fall under the design document, we recommend that smaller
non-critical features should nevertheless be thought out during the beginning of the
implementation phase, prior to actual coding. Critical interface code between
hardware and software should be as centralized as possible. Since we structured the
game engine to have the graphics interface code concentrated in a very small part of
the program, integration was completed within an hour instead of a day. User
customization of game parameters, though not originally part of the design
document, nevertheless proved extremely helpful in the testing stage. The user
customization code, allows for a very quick and simple means of changing the
parameters of the game without actually changing any of the game code.
Programming Portion/Hardware: We learned that it is an absolutely necessity to
start early on the Hardware portion. The more time allocated for this portion of the
project, the better. Additionally, it is apparent that all members of the team should
attempt to understand the specifics of lab 4 and 5. We encountered a developmental
bottleneck due to the fact that only one of our members understood VHDL enough
to code in it without wasting huge amounts of time on it. If every member of our
group had the same experience with VHDL, the development cycle would’ve been
much smoother.
Results
●
Conclusion
1. Start as early as possible, many of our design decisions and game parameters
were done in a hurried fashion and thus were not as well thought out.
2. Set milestones so as to be able to keep track of what is being done and what is
not being done.
3. When coding the software side, for each module, plan out the code-details of
that module before actually coding it. Knowing what the module is supposed
to do is not as effective as knowing how to build it when building it.
4. Get as much experience with VHDL as possible, so as to save effort on the
graphical component of the game.
5. Be sure to leave adequate time for testing and integration.
References
[Link]
[Link]
[Link]
3F&oq=&aqs=chrome.2.69i59i450l3.11710796j0j15&sourceid=chrome&
ie=UTF-8