{"id":22865,"date":"2020-08-21T11:13:29","date_gmt":"2020-08-21T11:13:29","guid":{"rendered":"http:\/\/itsourcecode.com\/?p=22865"},"modified":"2025-04-07T08:09:10","modified_gmt":"2025-04-07T08:09:10","slug":"pacman-in-python-code","status":"publish","type":"post","link":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/","title":{"rendered":"Pacman In Python Code Free to Download"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Pacman In Python Code<\/strong><\/h2>\n\n\n\n<p>The <strong>Pacman In Python Code<\/strong> is written in Python programming language, This <strong>Pacman Game In Python<\/strong> is an arcade game and anyone loves this game.<\/p>\n\n\n\n<p>A <strong>Pacman Game Code In Python<\/strong> concept is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don&#8217;t want to game over.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-pacman-game-in-python-project-information\"><strong>Pacman Game In Python<\/strong>: Project Information<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Project Name:<\/strong><\/td><td> <strong>Pacman Game In Python<\/strong> <\/td><\/tr><tr><td><strong>Language\/s Used:<\/strong><\/td><td>Python (GUI) Based<\/td><\/tr><tr><td><strong>Python version (Recommended):<\/strong><\/td><td>2.x or 3.x<\/td><\/tr><tr><td><strong>Database:<\/strong><\/td><td>None<\/td><\/tr><tr><td><strong>Type:<\/strong><\/td><td>Python App<\/td><\/tr><tr><td><strong>Developer:<\/strong><\/td><td>IT SOURCECODE<\/td><\/tr><tr><td><strong>Updates:<\/strong><\/td><td>0<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p>Anyway, if you want to level up your knowledge in programming especially games in Python, try this new article I\u2019ve made for you&nbsp;<a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/code-for-game-in-python\/\">Code For Game in Python: Python Game Projects With Source Code<\/a>.<\/p>\n\n\n\n<p>This <strong>Pacman Game Python Code<\/strong> also includes a downloadable <strong>Pacman Game Source Code In Python<\/strong>, just find the downloadable source code below and click to start downloading.<\/p>\n\n\n\n<p>To start creating a <strong><a href=\"https:\/\/magpi.raspberrypi.org\/articles\/code-pac-man-in-python\">Pacman<\/a> In Python Code<\/strong>, make sure that you have <strong>PyCharm IDE<\/strong> installed on your computer.<\/p>\n\n\n\n<p>By the way, if you are new to Python programming and don&#8217;t know what Python IDE to use, I have here a list of the<a href=\"https:\/\/itsourcecode.com\/blogs\/best-python-ide-for-windows-2021\/\"> Best Python IDE for Windows, Linux, and Mac OS<\/a> that will suit you. I also have here <a href=\"https:\/\/itsourcecode.com\/blogs\/how-to-download-and-install-latest-version-of-python-on-windows-2021\/\">How to Download and Install the Latest Version of Python on Windows<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to create a Pacman In Python Code<\/strong><\/h2>\n\n\n\n<div class=\"schema-how-to wp-block-yoast-how-to-block\"><p class=\"schema-how-to-description\">Here are the step-by-step guide on <strong>how to create Pacman In Python Code<\/strong><\/p> <ul class=\"schema-how-to-steps\"><li class=\"schema-how-to-step\" id=\"how-to-step-1597912401445\"><strong class=\"schema-how-to-step-name\">Step 1: Create a project name.<\/strong> <p class=\"schema-how-to-step-text\">First, open\u00a0<strong>Pycharm IDE<\/strong>\u00a0and then create a &#8220;<strong>project name<\/strong>&#8221; After creating a project name click the &#8220;<strong>create<\/strong>&#8221; button.<br\/><img decoding=\"async\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Project-Name.png\" alt=\"Pacman Code In Python Project Name\"\/><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1597912438544\"><strong class=\"schema-how-to-step-name\">Step 2: Create a python file.<\/strong> <p class=\"schema-how-to-step-text\">Second, after creating a project name, &#8220;<strong>right click<\/strong>&#8221; your project name and then click &#8220;<strong>new<\/strong>&#8221; After that click the &#8220;<strong>python file<\/strong>&#8220;.<br\/><img decoding=\"async\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-file.png\" alt=\"Pacman Code In Python file\"\/><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1597912460851\"><strong class=\"schema-how-to-step-name\">Step 3: Name your python file.<\/strong> <p class=\"schema-how-to-step-text\">Third, after creating a Python file, Name your Python file after that click &#8220;<strong>enter<\/strong>&#8220;.<br\/><img decoding=\"async\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-file-Name.png\" alt=\"Pacman Code In Python file Name\"\/><\/p> <\/li><li class=\"schema-how-to-step\" id=\"how-to-step-1597912478677\"><strong class=\"schema-how-to-step-name\">Step 4. The actual code.<\/strong> <p class=\"schema-how-to-step-text\">You are free to copy the code given below and download the full source code below.<\/p> <\/li><\/ul><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Python File Enemies<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\nimport random\n\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 576\n\n# Define some colors\nBLACK = (0,0,0)\nWHITE = (255,255,255)\nBLUE = (0,0,255)\nGREEN = (0,255,0)\nRED = (255,0,0)\n\nclass Block(pygame.sprite.Sprite):\n    def __init__(self,x,y,color,width,height):\n        # Call the parent class (Sprite) constructor\n        pygame.sprite.Sprite.__init__(self)\n        # Set the background color and set it to be transparent\n        self.image = pygame.Surface(&#91;width,height])\n        self.image.fill(color)\n        self.rect = self.image.get_rect()\n        self.rect.topleft = (x,y)\n\n\nclass Ellipse(pygame.sprite.Sprite):\n    def __init__(self,x,y,color,width,height):\n        # Call the parent class (Sprite) constructor\n        pygame.sprite.Sprite.__init__(self)\n        # Set the background color and set it to be transparent\n        self.image = pygame.Surface(&#91;width,height])\n        self.image.fill(BLACK)\n        self.image.set_colorkey(BLACK)\n        # Draw the ellipse\n        pygame.draw.ellipse(self.image,color,&#91;0,0,width,height])\n        self.rect = self.image.get_rect()\n        self.rect.topleft = (x,y)\n\n        \nclass Slime(pygame.sprite.Sprite):\n    def __init__(self,x,y,change_x,change_y):\n        # Call the parent class (Sprite) constructor\n        pygame.sprite.Sprite.__init__(self)\n        # Set the direction of the slime\n        self.change_x = change_x\n        self.change_y = change_y\n        # Load image\n        self.image = pygame.image.load(\"slime.png\").convert_alpha()\n        self.rect = self.image.get_rect()\n        self.rect.topleft = (x,y)\n \n\n    def update(self,horizontal_blocks,vertical_blocks):\n        self.rect.x += self.change_x\n        self.rect.y += self.change_y\n        if self.rect.right &lt; 0:\n            self.rect.left = SCREEN_WIDTH\n        elif self.rect.left &gt; SCREEN_WIDTH:\n            self.rect.right = 0\n        if self.rect.bottom &lt; 0:\n            self.rect.top = SCREEN_HEIGHT\n        elif self.rect.top &gt; SCREEN_HEIGHT:\n            self.rect.bottom = 0\n\n        if self.rect.topleft in self.get_intersection_position():\n            direction = random.choice((\"left\",\"right\",\"up\",\"down\"))\n            if direction == \"left\" and self.change_x == 0:\n                self.change_x = -2\n                self.change_y = 0\n            elif direction == \"right\" and self.change_x == 0:\n                self.change_x = 2\n                self.change_y = 0\n            elif direction == \"up\" and self.change_y == 0:\n                self.change_x = 0\n                self.change_y = -2\n            elif direction == \"down\" and self.change_y == 0:\n                self.change_x = 0\n                self.change_y = 2\n                \n\n    def get_intersection_position(self):\n        items = &#91;]\n        for i,row in enumerate(enviroment()):\n            for j,item in enumerate(row):\n                if item == 3:\n                    items.append((j*32,i*32))\n\n        return items\n    \n        \ndef enviroment():\n    grid = ((0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,3,1),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,3,1),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,3,1),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,3,1),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0),\n            (0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,2,0))\n\n    return grid\n\ndef draw_enviroment(screen):\n    for i,row in enumerate(enviroment()):\n        for j,item in enumerate(row):\n            if item == 1:\n                pygame.draw.line(screen, BLUE , &#91;j*32, i*32], &#91;j*32+32,i*32], 3)\n                pygame.draw.line(screen, BLUE , &#91;j*32, i*32+32], &#91;j*32+32,i*32+32], 3)\n            elif item == 2:\n                pygame.draw.line(screen, BLUE , &#91;j*32, i*32], &#91;j*32,i*32+32], 3)\n                pygame.draw.line(screen, BLUE , &#91;j*32+32, i*32], &#91;j*32+32,i*32+32], 3)\n<\/code><\/pre>\n\n\n\n<p>The code given is the python file enemies which shows the different colors of ghost enemies that you want to avoid.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Python File Game<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\nfrom player import Player\nfrom enemies import *\nimport tkinter\nfrom tkinter import messagebox\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 576\n\n# Define some colors\nBLACK = (0,0,0)\nWHITE = (255,255,255)\nBLUE = (0,0,255)\nRED = (255,0,0)\n\nclass Game(object):\n    def __init__(self):\n        self.font = pygame.font.Font(None,40)\n        self.about = False\n        self.game_over = True\n        # Create the variable for the score\n        self.score = 0\n        # Create the font for displaying the score on the screen\n        self.font = pygame.font.Font(None,35)\n        # Create the menu of the game\n        self.menu = Menu((\"Start\",\"About\",\"Exit\"),font_color = WHITE,font_size=60)\n        # Create the player\n        self.player = Player(32,128,\"player.png\")\n        # Create the blocks that will set the paths where the player can go\n        self.horizontal_blocks = pygame.sprite.Group()\n        self.vertical_blocks = pygame.sprite.Group()\n        # Create a group for the dots on the screen\n        self.dots_group = pygame.sprite.Group()\n        # Set the enviroment:\n        for i,row in enumerate(enviroment()):\n            for j,item in enumerate(row):\n                if item == 1:\n                    self.horizontal_blocks.add(Block(j*32+8,i*32+8,BLACK,16,16))\n                elif item == 2:\n                    self.vertical_blocks.add(Block(j*32+8,i*32+8,BLACK,16,16))\n        # Create the enemies\n        self.enemies = pygame.sprite.Group()\n        self.enemies.add(Slime(288,96,0,2))\n        self.enemies.add(Slime(288,320,0,-2))\n        self.enemies.add(Slime(544,128,0,2))\n        self.enemies.add(Slime(32,224,0,2))\n        self.enemies.add(Slime(160,64,2,0))\n        self.enemies.add(Slime(448,64,-2,0))\n        self.enemies.add(Slime(640,448,2,0))\n        self.enemies.add(Slime(448,320,2,0))\n        # Add the dots inside the game\n        for i, row in enumerate(enviroment()):\n            for j, item in enumerate(row):\n                if item != 0:\n                    self.dots_group.add(Ellipse(j*32+12,i*32+12,WHITE,8,8))\n\n        # Load the sound effects\n        self.pacman_sound = pygame.mixer.Sound(\"pacman_sound.ogg\")\n        self.game_over_sound = pygame.mixer.Sound(\"game_over_sound.ogg\")\n\n\n    def process_events(self):\n        for event in pygame.event.get(): # User did something\n            if event.type == pygame.QUIT: # If user clicked close\n                return True\n            self.menu.event_handler(event)\n            if event.type == pygame.KEYDOWN:\n                if event.key == pygame.K_RETURN:\n                    if self.game_over and not self.about:\n                        if self.menu.state == 0:\n                            # ---- START ------\n                            self.__init__()\n                            self.game_over = False\n                        elif self.menu.state == 1:\n                            # --- ABOUT ------\n                            self.about = True\n                        elif self.menu.state == 2:\n                            # --- EXIT -------\n                            # User clicked exit\n                            return True\n\n                elif event.key == pygame.K_RIGHT:\n                    self.player.move_right()\n\n                elif event.key == pygame.K_LEFT:\n                    self.player.move_left()\n\n                elif event.key == pygame.K_UP:\n                    self.player.move_up()\n\n                elif event.key == pygame.K_DOWN:\n                    self.player.move_down()\n                \n                elif event.key == pygame.K_ESCAPE:\n                    self.game_over = True\n                    self.about = False\n\n            elif event.type == pygame.KEYUP:\n                if event.key == pygame.K_RIGHT:\n                    self.player.stop_move_right()\n                elif event.key == pygame.K_LEFT:\n                    self.player.stop_move_left()\n                elif event.key == pygame.K_UP:\n                    self.player.stop_move_up()\n                elif event.key == pygame.K_DOWN:\n                    self.player.stop_move_down()\n\n            elif event.type == pygame.MOUSEBUTTONDOWN:\n                self.player.explosion = True\n                    \n        return False\n\n    def run_logic(self):\n        if not self.game_over:\n            self.player.update(self.horizontal_blocks,self.vertical_blocks)\n            block_hit_list = pygame.sprite.spritecollide(self.player,self.dots_group,True)\n            # When the block_hit_list contains one sprite that means that player hit a dot\n            if len(block_hit_list) &gt; 0:\n                # Here will be the sound effect\n                self.pacman_sound.play()\n                self.score += 1\n            block_hit_list = pygame.sprite.spritecollide(self.player,self.enemies,True)\n            if len(block_hit_list) &gt; 0:\n                self.player.explosion = True\n                self.game_over_sound.play()\n            self.game_over = self.player.game_over\n            self.enemies.update(self.horizontal_blocks,self.vertical_blocks)\n           # tkMessageBox.showinfo(\"GAME OVER!\",\"Final Score = \"+(str)(GAME.score))    \n\n    def display_frame(self,screen):\n        # First, clear the screen to white. Don't put other drawing commands\n        screen.fill(BLACK)\n        # --- Drawing code should go here\n        if self.game_over:\n            if self.about:\n                self.display_message(screen,\"It is an arcade Game\")\n                #\"a maze containing various dots,\\n\"\n                #known as Pac-Dots, and four ghosts.\\n\"\n                #\"The four ghosts roam the maze, trying to kill Pac-Man.\\n\"\n                #\"If any of the ghosts hit Pac-Man, he loses a life;\\n\"\n                #\"the game is over.\\n\")\n            else:\n                self.menu.display_frame(screen)\n        else:\n            # --- Draw the game here ---\n            self.horizontal_blocks.draw(screen)\n            self.vertical_blocks.draw(screen)\n            draw_enviroment(screen)\n            self.dots_group.draw(screen)\n            self.enemies.draw(screen)\n            screen.blit(self.player.image,self.player.rect)\n            #text=self.font.render(\"Score: \"+(str)(self.score), 1,self.RED)\n            #screen.blit(text, (30, 650))\n            # Render the text for the score\n            text = self.font.render(\"Score: \" + str(self.score),True,GREEN)\n            # Put the text on the screen\n            screen.blit(text,&#91;120,20])\n            \n        # --- Go ahead and update the screen with what we've drawn.\n        pygame.display.flip()\n\n    def display_message(self,screen,message,color=(255,0,0)):\n        label = self.font.render(message,True,color)\n        # Get the width and height of the label\n        width = label.get_width()\n        height = label.get_height()\n        # Determine the position of the label\n        posX = (SCREEN_WIDTH \/2) - (width \/2)\n        posY = (SCREEN_HEIGHT \/2) - (height \/2)\n        # Draw the label onto the screen\n        screen.blit(label,(posX,posY))\n\n\nclass Menu(object):\n    state = 0\n    def __init__(self,items,font_color=(0,0,0),select_color=(255,0,0),ttf_font=None,font_size=25):\n        self.font_color = font_color\n        self.select_color = select_color\n        self.items = items\n        self.font = pygame.font.Font(ttf_font,font_size)\n        \n    def display_frame(self,screen):\n        for index, item in enumerate(self.items):\n            if self.state == index:\n                label = self.font.render(item,True,self.select_color)\n            else:\n                label = self.font.render(item,True,self.font_color)\n            \n            width = label.get_width()\n            height = label.get_height()\n            \n            posX = (SCREEN_WIDTH \/2) - (width \/2)\n            # t_h: total height of text block\n            t_h = len(self.items) * height\n            posY = (SCREEN_HEIGHT \/2) - (t_h \/2) + (index * height)\n            \n            screen.blit(label,(posX,posY))\n        \n    def event_handler(self,event):\n        if event.type == pygame.KEYDOWN:\n            if event.key == pygame.K_UP:\n                if self.state &gt; 0:\n                    self.state -= 1\n            elif event.key == pygame.K_DOWN:\n                if self.state &lt; len(self.items) -1:\n                    self.state += 1\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The code given is the Python file game which is in this python file have many function modules.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Python File Player<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\n\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 576\n\n# Define some colors\nBLACK = (0,0,0)\nWHITE = (255,255,255)\n\nclass Player(pygame.sprite.Sprite):\n    change_x = 0\n    change_y = 0\n    explosion = False\n    game_over = False\n    def __init__(self,x,y,filename):\n        # Call the parent class (sprite) constructor\n        pygame.sprite.Sprite.__init__(self)\n        self.image = pygame.image.load(filename).convert()\n        self.image.set_colorkey(BLACK)\n        self.rect = self.image.get_rect()\n        self.rect.topleft = (x,y)\n        # Load image which will be for the animation\n        img = pygame.image.load(\"walk.png\").convert()\n        # Create the animations objects\n        self.move_right_animation = Animation(img,32,32)\n        self.move_left_animation = Animation(pygame.transform.flip(img,True,False),32,32)\n        self.move_up_animation = Animation(pygame.transform.rotate(img,90),32,32)\n        self.move_down_animation = Animation(pygame.transform.rotate(img,270),32,32)\n        # Load explosion image\n        img = pygame.image.load(\"explosion.png\").convert()\n        self.explosion_animation = Animation(img,30,30)\n        # Save the player image\n        self.player_image = pygame.image.load(filename).convert()\n        self.player_image.set_colorkey(BLACK)\n\n    def update(self,horizontal_blocks,vertical_blocks):\n        if not self.explosion:\n            if self.rect.right &lt; 0:\n                self.rect.left = SCREEN_WIDTH\n            elif self.rect.left &gt; SCREEN_WIDTH:\n                self.rect.right = 0\n            if self.rect.bottom &lt; 0:\n                self.rect.top = SCREEN_HEIGHT\n            elif self.rect.top &gt; SCREEN_HEIGHT:\n                self.rect.bottom = 0\n            self.rect.x += self.change_x\n            self.rect.y += self.change_y\n\n            # This will stop the user for go up or down when it is inside of the box\n\n            for block in pygame.sprite.spritecollide(self,horizontal_blocks,False):\n                self.rect.centery = block.rect.centery\n                self.change_y = 0\n            for block in pygame.sprite.spritecollide(self,vertical_blocks,False):\n                self.rect.centerx = block.rect.centerx\n                self.change_x = 0\n\n            # This will cause the animation to start\n            \n            if self.change_x &gt; 0:\n                self.move_right_animation.update(10)\n                self.image = self.move_right_animation.get_current_image()\n            elif self.change_x &lt; 0:\n                self.move_left_animation.update(10)\n                self.image = self.move_left_animation.get_current_image()\n\n            if self.change_y &gt; 0:\n                self.move_down_animation.update(10)\n                self.image = self.move_down_animation.get_current_image()\n            elif self.change_y &lt; 0:\n                self.move_up_animation.update(10)\n                self.image = self.move_up_animation.get_current_image()\n        else:\n            if self.explosion_animation.index == self.explosion_animation.get_length() -1:\n                pygame.time.wait(500)\n                self.game_over = True\n            self.explosion_animation.update(12)\n            self.image = self.explosion_animation.get_current_image()\n            \n\n    def move_right(self):\n        self.change_x = 3\n\n    def move_left(self):\n        self.change_x = -3\n\n    def move_up(self):\n        self.change_y = -3\n\n    def move_down(self):\n        self.change_y = 3\n\n    def stop_move_right(self):\n        if self.change_x != 0:\n            self.image = self.player_image\n        self.change_x = 0\n\n    def stop_move_left(self):\n        if self.change_x != 0:\n            self.image = pygame.transform.flip(self.player_image,True,False)\n        self.change_x = 0\n\n    def stop_move_up(self):\n        if self.change_y != 0:\n            self.image = pygame.transform.rotate(self.player_image,90)\n        self.change_y = 0\n\n    def stop_move_down(self):\n        if self.change_y != 0:\n            self.image = pygame.transform.rotate(self.player_image,270)\n        self.change_y = 0\n\n\n\nclass Animation(object):\n    def __init__(self,img,width,height):\n        # Load the sprite sheet\n        self.sprite_sheet = img\n        # Create a list to store the images\n        self.image_list = &#91;]\n        self.load_images(width,height)\n        # Create a variable which will hold the current image of the list\n        self.index = 0\n        # Create a variable that will hold the time\n        self.clock = 1\n        \n    def load_images(self,width,height):\n        # Go through every single image in the sprite sheet\n        for y in range(0,self.sprite_sheet.get_height(),height):\n            for x in range(0,self.sprite_sheet.get_width(),width): \n                # load images into a list\n                img = self.get_image(x,y,width,height)\n                self.image_list.append(img)\n\n    def get_image(self,x,y,width,height):\n        # Create a new blank image\n        image = pygame.Surface(&#91;width,height]).convert()\n        # Copy the sprite from the large sheet onto the smaller\n        image.blit(self.sprite_sheet,(0,0),(x,y,width,height))\n        # Assuming black works as the transparent color\n        image.set_colorkey((0,0,0))\n        # Return the image\n        return image\n\n    def get_current_image(self):\n        return self.image_list&#91;self.index]\n\n    def get_length(self):\n        return len(self.image_list)\n\n    def update(self,fps=30):\n        step = 30 \/\/ fps\n        l = range(1,30,step)\n        if self.clock == 30:\n            self.clock = 1\n        else:\n            self.clock += 1\n\n        if self.clock in l:\n            # Increase index\n            self.index += 1\n            if self.index == len(self.image_list):\n                self.index = 0\n\n            \n    \n        \n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The code given is the Python file player that can manage the game.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Code Given Below Is For The Python File Main<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\nfrom game import Game\n\nSCREEN_WIDTH = 800\nSCREEN_HEIGHT = 576\n\ndef main():\n    # Initialize all imported pygame modules\n    pygame.init()\n    # Set the width and height of the screen &#91;width, height]\n    screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))\n    # Set the current window caption\n    pygame.display.set_caption(\"PACMAN\")\n    #Loop until the user clicks the close button.\n    done = False\n    # Used to manage how fast the screen updates\n    clock = pygame.time.Clock()\n    # Create a game object\n    game = Game()\n    # -------- Main Program Loop -----------\n    while not done:\n        # --- Process events (keystrokes, mouse clicks, etc)\n        done = game.process_events()\n        # --- Game logic should go here\n        game.run_logic()\n        # --- Draw the current frame\n        game.display_frame(screen)\n        # --- Limit to 30 frames per second\n        clock.tick(30)\n        #tkMessageBox.showinfo(\"GAME OVER!\",\"Final Score = \"+(str)(GAME.score))\n    # Close the window and quit.\n    # If you forget this line, the program will 'hang'\n    # on exit if running from IDLE.\n    pygame.quit()\n\nif __name__ == '__main__':\n    main()\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The code given is the Python file main which is in this Python file connected to all the given Python files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Output:<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"801\" height=\"609\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1.png\" alt=\"\" class=\"wp-image-22875\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1.png 801w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1-300x228.png 300w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1-768x584.png 768w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1-696x529.png 696w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1-552x420.png 552w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output1-80x60.png 80w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"801\" height=\"607\" src=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2.png\" alt=\"\" class=\"wp-image-22876\" srcset=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2.png 801w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2-300x227.png 300w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2-768x582.png 768w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2-696x527.png 696w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2-554x420.png 554w, https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Output2-80x60.png 80w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Downloadable Source Code<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-In-Python-Code.zip\"><strong>DOWNLOAD<\/strong><\/a><\/div>\n<\/div>\n\n\n\n<p>I have here the list of&nbsp;<a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/best-python-project-with-source-code-2020\/\">Best Python Projects with Source code free to download for free<\/a>, I hope this can help you a lot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>The&nbsp;<strong>Pacman Code In Python<\/strong>&nbsp;is written in Python programming language, Python is very smooth to research the syntax emphasizes readability and it is able to reduce time ingesting in developing.<\/p>\n\n\n\n<p>Also, this tutorial is the simplest way for beginners or students to enhance their logical skills in programming. This game project is a way for students or beginners to design and develop games.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-e2102932-3919-4751-8ae9-e2e013e9a506\"><strong>Related Articles<\/strong><\/h2>\n\n\n\n<ul id=\"block-88f08f8a-129d-4b30-927c-64214788c140\" class=\"wp-block-list\">\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/snakes-and-ladders-game-in-python-with-source-code\/\">Snakes and Ladders Game in Python with Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/code-for-game-in-python\/\">Code For Game in Python: Python Game Projects With Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/stickman-game-in-python-with-source-code\/\">Stickman Game in Python with Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/tank-game-python-with-source-code\/\">Tank Game Python with Source Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/tetris-in-python-code\/\">Tetris In Python Code<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-0863d1d8-f13d-4559-af50-69cbc78f862a\"><strong>Inquiries<\/strong><\/h2>\n\n\n\n<p id=\"block-da714d96-2ee9-4dd6-bfb6-24791bd6ca8f\">If you have any questions or suggestions about&nbsp;<strong>Pacman Code In Python<\/strong>, please feel free to leave a comment below.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pacman In Python Code The Pacman In Python Code is written in Python programming language, This Pacman Game In Python is an arcade game and anyone loves this game. A &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Pacman In Python Code Free to Download\" class=\"read-more button\" href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#more-22865\" aria-label=\"Read more about Pacman In Python Code Free to Download\">Read more<\/a><\/p>\n","protected":false},"author":1767,"featured_media":118047,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19632,60567],"tags":[37577,37574,37585,37580,37590,37589,37571,37593,37570,37567,37583,37568,37587,37569,37573,37591,37582,37578,37584,37572,37579,37586,21761,21762,37592,37581],"class_list":["post-22865","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-projects","category-pygame","tag-code-pacman-in-python","tag-pacman-ai-python","tag-pacman-algorithm-python","tag-pacman-dfs-search-python","tag-pacman-game-code-in-python","tag-pacman-game-in-python","tag-pacman-game-python-code","tag-pacman-game-source-code-in-python","tag-pacman-in-python","tag-pacman-in-python-code","tag-pacman-on-python","tag-pacman-python","tag-pacman-python-3","tag-pacman-python-code","tag-pacman-python-code-github","tag-pacman-python-game","tag-pacman-python-game-code","tag-pacman-python-github","tag-pacman-python-tutorial","tag-python-pacman-game","tag-python-pacman-game-code","tag-python-pacman-search-solution","tag-python-projects-with-source-code","tag-python-source-code","tag-simple-pacman-game-in-python","tag-simple-pacman-python-code","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Pacman In Python Code Free to Download<\/title>\n<meta name=\"description\" content=\"The Pacman Game In Python Code is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don&#039;t want to game over.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pacman In Python Code Free to Download\" \/>\n<meta property=\"og:description\" content=\"The Pacman Game In Python Code is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don&#039;t want to game over.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Itsourcecode.com\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-21T11:13:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-07T08:09:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/pacman-in-python-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"angel jude suarez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"angel jude suarez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/\"},\"author\":{\"name\":\"angel jude suarez\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/dafb6a91b43e60537c56e3e1d227d460\"},\"headline\":\"Pacman In Python Code Free to Download\",\"datePublished\":\"2020-08-21T11:13:29+00:00\",\"dateModified\":\"2025-04-07T08:09:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/\"},\"wordCount\":618,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/pacman-in-python-1.png\",\"keywords\":[\"code pacman in python\",\"pacman ai python\",\"pacman algorithm python\",\"pacman dfs search python\",\"pacman game code in python\",\"pacman game in python\",\"pacman game python code\",\"pacman game source code in python\",\"pacman in python\",\"Pacman In Python Code\",\"pacman on python\",\"pacman python\",\"pacman python 3\",\"pacman python code\",\"pacman python code github\",\"pacman python game\",\"pacman python game code\",\"pacman python github\",\"pacman python tutorial\",\"python pacman game\",\"python pacman game code\",\"python pacman search solution\",\"python projects with source code\",\"python source code\",\"simple pacman game in python\",\"simple pacman python code\"],\"articleSection\":[\"Best Python Projects With Source Code\",\"Pygame Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/\",\"name\":\"Pacman In Python Code Free to Download\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/pacman-in-python-1.png\",\"datePublished\":\"2020-08-21T11:13:29+00:00\",\"dateModified\":\"2025-04-07T08:09:10+00:00\",\"description\":\"The Pacman Game In Python Code is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don't want to game over.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#primaryimage\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/pacman-in-python-1.png\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/pacman-in-python-1.png\",\"width\":1024,\"height\":576,\"caption\":\"pacman in python with source code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsourcecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pacman In Python Code Free to Download\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/\",\"name\":\"Itsourcecode.com\",\"description\":\"Partner In Your Coding Journey!\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsourcecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\",\"name\":\"itsourcecode\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"width\":409,\"height\":409,\"caption\":\"itsourcecode\"},\"logo\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\"},\"description\":\"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!\",\"sameAs\":[\"https:\\\/\\\/itsourcecode.com\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/dafb6a91b43e60537c56e3e1d227d460\",\"name\":\"angel jude suarez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718\",\"caption\":\"angel jude suarez\"},\"description\":\"Hello programmers, I'm Angel Jude Reyes Suarez, a student and a programmer of different programming languages like Python, Java, JavaScript, PHP, C, C++, Vb.net, and MySQL. and I have also knowledge in developing system or websites from Front-End to Back-End. and also a writer of itsourcecode.com.\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/author\\\/angeljudesuarez\\\/\"},{\"@type\":\"HowTo\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#howto-1\",\"name\":\"Pacman In Python Code Free to Download\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#article\"},\"description\":\"Here are the step-by-step guide on &lt;strong>how to create Pacman In Python Code&lt;\\\/strong>\",\"step\":[{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#how-to-step-1597912401445\",\"name\":\"Step 1: Create a project name.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"First, open\u00a0Pycharm IDE\u00a0and then create a \\\"project name\\\" After creating a project name click the \\\"create\\\" button.\"}],\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#schema-image-09c93800f4327375322bc750312e80d1\",\"url\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Pacman-Code-In-Python-Project-Name.png\",\"contentUrl\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Pacman-Code-In-Python-Project-Name.png\"}},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#how-to-step-1597912438544\",\"name\":\"Step 2: Create a python file.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"Second, after creating a project name, \\\"right click\\\" your project name and then click \\\"new\\\" After that click the \\\"python file\\\".\"}],\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#schema-image-ee8ea8c65dcd605ac39ca5566093520f\",\"url\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Pacman-Code-In-Python-file.png\",\"contentUrl\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Pacman-Code-In-Python-file.png\"}},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#how-to-step-1597912460851\",\"name\":\"Step 3: Name your python file.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"Third, after creating a Python file, Name your Python file after that click \\\"enter\\\".\"}],\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#schema-image-b1564a3a038740d081931d70d340d3d1\",\"url\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Pacman-Code-In-Python-file-Name.png\",\"contentUrl\":\"http:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/Pacman-Code-In-Python-file-Name.png\"}},{\"@type\":\"HowToStep\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/free-projects\\\/python-projects\\\/pacman-in-python-code\\\/#how-to-step-1597912478677\",\"name\":\"Step 4. The actual code.\",\"itemListElement\":[{\"@type\":\"HowToDirection\",\"text\":\"You are free to copy the code given below and download the full source code below.\"}]}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Pacman In Python Code Free to Download","description":"The Pacman Game In Python Code is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don't want to game over.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/","og_locale":"en_US","og_type":"article","og_title":"Pacman In Python Code Free to Download","og_description":"The Pacman Game In Python Code is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don't want to game over.","og_url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/","og_site_name":"Itsourcecode.com","article_published_time":"2020-08-21T11:13:29+00:00","article_modified_time":"2025-04-07T08:09:10+00:00","og_image":[{"width":1024,"height":576,"url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/pacman-in-python-1.png","type":"image\/png"}],"author":"angel jude suarez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"angel jude suarez","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#article","isPartOf":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/"},"author":{"name":"angel jude suarez","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/dafb6a91b43e60537c56e3e1d227d460"},"headline":"Pacman In Python Code Free to Download","datePublished":"2020-08-21T11:13:29+00:00","dateModified":"2025-04-07T08:09:10+00:00","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/"},"wordCount":618,"commentCount":4,"publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"image":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/pacman-in-python-1.png","keywords":["code pacman in python","pacman ai python","pacman algorithm python","pacman dfs search python","pacman game code in python","pacman game in python","pacman game python code","pacman game source code in python","pacman in python","Pacman In Python Code","pacman on python","pacman python","pacman python 3","pacman python code","pacman python code github","pacman python game","pacman python game code","pacman python github","pacman python tutorial","python pacman game","python pacman game code","python pacman search solution","python projects with source code","python source code","simple pacman game in python","simple pacman python code"],"articleSection":["Best Python Projects With Source Code","Pygame Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/","name":"Pacman In Python Code Free to Download","isPartOf":{"@id":"https:\/\/itsourcecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#primaryimage"},"image":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/pacman-in-python-1.png","datePublished":"2020-08-21T11:13:29+00:00","dateModified":"2025-04-07T08:09:10+00:00","description":"The Pacman Game In Python Code is quite simple. Pacman eats dots in a maze to score points. Avoid the ghosts if you don't want to game over.","breadcrumb":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#primaryimage","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/pacman-in-python-1.png","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/pacman-in-python-1.png","width":1024,"height":576,"caption":"pacman in python with source code"},{"@type":"BreadcrumbList","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsourcecode.com\/"},{"@type":"ListItem","position":2,"name":"Pacman In Python Code Free to Download"}]},{"@type":"WebSite","@id":"https:\/\/itsourcecode.com\/#website","url":"https:\/\/itsourcecode.com\/","name":"Itsourcecode.com","description":"Partner In Your Coding Journey!","publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsourcecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc","name":"itsourcecode","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","width":409,"height":409,"caption":"itsourcecode"},"logo":{"@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg"},"description":"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!","sameAs":["https:\/\/itsourcecode.com\/"]},{"@type":"Person","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/dafb6a91b43e60537c56e3e1d227d460","name":"angel jude suarez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","url":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/49f87b924bdd4e5fcbc3635ed3f7af29.jpg?ver=1776429718","caption":"angel jude suarez"},"description":"Hello programmers, I'm Angel Jude Reyes Suarez, a student and a programmer of different programming languages like Python, Java, JavaScript, PHP, C, C++, Vb.net, and MySQL. and I have also knowledge in developing system or websites from Front-End to Back-End. and also a writer of itsourcecode.com.","url":"https:\/\/itsourcecode.com\/author\/angeljudesuarez\/"},{"@type":"HowTo","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#howto-1","name":"Pacman In Python Code Free to Download","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#article"},"description":"Here are the step-by-step guide on &lt;strong>how to create Pacman In Python Code&lt;\/strong>","step":[{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#how-to-step-1597912401445","name":"Step 1: Create a project name.","itemListElement":[{"@type":"HowToDirection","text":"First, open\u00a0Pycharm IDE\u00a0and then create a \"project name\" After creating a project name click the \"create\" button."}],"image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#schema-image-09c93800f4327375322bc750312e80d1","url":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Project-Name.png","contentUrl":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-Project-Name.png"}},{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#how-to-step-1597912438544","name":"Step 2: Create a python file.","itemListElement":[{"@type":"HowToDirection","text":"Second, after creating a project name, \"right click\" your project name and then click \"new\" After that click the \"python file\"."}],"image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#schema-image-ee8ea8c65dcd605ac39ca5566093520f","url":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-file.png","contentUrl":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-file.png"}},{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#how-to-step-1597912460851","name":"Step 3: Name your python file.","itemListElement":[{"@type":"HowToDirection","text":"Third, after creating a Python file, Name your Python file after that click \"enter\"."}],"image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#schema-image-b1564a3a038740d081931d70d340d3d1","url":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-file-Name.png","contentUrl":"http:\/\/itsourcecode.com\/wp-content\/uploads\/2020\/08\/Pacman-Code-In-Python-file-Name.png"}},{"@type":"HowToStep","url":"https:\/\/itsourcecode.com\/free-projects\/python-projects\/pacman-in-python-code\/#how-to-step-1597912478677","name":"Step 4. The actual code.","itemListElement":[{"@type":"HowToDirection","text":"You are free to copy the code given below and download the full source code below."}]}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/22865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/users\/1767"}],"replies":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/comments?post=22865"}],"version-history":[{"count":12,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/22865\/revisions"}],"predecessor-version":[{"id":127633,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/22865\/revisions\/127633"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media\/118047"}],"wp:attachment":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media?parent=22865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/categories?post=22865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/tags?post=22865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}