{"id":8955,"date":"2022-03-13T18:30:46","date_gmt":"2022-03-13T13:00:46","guid":{"rendered":"https:\/\/copyassignment.com\/?p=8955"},"modified":"2022-11-19T14:20:44","modified_gmt":"2022-11-19T08:50:44","slug":"flappy-bird-in-python-pygame-with-source-code","status":"publish","type":"post","link":"https:\/\/copyassignment.com\/flappy-bird-in-python-pygame-with-source-code\/","title":{"rendered":"Flappy Bird In Python Pygame with source code"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">OVERVIEW OF THE PROJECT<\/h2>\n\n\n\n<p>Hi there, welcome to the copyassignment hope you all are doing wonderful. Today, we are here to make a very interesting game <strong>Flappy Bird In Python Pygame<\/strong>. Hope you are familiar with this entertaining and very fascinating game.<\/p>\n\n\n\n\n\n\n\n<p>We would see how we can code the game <strong>Flappy bird from Scratch<\/strong>. My aim is to provide you with the knowledge of game making with lots of logic building which can help you in your future projects.<\/p>\n\n\n\n<p>We are creating this game with the help of the most popular and easy-to-understand programming language &#8216;PYTHON&#8217; also this is my personal favorite programming language. <\/p>\n\n\n\n<p>We will use Pygame which is a set of modules for creating our game Flappy bird. Hope you all are excited so much because I can feel your vibe from here.<\/p>\n\n\n\n<p>So, don&#8217;t worry about any hard technical terms we&#8217;ll guide you from scratch to make this game and I&#8217;ll try my best to clear all the concepts which we will be using to make this.<\/p>\n\n\n\n<p>Before going further let&#8217;s have a look at the game we are going to make today just be with me and will make this happen. Just let go of all the thoughts from your mind and be patient and just be with us.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Flappy Bird With Python Pygame || Source Code in Description\" width=\"500\" height=\"281\" data-src=\"https:\/\/www.youtube.com\/embed\/rRb9mrvcXxU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color\"><a href=\"https:\/\/drive.google.com\/drive\/folders\/1QMbd2b-l_dsE38nhIw_g9gOvSzbUj_9R?usp=sharing\" target=\"_blank\" rel=\"noreferrer noopener\">LINK FOR FLAPPY BIRD SOURCE CODE SPRITES AND MUSIC<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PREREQUISITE \/PREFACE OF THE GAME<\/h2>\n\n\n\n<p>Before starting to code let me tell you the requirements and also let me explain some terms that we are going to use in this project because we are here for beginners also.<br>These are just some basics you can also ignore this section if you are familiar with it already. In this project, you just need basic knowledge of python and some Logic and you are good to go.<\/p>\n\n\n\n<p>So, without any further delay let\u2019s start our journey. <strong>But before that make sure that you have:-<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a><\/strong> is installed on your computer.<\/li>\n\n\n\n<li>A Code Editor because it makes your work easy. I use <strong><a href=\"https:\/\/code.visualstudio.com\/Download\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Visual Studio Code<\/a> <\/strong>you can use <strong><a href=\"https:\/\/www.jetbrains.com\/pycharm\/download\/#section=windows\" target=\"_blank\" rel=\"noreferrer noopener\">Pycharm <\/a><\/strong>or any editor you want. It doesn\u2019t matter.<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/www.pygame.org\/\">Pygame<\/a><\/strong> library is installed because if not then open the command prompt or terminal on your computer and then type one of the following commands in the terminal:<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"has-white-color has-vivid-purple-background-color has-text-color has-background\">1.\u201dpip install pygame\u201d<\/p>\n\n\n\n<p class=\"has-white-color has-vivid-purple-background-color has-text-color has-background\">2.\u201dpy -m pip install -U pygame \u2013user\u201d<\/p>\n\n\n\n<p class=\"has-white-color has-vivid-purple-background-color has-text-color has-background\">3.\u201dpy -m pip install pygame\u201d<\/p>\n<\/div><\/div>\n\n\n\n<p>Now, we have installed Pygame on our computer. Let&#8217;s quickly understand What the Pygame is and what does it do?<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">STARTING WITH THE Flappy Bird In Python Pygame<\/h2>\n\n\n\n<p>Pygame is a set of modules or we can say a library by Python which we use for making games.<br>There are 4 things important in the Pygame: &#8211;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Game Loop<\/li>\n\n\n\n<li>Events <\/li>\n\n\n\n<li>Sprites<\/li>\n\n\n\n<li>Sounds<\/li>\n<\/ol>\n\n\n\n<p><strong>Game loop<\/strong> is an infinite loop in which we blit our <strong>Sprites <\/strong>and play <strong>Sounds <\/strong>by handling or accessing <strong>Events <\/strong>from the user. <\/p>\n\n\n\n<p>Blitting of the <strong>Sprites<\/strong> frequently in a <strong>loop<\/strong> gives the <strong>illusion<\/strong> to the user that they are <strong>playing the game.<\/strong><\/p>\n\n\n\n<p>However it&#8217;s just the game of removing images and blitting new ones, but it happens so fast that&#8217;s why our eyes can&#8217;t detect it and because of that our sensory nerves make it a game.<\/p>\n\n\n\n<p>After having all this now we can start to code but before that, I also said that I&#8217;ll introduce some basic terms that we are going to use in our Game. So, have a look at these terms:-<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Function<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>init()<\/td><td>Initializes all of the imported Pygame modules (returns a tuple indicating success and failure of initializations)<\/td><\/tr><tr><td>set_mode()<\/td><td>Takes a tuple or a list as its parameter to create a surface (tuple preferred)<\/td><\/tr><tr><td>update()<\/td><td>Updates the screen<\/td><\/tr><tr><td>quit()<\/td><td>Used to uninitialized everything<\/td><\/tr><tr><td>set_caption()<\/td><td>Will set the caption text on the top of the display screen<\/td><\/tr><tr><td>event.get()<\/td><td>Returns list of all events<\/td><\/tr><tr><td>time.Clock()<\/td><td>Helps track time<\/td><\/tr><tr><td>font.SysFont()              <\/td><td>Will create a Pygame font from the System font resources<\/td><\/tr><tr><td>mouse.get_pos()<\/td><td>Returns the coordinates of the Mouse cursor<\/td><\/tr><tr><td>get_height()   <\/td><td>Gives the height of the object<\/td><\/tr><tr><td>get_width()<\/td><td>Gives the Width of the Object<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><br>SOME BASIC FUNCTIONS AND THEIR USES<\/figcaption><\/figure>\n\n\n\n<p>Now, we are ready. So let&#8217;s start this beautiful journey and I said earlier be with us and you will end up having a great project.<\/p>\n\n\n\n<div style=\"text-align:center\" class=\"wp-block-atomic-blocks-ab-button ab-block-button\"><a href=\"https:\/\/copyassignment.com\/top-100-python-projects-with-source-code\/\" class=\"ab-button ab-button-shape-rounded ab-button-size-medium\" style=\"color:#ffffff;background-color:#3373dc\">Best 100+ Python Projects with source code<\/a><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">CREATING GAME WINDOW &amp; ADDING SPRITES AND SOUNDS<\/h3>\n\n\n\n<p>We will make a folder for ex- <strong>&#8216;flappy bird&#8217; <\/strong>in this case in which we will keep all our sprites and sounds to make it easy. Don&#8217;t worry I&#8217;ll provide you with that. <\/p>\n\n\n\n<p>Now, we will create our game window for that first we&#8217;ll have to import Pygame and other modules too which we are going to use in this game.<\/p>\n\n\n\n<p>So for importing Pygame we&#8217;ll just write &#8216;import pygame&#8217; and it will import the pygame for us. Let&#8217;s look at the code below for a better understanding of Flappy Bird In Python Pygame.<\/p>\n\n\n\n<p>We&#8217;ll create a file <strong>&#8216;main.py&#8217;<\/strong> in which we are going to write all of our codes you can name anything you want but there shouldn&#8217;t be any module&#8217;s name otherwise it may throw an error.<\/p>\n\n\n\n<p>Our files will look something like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-2.png?w=1012\" alt=\"files hierarchy Flappy Bird In Pygame Python\" class=\"wp-image-262 lazyload\" width=\"780\" height=\"460\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 780px; --smush-placeholder-aspect-ratio: 780\/460;\" \/><figcaption class=\"wp-element-caption\">                                                               FILES HIERARCHY<\/figcaption><\/figure>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports<\/pre><\/div>\n\n\n\n<p>Now, run the code and check whether our modules are imported. If they are imported, there won&#8217;t be any error, but if it throws an error, you have to check the code again whether you have misspelled or pygame isn&#8217;t installed successfully.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CREATING GLOBAL VARIABLES FOR FLAPPY BIRD IN PYTHON PYGAME<\/h3>\n\n\n\n<p>After importing we&#8217;ll create some <strong>&#8216;Global Variables&#8217;<\/strong> which we will use throughout the game. So let&#8217;s create some <strong>&#8216;Global Variables&#8217;<\/strong>. Our game window will also be a Global variable. So, look at the code below.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\n\n#Global Variables for The Game\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))<\/pre><\/div>\n\n\n\n<p>First, we stated the <strong>&#8216;FPS&#8217;<\/strong> which is nothing but the <strong>&#8216;Frame Per Second&#8217;<\/strong> we gave it a value of 32 which means we&#8217;ll play our games in 32 <strong>&#8216;Frame Per Second&#8217;<\/strong> in simple words 32 images will blit on the screen in just One Second.<\/p>\n\n\n\n<p>Then, we declare the <strong>&#8216;SCREENWIDTH&#8217;<\/strong> and <strong>&#8216;SCREENHEIGHT&#8217;<\/strong> and give it values of 289 and 511 which is <strong>&#8216;LENGTH &amp; BREADTH&#8217;<\/strong> of our game window. And after that by using the code <strong>&#8216;pygame.display.set_mode()&#8217;<\/strong> we made our game window.<\/p>\n\n\n\n<p>if you are having problem in understanding <strong>&#8216;pygame.display.set_mode()&#8217;<\/strong>. Then you can check out our other posts <strong>&#8216;<a href=\"https:\/\/copyassignment.com\/car-race-game-in-pygame-and-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">CAR RACE GAME IN PYGAME FROM SCRATCH<\/a>&#8216;. <\/strong>There we have discussed in detail the working of these codes.<\/p>\n\n\n\n<p>Now, we&#8217;ll do our next task which is declaring some variables and will make some dictionaries and will load our sprites as well.<\/p>\n\n\n\n<p>So look at the code below.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\n\n#GLOBAL VARIABLES \n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '<\/pre><\/div>\n\n\n\n<p>First of all, we have declared the variable <strong>&#8216;GROUNDY&#8217;<\/strong> which is for our <strong>&#8216;base image&#8217;<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/base.png?w=336\" alt=\"base image Flappy Bird In Pygame Python\" class=\"wp-image-264 lazyload\" width=\"616\" height=\"205\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 616px; --smush-placeholder-aspect-ratio: 616\/205;\" \/><figcaption class=\"wp-element-caption\">base image<\/figcaption><\/figure>\n\n\n\n<p>After then we created the dictionary <strong>&#8216;GAME_SPRITES&#8217;<\/strong> and <strong>&#8216;GAME_SOUNDS&#8217;<\/strong> after then we gave paths to our <strong>bird,<\/strong> <strong>background,<\/strong> <strong>pipes <\/strong>images.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">LOADING ALL THE SPRITES AND SOUNDS<\/h3>\n\n\n\n<p>Now, we will load all the <strong>SPRITES &amp; SOUNDS<\/strong> for our game. So, let&#8217;s look that what we have in our <strong>SPRITES &amp; SOUNDS<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image.png?w=1024\" alt=\"Flappy Bird In Pygame Python sprites\" class=\"wp-image-258 lazyload\" width=\"821\" height=\"216\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 821px; --smush-placeholder-aspect-ratio: 821\/216;\" \/><figcaption class=\"wp-element-caption\">SPRITES<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-1.png?w=869\" alt=\"Flappy Bird In Pygame Python sounds\" class=\"wp-image-260 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">SOUNDS<\/figcaption><\/figure>\n\n\n\n<p>So we have seen our all sprites we have numbers from 0 to 9 which we&#8217;ll use for <strong>blitting<\/strong> our Score. We have a base image which we can also say is the ground of our game, and we have a background image which is the <strong>background of our game<\/strong>.<\/p>\n\n\n\n<p>After then we have a <strong>bird image<\/strong> which is our player and then a game over which we&#8217;ll display after game over and then home and then a message which will be our Welcome Screen after then we have pipes<br>because it would be obstacles through which our bird has to be <strong>flapped<\/strong> and then <strong>retry<\/strong> which we will use to play the game again.<\/p>\n\n\n\n<p>So, now it&#8217;s time to load all the <strong>SPRITES &amp; SOUNDS<\/strong>. Let&#8217;s have a look at the code.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\n\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    S\n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')<\/pre><\/div>\n\n\n\n<p>I don&#8217;t think I need to explain anything in the above code because there is nothing to explain here however I have commented out in the code as well so you can understand it from there.<\/p>\n\n\n\n<p>After then we&#8217;ll create a while loop inside this we&#8217;ll call our <strong>welcomeScreen function and mainGame function<\/strong>. Don&#8217;t worry we&#8217;ll create them we haven&#8217;t created them yet. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        mainGame() #This is our main game funtion\n<\/code><\/pre>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\">CREATING A WELCOME SCREEN FOR FLAPPY BIRD IN PYTHON PYGAME<\/h2>\n\n\n\n<p>Now, we are going to create the welcome screen function that I said to you earlier. Now, we will blit the images. But before that let me tell you how images are displayed on our game window. Hope you are familiar with it already but if not let&#8217;s see.<\/p>\n\n\n\n<p>Every image we blit on our screen is with the help of their coordinates. Let&#8217;s see the image below of the pygame window that we have created with the dimensions of <strong>(289 X 511)<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">COORDINATES EXPLANATION<\/h3>\n\n\n\n<p>Every top left corner of the image or screen is the origin like you are seeing in the image below. <strong>X-axis and Y-axis<\/strong> can also be negative but negative values will be displayed outside our pygame Window.<\/p>\n\n\n\n<p>While <strong>Y-axis<\/strong> increases when we go <strong>downside<\/strong> and <strong>decreases<\/strong> when we go <strong>upside<\/strong>.<\/p>\n\n\n\n<p>So, whenever we operate with any images just keep it in mind that its <strong>top-left corner<\/strong> will be (0,0) means will be the origin and by the hit and trial method you can get your desired coordinates.<\/p>\n\n\n\n<p>The values which we are going to use in our game has been came through several attempts. So, don&#8217;t bother from where I got these values. There is nothing in it. You have to check your own which values satisfy you.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-3.png?w=752\" alt=\"axes of the game window in Flappy Bird game\" class=\"wp-image-268 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">axes of the game window<\/figcaption><\/figure>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-4.png?w=410\" alt=\"how do axes changes\" class=\"wp-image-270 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">HOW DO AXES CHANGES<\/figcaption><\/figure>\n\n\n\n<p>So now we know the Science behind blitting of images on the screen. So let&#8217;s start blitting means coding to blit our images on the screen. <br>But first, have a look at our welcome screen image which we named as a message.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/message.png?w=184\" alt=\"welcome screen of Flappy Bird In Pygame Python\" class=\"wp-image-276 lazyload\" width=\"294\" height=\"427\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 294px; --smush-placeholder-aspect-ratio: 294\/427;\" \/><figcaption class=\"wp-element-caption\">Welcome Screen image<\/figcaption><\/figure>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\ndef welcomeScreen():\n\n    #IT WIll Show Welcome Screen TO user to make the game more interactive and interesting\n    playerx = int(SCREENWIDTH\/5)\n    playery = int(SCREENHEIGHT - GAME_SPRITES['player'].get_height())\/2\n    messagex = int(SCREENWIDTH - GAME_SPRITES['message'].get_width())\/2\n    messagey = int(SCREENHEIGHT * 0.13)\n    basex = 0\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    S\n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')\n  while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        mainGame() #This is our main game funtion<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">CODE EXPLANATION<\/h3>\n\n\n\n<p>What we have created is we defined or created a function <strong>welcomeScreen()<\/strong> in which we declared a variable <strong>&#8216;playerx&#8217;<\/strong> which will be x coordinate of our player which is <strong>bird<\/strong>. <\/p>\n\n\n\n<p>The second is <strong>&#8216;playery&#8217;<\/strong>  which is a little bit technical. So, understand it with your full patience.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>playery = int(SCREENHEIGHT - GAME_SPRITES&#91;'player'].get_height())\/2<\/code><\/pre>\n\n\n\n<p>What we did is, we subtracted the <strong>height of the player<\/strong> from the <strong>screen height<\/strong> and then divide it by 2. <\/p>\n\n\n\n<p><strong>get_height()<\/strong> is a function used to get the height of the object as the name itself tells. In our case, the object is the player which is nothing but the image of the bird. <\/p>\n\n\n\n<p>We did it because we wanted to place our birds at the centre so it gives the sense of symmetry. <\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\">Let&#8217;s understand it through example.<br>Suppose the height of the screen is 30 <br>                  height of the player is 02<br>                                         playery = (30-02)\/2<\/p>\n\n\n\n<p>The same logic goes with the <strong>&#8216;messagex&#8217;<\/strong>  but in this case, it&#8217;s not height it&#8217;s the width of the image. From the <strong>width of the screen<\/strong>, we subtracted the <strong>width of the message<\/strong> which is an image. <br>And then we have <strong>&#8216;messagey&#8217;<\/strong> in which it stores the <strong>y-coordinate<\/strong> for the message.<\/p>\n\n\n\n<p>After then we have <strong>basex<\/strong> which is the <strong>x-coordinate<\/strong>  of our <strong>base image<\/strong> and its Y we have already declared in <strong>Global Variables<\/strong> named as <strong>GROUNDY<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/base-1.png?w=336\" alt=\"base image\" class=\"wp-image-278 lazyload\" width=\"606\" height=\"202\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 606px; --smush-placeholder-aspect-ratio: 606\/202;\" \/><figcaption class=\"wp-element-caption\">base image<\/figcaption><\/figure>\n\n\n\n<p>All the values we are using came from <strong>various attempts<\/strong>. So, it&#8217;s not the point to be worried that how these values are coming. It will just come up with you with the experience.<\/p>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\">OPERATING EVENTS AND TAKING INPUTS FROM THE USER<\/h2>\n\n\n\n<p>Till now, we did so much we loaded all the sprites and sounds, we created welcomeScreen function in which we have given <strong>playerx, playery, messagex, messagey and basex.<\/strong><\/p>\n\n\n\n<p>But there is nothing yet when you&#8217;ll run the code you will see that our window <strong>appears<\/strong> for a second and then will <strong>disappear.<\/strong> <br><br>So now we&#8217;ll create a <strong>while infinite loop <\/strong>so that our screen can&#8217;t disappear within a second but with our choice and we have to blit the images and play intro music as well.<\/p>\n\n\n\n<p>Before going further to code Flappy Bird In Python Pygame, let&#8217;s have a look at the code after then we will explain them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()<\/code><\/pre>\n\n\n\n<p>What we are doing is we are commanding that don&#8217;t close the game until we want to close it, after then we accessed all the events which are going on via <strong>for event in pygame.event.get():<\/strong><\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>Events are anything that you do with your computer either pressing a keyboard&#8217;s key or moving the mouse cursor all are said to be events<\/strong>.<\/p>\n\n\n\n<p>And from that Events, we checked whether users clicks on the <strong>Cross button<\/strong> or presses the <strong>Escape key<\/strong>. If yes then we will close the pygame window with the help of <strong>pygame.quit() and sys.exit()<\/strong>.<\/p>\n\n\n\n<p>Now, we will check for other Events, we want that if the user presses the <strong>Space bar or Up arrow <\/strong>key then we will start the game for them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ACCESSING EVENTS<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n    \n             ## If user presses the Space bar or up arrow key start the game for them\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n<\/code><\/pre>\n\n\n\n<p>So we made an infinite loop and inside this, we first accessed all the events that are happening within the game.<br><strong>Events are anything that you do with your computer either pressing a keyboard&#8217;s key or moving the mouse cursor all are said to be events<\/strong>.<\/p>\n\n\n\n<p>And from that Events, we checked whether users clicks on the <strong>Cross button<\/strong> or presses the <strong>Escape key<\/strong>. If yes then we will close the pygame window with the help of <strong>pygame.quit() and sys.exit()<\/strong>.<\/p>\n\n\n\n<p>Now, we will check for other Events, we want that if the user presses the <strong>Space bar or Up arrow <\/strong>key then we will start the game for them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n    \n             ## If user presses the Space bar or up arrow key start the game for them\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n<\/code><\/pre>\n\n\n\n<p>Even though we have coded so much but our screen is still black there is no image, no sound, nothing because we haven&#8217;t displayed them yet. <br>So, let&#8217;s first blit our images after then we&#8217;ll check some mouse events for <\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n\n            \n\n            else :\n                SCREEN.blit(GAME_SPRITES['background'],(0,0))\n                SCREEN.blit(GAME_SPRITES['player'],(playerx,playery))\n                SCREEN.blit(GAME_SPRITES['message'],(messagex,messagey))\n                SCREEN.blit(GAME_SPRITES['base'],(basex,GROUNDY))\n                pygame.display.update()\n                FPSCLOCK.tick(FPS)\n<\/pre><\/div>\n\n\n\n<p>Under <strong>else statement<\/strong>, we blitted our images and then updated them.<br><strong>Screen.blit()<\/strong> is a funtction which takes two arguments first is image we want to blit and second is <strong>coordinates<\/strong>. for ex-  <strong>SCREEN.blit(image, coordinates)<\/strong><\/p>\n\n\n\n<p>And then we typed <strong>&#8216;pygame.display.update()&#8217;<\/strong> which is very important it updates the window and then we have <strong>&#8216;FPSClock&#8217;<\/strong> which controls our <strong>FPS<\/strong>.<\/p>\n\n\n\n<p>Now, we have displayed our images and we don&#8217;t have black or dark screen to see. We have our beautiful welcome screen. Let&#8217;s have a look.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-5.png?w=431\" alt=\"welcome screen of Flappy Bird game\" class=\"wp-image-287 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">Welcome Screen<\/figcaption><\/figure>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\">ACCESSING MOUSE EVENTS<\/h3>\n\n\n\n<p>Now, we are glad to see some visuals on our game window now we would operate some <strong>Mouse events<\/strong>. We want two things first is when we click on the <strong>play button<\/strong> our game should be <strong>Start<\/strong> and Second when we hover to the play button then the cursor arrow should be changed into a <strong>hand gesture<\/strong>.<\/p>\n\n\n\n<p>First, we will change our mouse cursor when we hover on the play button.<br>But before that, we have to create a transparent <strong>rectangle<\/strong> which we will use as a <strong>play button<\/strong> because the icon is not any button <strong>it is within the image.<\/strong><br><br>So, let&#8217;s look at the highlighted lines of code.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\ndef welcomeScreen():\n\n    #IT WIll Show Welcome Screen TO user to make the game more interactive and interesting\n    playerx = int(SCREENWIDTH\/5)\n    playery = int(SCREENHEIGHT - GAME_SPRITES['player'].get_height())\/2\n    messagex = int(SCREENWIDTH - GAME_SPRITES['message'].get_width())\/2\n    messagey = int(SCREENHEIGHT * 0.13)\n    basex = 0\n    \n    # Drawing Rectangle for playbutton\n    playbutton = pygame.Rect(108,222,68,65)\n\n    while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n            \n            #This will make the cursor to arrow again if we move out our cursor from playbutton\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0] > playbutton[0]  and pygame.mouse.get_pos()[0] &lt; playbutton[0] + playbutton[2]:\n                if pygame.mouse.get_pos()[1] > playbutton[1]  and pygame.mouse.get_pos()[1] &lt; playbutton[1] + playbutton[3]:\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n\n            else :\n                SCREEN.blit(GAME_SPRITES['background'],(0,0))\n                SCREEN.blit(GAME_SPRITES['player'],(playerx,playery))\n                SCREEN.blit(GAME_SPRITES['message'],(messagex,messagey))\n                SCREEN.blit(GAME_SPRITES['base'],(basex,GROUNDY))\n                pygame.display.update()\n                FPSCLOCK.tick(FPS)\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    \n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')\n    while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        # mainGame() #This is our main game funtion<\/pre><\/div>\n\n\n\n<p>First, we created a rectangle in a variable call <strong>playbutton<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    # Drawing Rectangle for playbutton\n    playbutton = pygame.Rect(108,222,68,65)<\/code><\/pre>\n\n\n\n<p>pygame.Rect() takes 4 things as arguments <strong>x, y, length, breadth<\/strong> of the rectangle. Here <strong>x, y<\/strong> <strong>coordinates<\/strong> are (108,222) and the <strong>dimension of the rectangle are <\/strong>(68,65).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">HOVER EFFECT<\/h3>\n\n\n\n<p>Now, we will write code that if we hover over the play button arrow will change into a hand gesture.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> #This will make the cursor to arrow again if we move out our cursor from playbutton\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()&#91;0] &gt; playbutton&#91;0]  and pygame.mouse.get_pos()&#91;0] &lt; playbutton&#91;0] + playbutton&#91;2]:\n                if pygame.mouse.get_pos()&#91;1] &gt; playbutton&#91;1]  and pygame.mouse.get_pos()&#91;1] &lt; playbutton&#91;1] + playbutton&#91;3]:\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)<\/code><\/pre>\n\n\n\n<p><strong>pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)<\/strong> &#8211;&gt; This will set our cursor to the arrow again when we move out our mouse cursor from the play button.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pygame.mouse.get_pos()<\/code><\/pre>\n\n\n\n<p>This will give the <strong>coordinates\/position<\/strong> of our <strong>mouse cursor.<\/strong> It will return two values one will be our <strong>x-coordinate<\/strong> and the second will be our <strong>y-coordinate.<\/strong><\/p>\n\n\n\n<p>After then we checked if our mouse cursor&#8217;s <strong>x-coordinate<\/strong> is greater than our <strong>play button&#8217;s x-coordinate<\/strong> and smaller than the <strong>play button&#8217;s x-coordinate<\/strong> + <strong>width of the play button<\/strong>.<\/p>\n\n\n\n<p>After then we checked our mouse cursor&#8217;s <strong>y-coordinate<\/strong> is greater than our <strong>play button&#8217;s x-coordinate<\/strong> and smaller than the <strong>play button&#8217;s y-coordinate<\/strong> + <strong>height of the play button<\/strong>.<\/p>\n\n\n\n<p>If both conditions which are discussed above satisfies then change our mouse <strong>cursor&#8217;s arrow to hand gesture<\/strong>. See below.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"640\" style=\"aspect-ratio: 352 \/ 640;\" width=\"352\" controls src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/03\/HOVER-EFFECT.mp4\"><\/video><\/figure>\n\n\n\n<p>Now, we will write code that will check if the user clicks on the <strong>play button<\/strong> then start the game for them. Let&#8217;s have a look at the code for that.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if playbutton.collidepoint(pygame.mouse.get_pos()): #checking if mouse is collided with the play button\n            \n                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: #checking if mouse has been clicked\n                    mainGame()<\/code><\/pre>\n\n\n\n<p>By this, we have successfully created our <strong>welcomeScreen()<\/strong> function but if you run this code we will get an error because we haven&#8217;t created our <strong>mainGame() <\/strong>function. Now our code will look something like this&#8230;<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\ndef welcomeScreen():\n\n    #IT WIll Show Welcome Screen TO user to make the game more interactive and interesting\n    playerx = int(SCREENWIDTH\/5)\n    playery = int(SCREENHEIGHT - GAME_SPRITES['player'].get_height())\/2\n    messagex = int(SCREENWIDTH - GAME_SPRITES['message'].get_width())\/2\n    messagey = int(SCREENHEIGHT * 0.13)\n    basex = 0\n    \n    # Drawing Rectangle for playbutton\n    playbutton = pygame.Rect(108,222,68,65)\n\n    while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0] > playbutton[0]  and pygame.mouse.get_pos()[0] &lt; playbutton[0] + playbutton[2]:\n                if pygame.mouse.get_pos()[1] > playbutton[1]  and pygame.mouse.get_pos()[1] &lt; playbutton[1] + playbutton[3]:\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n\n            if playbutton.collidepoint(pygame.mouse.get_pos()): #checking if mouse is collided with the play button\n            \n                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: #checking if mouse has been clicked\n                    mainGame()\n\n            else :\n                SCREEN.blit(GAME_SPRITES['background'],(0,0))\n                SCREEN.blit(GAME_SPRITES['player'],(playerx,playery))\n                SCREEN.blit(GAME_SPRITES['message'],(messagex,messagey))\n                SCREEN.blit(GAME_SPRITES['base'],(basex,GROUNDY))\n                pygame.display.update()\n                FPSCLOCK.tick(FPS)\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    \n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')\n    while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        mainGame() #This is our main game funtion<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">CREATING OUR MAIN GAME FUNCTION<\/h3>\n\n\n\n<p>So far we have done a lot of things we have successfully created our welcome screen. But now we are going to create our <strong>main game function<\/strong> so that now we can also play the Flappy Bird In Pygame Python.<\/p>\n\n\n\n<p>But before starting let me give you a summarized idea of what we are going to do in this particular functions. We&#8217;ll work on a bunch of things because it&#8217;s the <strong>main function<\/strong> by which we would be able to <strong>play the game<\/strong> because we can play the game even without a welcome screen but it adds beauty to the game and gives a sense of professionalism.<\/p>\n\n\n\n<p>So let&#8217;s make a table of what we are going to do in this <strong>maingame()<\/strong> function.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We would blit all the sprites<\/li>\n\n\n\n<li>After then we&#8217;ll make our player which is bird movable and will give a realistic feel.<\/li>\n\n\n\n<li>Then our next task is to generate random pipes which would be our obstacles for the game<\/li>\n\n\n\n<li>After doing that we would make the pipes movable.<\/li>\n\n\n\n<li>We would make functions for collisions<\/li>\n\n\n\n<li>After collisions we will make the game over and will give them the option whether they want to play again or return to the home screen. It would be in our gameover functions not in this we will just call it after the collision.<\/li>\n\n\n\n<li>We would have some sound effects and some background music.<\/li>\n<\/ul>\n\n\n\n<p>Now we are going to create our main game so let&#8217;s start.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def mainGame():\n    score = 0\n    playerx = int(SCREENWIDTH\/5)\n    playery = int (SCREENHEIGHT\/2)\n    basex = 0<\/code><\/pre>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\" id=\"generating-random-pipes\">GENERATING RANDOM PIPES FOR FLAPPY BIRD IN PYTHON PYGAME<\/h2>\n\n\n\n<p>Now, we will create a <strong>getRandomPipe()<\/strong> function which we will use to generate random pipes as the name itself suggests. <br>We would have two pipes one is upper pipe and the second is lower pipe.<\/p>\n\n\n\n<p>Let&#8217;s first discuss how we&#8217;ll blit our pipes. We&#8217;ll blit our upper pipes and lowerpipes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-6-edited.png\" alt=\"HOW OUR PIPES WILL LOOK\" class=\"wp-image-305 lazyload\" width=\"448\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">HOW OUR PIPES WILL LOOK<\/figcaption><\/figure>\n\n\n\n<p>So we can see there is gap between our pipes to pass our bird. We would have to declare the offset value for it.<br>And we will blit our pipes in randomly it will increase the difficulty level and it will give us the realistic feel of the game.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CREATING FUNCTION FOR GENERATING RANDOM PIPES<\/h3>\n\n\n\n<p>In the <strong>getRandomPipe()<\/strong> we would have a list that would have dictionaries that will contain <strong>x and y<\/strong> values for our pipes. X of both pipes will same and we will give the value of <strong>x<\/strong> as <strong>screen width + 10<\/strong> after then we will move the pipe. <br>Let&#8217;s see in coding language because that&#8217;s what we understand better.<br><strong>y1 is for upper pipes and y2 is for lower pipes<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-foreground-dark-color has-text-color\"><code>pipe = &#91; {'x': x value for pipe, 'y': y1}, #values for upper pipe\n         {'x': x value for pipe, 'y': y2}  #values for lower pipe\n  ]<\/code><\/pre>\n\n\n\n<p>First, we will obtain <strong>y<\/strong> for the lower pipe which is <strong>y2<\/strong>.<br>We will need such random values that our pipe shouldn&#8217;t overlap the whole screen and should be some gap that is <strong>offset<\/strong> between upper and lower pipes.<\/p>\n\n\n\n<p>This part is a little bit tricky and has some mathematical operations. I&#8217;m explaining it but if your focus is on making the game then you can ignore this.<br><br>So, we will generate some random value by adding the <strong>offset<\/strong> and then<br>We will <strong>subtract the base height from the screenheight(SH)<\/strong> and then will <strong>subtract 1.5*offset<\/strong>. It is the value that came from so many experiments. So as I said earlier you will get the value just by the trial and error method.<\/p>\n\n\n\n<p>Look at the picture below to relate with all this what I am saying. The extra red outline you are seeing is that it&#8217;s out from our Screen but it exists so we have to generate the value considering the top-left point of the pipe.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-7.png?w=502\" alt=\"lower pipes explanation\" class=\"wp-image-306 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">Lower pipes Explanation<\/figcaption><\/figure>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p> So don&#8217;t think about this and let&#8217;s come to code that how we will write all this in code and will generate the <strong>y for our lower pipe<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES&#91;'base'].get_height() - 1.2 *offset))<\/code><\/pre>\n\n\n\n<p><strong>random.randrange()<\/strong> is a function that generates random values between ranges.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"generating-y-coordinate-for-upper-pipes\">Generating y-coordinate for upper pipes<\/h3>\n\n\n\n<p>We saw how we generated <strong>y-coordinate<\/strong> for our lower pipe. Now we&#8217;ll see how we can generate <strong>y-coordinate<\/strong> for upper pipes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>y1 = pipeHeight - y2 + offset<\/code><\/pre>\n\n\n\n<p>What we did is we subtracted the <strong>y2<\/strong> which we obtained previously from the pipe height and then added offset in them and we got the appropriate <strong>y-coordinate<\/strong> for our <strong>upper pipes.<\/strong> What we did is we subtracted the <strong>y2<\/strong> which we obtained previously from the pipe height and then added offset in them and we got the appropriate <strong>y-coordinate<\/strong> for our <strong>upper pipes.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/02\/image-8.png?w=401\" alt=\"upper pipes explanation\" class=\"wp-image-309 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">upper pipe explanation<\/figcaption><\/figure>\n\n\n\n<p>Now, we will combine all this in the <strong>getRandomPipe()<\/strong> function. Notice our upper pipe is above the Screen so the value of the <strong>Y<\/strong> will be negative. Now let&#8217;s see the code.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">def getRandomPipe():\n    \"\"\"\n    generating positions of the two pipes one upper pipe and other lower pipe \n    To blit on the Screen\n    \"\"\"\n                \n    pipeHeight = GAME_SPRITES['pipe'][0].get_height()\n    offset = SCREENHEIGHT\/4.5\n    y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES['base'].get_height() - 1.2 *offset))\n    pipeX = SCREENWIDTH + 10\n    y1 = pipeHeight - y2 + offset\n    pipe = [ \n        {'x': pipeX, 'y': -y1}, #Upper Pipes\n        {'x': pipeX, 'y': y2}   #Lower Pipes\n    ]\n    return pipe <\/pre><\/div>\n\n\n\n<p>We have created our <strong>getRandomPipe()<\/strong> function now it&#8217;s time to use that. So let&#8217;s see the code for that.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating upper and Lower Pipes for the game<\/h3>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">#Creating upper and Lower Pipes for the game\n    newPipe1 = getRandomPipe()\n    newPipe2 = getRandomPipe()\n\n    # Upper pipe List\n    upperPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[0]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[0]['y']}\n    ]\n\n    #lists of Lower Pipe\n    lowerPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[1]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[1]['y']}\n    ]<\/pre><\/div>\n\n\n\n<p>1st and 2nd lines of code say that we created two variables <strong>newPipe1 and newPipe2<\/strong> and gave them the random value which we obtained from the <strong>getRandomPipe()<\/strong> function.<\/p>\n\n\n\n<p>And then we made two lists <strong>upperPipes and lowerPipes<\/strong>.<br>In the <strong>upperPipes<\/strong> list, we gave two values of <strong>x and y<\/strong>. The first value of <strong>x and y<\/strong> is the pipe that is blitted on the screen and the second value is for another upper pipe that is blitted at some distance from the first.<\/p>\n\n\n\n<p>Same logic applied with the <strong>lowerPipes<\/strong> list. We gave them some gap because when our pipe will be moving which we&#8217;ll see after some time then the player should have enough space to pass the pipes.<\/p>\n\n\n\n<p>So now it&#8217;s time to blit our sprites, we can also do it later but for your curious mind. Let&#8217;s blit what we have done yet.<\/p>\n\n\n\n<p>while True:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    for event in pygame.event.get():\n\n        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n            pygame.quit()\n            sys.exit()\n\n    # Lets blit our sprites now\n    SCREEN.blit(GAME_SPRITES&#91;'background'], (0, 0))\n    for upperPipe, lowerPipe in zip(upperPipes, lowerPipes):\n        SCREEN.blit(GAME_SPRITES&#91;'pipe']&#91;0], (upperPipe&#91;'x'], upperPipe&#91;'y']))\n        SCREEN.blit(GAME_SPRITES&#91;'pipe']&#91;1], (lowerPipe&#91;'x'], lowerPipe&#91;'y']))\n\n    SCREEN.blit(GAME_SPRITES&#91;'base'], (basex, GROUNDY))\n    SCREEN.blit(GAME_SPRITES&#91;'player'], (playerx, playery))\n    pygame.display.update()\n    FPSCLOCK.tick(FPS)<\/code><\/pre>\n\n\n\n<p>We have discussed the blit function already so there is nothing to explain in it but the one thing you will see is the <strong>zip<\/strong>. So let me explain what it does. No, let me show you then you would understand it better.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ZIP EXPLANATION<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/theconquerorsofworld.files.wordpress.com\/2022\/03\/image.png?w=1024\" alt=\"zip in python\" class=\"wp-image-314 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" \/><figcaption class=\"wp-element-caption\">zip example<\/figcaption><\/figure>\n\n\n\n<p>Now you can see what the zip does. It basically mixes the values of the two lists and there is nothing to explain in the above code. So, now we should move further<\/p>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\" id=\"making-the-game-dynamic-from-static\">MAKING THE GAME DYNAMIC FROM STATIC<\/h2>\n\n\n\n<p>Now, our task is to make the pipes movable we&#8217;ll move the pipes from right to left and it will give the illusion that the bird is moving. After then we also have to make our Flappy Bird flap. After then we&#8217;ll check for score and will show it on the screen we&#8217;ll check for collisions and after the collision, we&#8217;ll call our gameover function, and then we boom. Our Flappy Bird In Python Pygame will be completed.<\/p>\n\n\n\n<p>So without any further delay let&#8217;s make our game <strong>static to dynamic<\/strong>. Look at the code that we are going to code in this particular section.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\ndef welcomeScreen():\n\n    #IT WIll Show Welcome Screen TO user to make the game more interactive and interesting\n    playerx = int(SCREENWIDTH\/5)\n    playery = int(SCREENHEIGHT - GAME_SPRITES['player'].get_height())\/2\n    messagex = int(SCREENWIDTH - GAME_SPRITES['message'].get_width())\/2\n    messagey = int(SCREENHEIGHT * 0.13)\n    basex = 0\n    \n    # Drawing Rectangle for playbutton\n    playbutton = pygame.Rect(108,222,68,65)\n\n    while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0] > playbutton[0]  and pygame.mouse.get_pos()[0] &lt; playbutton[0] + playbutton[2]:\n                if pygame.mouse.get_pos()[1] > playbutton[1]  and pygame.mouse.get_pos()[1] &lt; playbutton[1] + playbutton[3]:\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n\n            if playbutton.collidepoint(pygame.mouse.get_pos()): #checking if mouse is collided with the play button\n            \n                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: #checking if mouse has been clicked\n                    mainGame()\n\n            else :\n                SCREEN.blit(GAME_SPRITES['background'],(0,0))\n                SCREEN.blit(GAME_SPRITES['player'],(playerx,playery))\n                SCREEN.blit(GAME_SPRITES['message'],(messagex,messagey))\n                SCREEN.blit(GAME_SPRITES['base'],(basex,GROUNDY))\n                pygame.display.update()\n                FPSCLOCK.tick(FPS)\n\ndef mainGame():\n    \n    score = 0\n    playerx = int(SCREENWIDTH\/5)\n    playery = int (SCREENHEIGHT\/2)\n    basex = 0\n\n    #Creating upper and Lower Pipes for the game\n    newPipe1 = getRandomPipe()\n    newPipe2 = getRandomPipe()\n\n    # Upper pipe List\n    upperPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[0]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[0]['y']}\n    ]\n\n    #lists of Lower Pipe\n    lowerPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[1]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[1]['y']}\n    ]\n\n    pipeVelX = -4\n    playerVelY = -9\n    playerMaxVelY = 10  \n    playerMinVelY = -8\n    playerAccY = 1\n\n    playerFlapAccv = -8 # velocity while flapping\n    playerFlapped = False # It is true only when the bird is flapping\n\n    while True:\n\n        for event in pygame.event.get():\n           \n            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                if playery > 0:\n                    playerVelY = playerFlapAccv\n                    playerFlapped = True\n                    GAME_SOUNDS['wing'].play()\n\n        if playerVelY &lt;playerMaxVelY and not playerFlapped:\n            playerVelY += playerAccY\n\n        if playerFlapped:\n            playerFlapped = False            \n        playerHeight = GAME_SPRITES['player'].get_height()\n        playery = playery + min(playerVelY, GROUNDY - playery - playerHeight)\n\n        # move pipes to the left\n        for upperPipe , lowerPipe in zip(upperPipes, lowerPipes):\n            upperPipe['x'] += pipeVelX\n            lowerPipe['x'] += pipeVelX\n\n        # Add a new pipe when the first is about to cross the leftmost part of the screen\n        if 0&lt;upperPipes[0]['x']&lt;5:\n            newpipe = getRandomPipe()\n            upperPipes.append(newpipe[0])\n            lowerPipes.append(newpipe[1])\n\n        # if the pipe is out of the screen, remove it\n        if upperPipes[0]['x'] &lt; -GAME_SPRITES['pipe'][0].get_width():\n            upperPipes.pop(0)\n            lowerPipes.pop(0)\n\n        # Lets blit our sprites now\n        SCREEN.blit(GAME_SPRITES['background'], (0, 0))\n        for upperPipe, lowerPipe in zip(upperPipes, lowerPipes):\n            SCREEN.blit(GAME_SPRITES['pipe'][0], (upperPipe['x'], upperPipe['y']))\n            SCREEN.blit(GAME_SPRITES['pipe'][1], (lowerPipe['x'], lowerPipe['y']))\n\n        SCREEN.blit(GAME_SPRITES['base'], (basex, GROUNDY))\n        SCREEN.blit(GAME_SPRITES['player'], (playerx, playery))\n        pygame.display.update()\n        FPSCLOCK.tick(FPS)\n\ndef getRandomPipe():\n    \"\"\"\n    generating positions of the two pipes one upper pipe and other lower pipe \n    To blit on the Screen\n    \"\"\"\n                \n    pipeHeight = GAME_SPRITES['pipe'][0].get_height()\n    offset = SCREENHEIGHT\/4.5\n    y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES['base'].get_height() - 1.2 *offset))\n    pipeX = SCREENWIDTH + 10\n    y1 = pipeHeight - y2 + offset\n    pipe = [ \n        {'x': pipeX, 'y': -y1}, #Upper Pipes\n        {'x': pipeX, 'y': y2}   #Lower Pipes\n    ]\n    return pipe \n\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    \n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')\n    while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        mainGame() #This is our main game funtion<\/pre><\/div>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<p>Now we will understand it by part wise<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    pipeVelX = -4\n    playerVelY = -9\n    playerMaxVelY = 10 \n    playerMinVelY = -8\n    playerAccY = 1\n \n    playerFlapAccv = -8 # velocity while flapping\n    playerFlapped = False # It is true only when the bird is flapping<\/code><\/pre>\n\n\n\n<p>First, we declare the value of the pipe velocity which is -4 because we want to move our pipe from right to left not left to right. Then we set the <strong>player&#8217;s y <\/strong>velocity to -9 and the <strong>maximum and minimum<\/strong> velocity of the player&#8217;s y is <strong>10 and -8<\/strong> respectively.<br>And then we declared a Boolean variable of <strong>playerFlapped<\/strong> which will be True when the bird is flapping.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>            if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                if playery &gt; 0:\n                    playerVelY = playerFlapAccv\n                    playerFlapped = True\n                    GAME_SOUNDS&#91;'wing'].play()\n <\/code><\/pre>\n\n\n\n<p>This will check if the user has pressed the SPACE bar key or UP ARROW key and if playerY is greater than the 0 then update the player&#8217;s y velocity with player&#8217;s velocity while flapping. <\/p>\n\n\n\n<p>After then changed the boolean value to true from false that the player is flapped and played the sound effect.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">IF PLAYER HAS TOUCHED THE GROUND<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>if playerFlapped:\n            playerFlapped = False           \n        playerHeight = GAME_SPRITES&#91;'player'].get_height()\n        playery = playery + min(playerVelY, GROUNDY - playery - playerHeight)<\/code><\/pre>\n\n\n\n<p>This will make sure that if the bird has touched the ground then don&#8217;t go further than that and set the value of the playerY to playerY because <strong>(GROUNDY &#8211; playery &#8211; playerHeight)<\/strong> this value will become zero if the bird will touch the ground and minimum of any no with zero will be zero. That&#8217;s the logic behind this.<br>If you are not understanding it you can check the value graphically by the rough diagram on your notebook and the bird should be in touch with the base or the ground.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># move pipes to the left\n        for upperPipe , lowerPipe in zip(upperPipes, lowerPipes):\n            upperPipe&#91;'x'] += pipeVelX\n            lowerPipe&#91;'x'] += pipeVelX\n \n        # Add a new pipe when the first is about to cross the leftmost part of the screen\n        if 0&lt;upperPipes&#91;0]&#91;'x']&lt;5:\n            newpipe = getRandomPipe()\n            upperPipes.append(newpipe&#91;0])\n            lowerPipes.append(newpipe&#91;1])\n \n        # if the pipe is out of the screen, remove it\n        if upperPipes&#91;0]&#91;'x'] &lt; -GAME_SPRITES&#91;'pipe']&#91;0].get_width():\n            upperPipes.pop(0)\n            lowerPipes.pop(0)<\/code><\/pre>\n\n\n\n<p>This will move our pipe from the right to left and when the pipe is going to cross the leftmost part of the screen then we created another pipe and it will be in an infinite loop.<\/p>\n\n\n\n<p>The last line will remove the pipe if it&#8217;s out of the screen. Hope you understand. Now, look at the output of the code.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"352\" style=\"aspect-ratio: 640 \/ 352;\" width=\"640\" controls muted src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/03\/MOVING-PIPES.mp4\"><\/video><\/figure>\n\n\n\n<p>Now our work is to display the score and after that, we will detect the collision and make the game over. So we&#8217;ll look after it. After the collision, we will call our game over the function which we&#8217;ll create. And then we&#8217;ll add some background music in the game and the welcome screen as well.<\/p>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\">SHOWING SCORE FOR OUR FLAPPY BIRD GAME<\/h2>\n\n\n\n<p>Now, we are going to update our score and will show it in our game window. But first, we&#8217;ll set criteria for updating the score. Then we&#8217;ll update the score. Let&#8217;s check the code for that.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#check for score\n        playerMidPos = playerx + GAME_SPRITES&#91;'player'].get_width()\/2\n        for pipe in upperPipes:\n            pipeMidPos = pipe&#91;'x'] + GAME_SPRITES&#91;'pipe']&#91;0].get_width()\/2\n            if pipeMidPos&lt;= playerMidPos &lt; pipeMidPos +4:\n                score +=1\n                print(f\"Your score is {score}\") \n                GAME_SOUNDS&#91;'point'].play()<\/code><\/pre>\n\n\n\n<p>First, we obtain the <strong>mid-position of the player<\/strong> <strong>and pipe<\/strong> and check if the <strong>mid-position of the player <\/strong>crosses the <strong>mid-position of the pipe<\/strong> then increase the <strong>score by 1<\/strong>. After then we printed our score and played the <strong>sound effect of point<\/strong>.<\/p>\n\n\n\n<p>We have successfully updated our score but we want to show it on our Screen. So now we will see how we can do that.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>myDigits = &#91;int(x) for x in list(str(score))]\n        width = 0\n        for digit in myDigits:\n            width += GAME_SPRITES&#91;'numbers']&#91;digit].get_width()\n        Xoffset = (SCREENWIDTH - width)\/2\n\n        for digit in myDigits:\n            SCREEN.blit(GAME_SPRITES&#91;'numbers']&#91;digit], (Xoffset, SCREENHEIGHT*0.12))\n            Xoffset += GAME_SPRITES&#91;'numbers']&#91;digit].get_width()<\/code><\/pre>\n\n\n\n<p>Let me explain this one by one first line of code create a list of the score and then we typecast them into Integers. <strong>myDigits<\/strong> stores a list of our scores.<br>Then we set the width to zero.<\/p>\n\n\n\n<p>Second, we created a for loop for our digits and then increased the width with our images&#8217; width for numbers. And then we declare the offset which is our <strong>x-coordinate<\/strong> where we would blit our score.<\/p>\n\n\n\n<p>And then we blitted our Score and after then increased the offset by the images&#8217; width because we have images from 0 to 9 if we would not increase the offset then for 10, 0 will overlap 1 and we don&#8217; want it to happen that&#8217;s why we increased the offset.<\/p>\n\n\n\n<p>So, now look at the code below and their output and notice how our score is changing.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\">The Code<\/h3>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\ndef welcomeScreen():\n\n    #IT WIll Show Welcome Screen TO user to make the game more interactive and interesting\n    playerx = int(SCREENWIDTH\/5)\n    playery = int(SCREENHEIGHT - GAME_SPRITES['player'].get_height())\/2\n    messagex = int(SCREENWIDTH - GAME_SPRITES['message'].get_width())\/2\n    messagey = int(SCREENHEIGHT * 0.13)\n    basex = 0\n    \n    # Drawing Rectangle for playbutton\n    playbutton = pygame.Rect(108,222,68,65)\n\n    while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0] > playbutton[0]  and pygame.mouse.get_pos()[0] &lt; playbutton[0] + playbutton[2]:\n                if pygame.mouse.get_pos()[1] > playbutton[1]  and pygame.mouse.get_pos()[1] &lt; playbutton[1] + playbutton[3]:\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n\n            if playbutton.collidepoint(pygame.mouse.get_pos()): #checking if mouse is collided with the play button\n            \n                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: #checking if mouse has been clicked\n                    mainGame()\n\n            else :\n                SCREEN.blit(GAME_SPRITES['background'],(0,0))\n                SCREEN.blit(GAME_SPRITES['player'],(playerx,playery))\n                SCREEN.blit(GAME_SPRITES['message'],(messagex,messagey))\n                SCREEN.blit(GAME_SPRITES['base'],(basex,GROUNDY))\n                pygame.display.update()\n                FPSCLOCK.tick(FPS)\n\ndef mainGame():\n    \n    score = 0\n    playerx = int(SCREENWIDTH\/5)\n    playery = int (SCREENHEIGHT\/2)\n    basex = 0\n\n    #Creating upper and Lower Pipes for the game\n    newPipe1 = getRandomPipe()\n    newPipe2 = getRandomPipe()\n\n    # Upper pipe List\n    upperPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[0]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[0]['y']}\n    ]\n\n    #lists of Lower Pipe\n    lowerPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[1]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[1]['y']}\n    ]\n\n    pipeVelX = -4\n    playerVelY = -9\n    playerMaxVelY = 10  \n    playerMinVelY = -8\n    playerAccY = 1\n\n    playerFlapAccv = -8 # velocity while flapping\n    playerFlapped = False # It is true only when the bird is flapping\n\n    while True:\n\n        for event in pygame.event.get():\n           \n            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                if playery > 0:\n                    playerVelY = playerFlapAccv\n                    playerFlapped = True\n                    GAME_SOUNDS['wing'].play()\n\n        #check for score\n        playerMidPos = playerx + GAME_SPRITES['player'].get_width()\/2\n        for pipe in upperPipes:\n            pipeMidPos = pipe['x'] + GAME_SPRITES['pipe'][0].get_width()\/2\n            if pipeMidPos&lt;= playerMidPos &lt; pipeMidPos +4:\n                score +=1\n                print(f\"Your score is {score}\") \n                GAME_SOUNDS['point'].play()\n\n        if playerVelY &lt;playerMaxVelY and not playerFlapped:\n            playerVelY += playerAccY\n\n        if playerFlapped:\n            playerFlapped = False            \n        playerHeight = GAME_SPRITES['player'].get_height()\n        playery = playery + min(playerVelY, GROUNDY - playery - playerHeight)\n\n        # move pipes to the left\n        for upperPipe , lowerPipe in zip(upperPipes, lowerPipes):\n            upperPipe['x'] += pipeVelX\n            lowerPipe['x'] += pipeVelX\n\n        # Add a new pipe when the first is about to cross the leftmost part of the screen\n        if 0&lt;upperPipes[0]['x']&lt;5:\n            newpipe = getRandomPipe()\n            upperPipes.append(newpipe[0])\n            lowerPipes.append(newpipe[1])\n\n        # if the pipe is out of the screen, remove it\n        if upperPipes[0]['x'] &lt; -GAME_SPRITES['pipe'][0].get_width():\n            upperPipes.pop(0)\n            lowerPipes.pop(0)\n\n        # Lets blit our sprites now\n        SCREEN.blit(GAME_SPRITES['background'], (0, 0))\n        for upperPipe, lowerPipe in zip(upperPipes, lowerPipes):\n            SCREEN.blit(GAME_SPRITES['pipe'][0], (upperPipe['x'], upperPipe['y']))\n            SCREEN.blit(GAME_SPRITES['pipe'][1], (lowerPipe['x'], lowerPipe['y']))\n\n        SCREEN.blit(GAME_SPRITES['base'], (basex, GROUNDY))\n        SCREEN.blit(GAME_SPRITES['player'], (playerx, playery))\n        myDigits = [int(x) for x in list(str(score))]\n        width = 0\n        for digit in myDigits:\n            width += GAME_SPRITES['numbers'][digit].get_width()\n        Xoffset = (SCREENWIDTH - width)\/2\n\n        for digit in myDigits:\n            SCREEN.blit(GAME_SPRITES['numbers'][digit], (Xoffset, SCREENHEIGHT*0.12))\n            Xoffset += GAME_SPRITES['numbers'][digit].get_width()\n        pygame.display.update()\n        FPSCLOCK.tick(FPS)\n\ndef getRandomPipe():\n    \"\"\"\n    generating positions of the two pipes one upper pipe and other lower pipe \n    To blit on the Screen\n    \"\"\"\n                \n    pipeHeight = GAME_SPRITES['pipe'][0].get_height()\n    offset = SCREENHEIGHT\/4.5\n    y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES['base'].get_height() - 1.2 *offset))\n    pipeX = SCREENWIDTH + 10\n    y1 = pipeHeight - y2 + offset\n    pipe = [ \n        {'x': pipeX, 'y': -y1}, #Upper Pipes\n        {'x': pipeX, 'y': y2}   #Lower Pipes\n    ]\n    return pipe \n\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    \n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')\n    while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        mainGame() #This is our main game funtion<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"732\" style=\"aspect-ratio: 414 \/ 732;\" width=\"414\" controls src=\"https:\/\/copyassignment.com\/wp-content\/uploads\/2022\/03\/Showing-Score-of-The-Game.mp4\"><\/video><\/figure>\n\n\n\n<p>So you can see that as our bird crosses the pipe&#8217;s mid-position our score got updated. But you can see even after colliding with the pipe there is nothing happens because we haven&#8217;t coded anything for collision.<\/p>\n\n\n\n<p>So now we will create the collision functions and after that, we&#8217;ll show the users gameover in Flappy Bird In Python Pygame.<\/p>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\" id=\"detecting-collisions\">DETECTING COLLISIONS<\/h2>\n\n\n\n<p>So now we will check if the player has collided or not. There will be 4 types of collision.<br>First, if our bird has moved out of the screen. Second, if the bird hits the ground. The third and fourth will be the collision between pipes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crashTest = isCollide(playerx, playery, upperPipes, lowerPipes) # This function will return true if the player is crashed\n        if crashTest:\n            return     \n<\/code><\/pre>\n\n\n\n<p>This function will return true if the player is crashed and then will return to the collide function and will check which collision is happened and then will follow the further statement.<\/p>\n\n\n\n<p>So now we are going to create our function first we will check collision with the ground and upmost screen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def isCollide(playerx, playery, upperPipes, lowerPipes):\n    if playery&gt; GROUNDY - 25  or playery&lt;0:\n        GAME_SOUNDS&#91;'hit'].play()\n        \n        gameOver()\n<\/code><\/pre>\n\n\n\n<p>It will check if the player&#8217;s <strong>Y-coordinate<\/strong> has become greater than <strong>GROUNDY &#8211; 25<\/strong> or if the player&#8217;s <strong>Y-coordinate<\/strong> is smaller than 0 then it will play the <strong>hit sound effect<\/strong> and our game will over and after then we call our gameOver function which we&#8217;ll create after some time, so don&#8217;t be confused.<\/p>\n\n\n\n<p>Now, we will see the collision between the pipes. So, let&#8217;s see the code for them.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">def isCollide(playerx, playery, upperPipes, lowerPipes):\n    if playery> GROUNDY - 25  or playery&lt;0:\n        GAME_SOUNDS['hit'].play()\n        \n        gameOver()\n        \n        \n    #UPPER PIPE COLLISION\n    for pipe in upperPipes:\n        pipeHeight = GAME_SPRITES['pipe'][0].get_height()\n        if(playery &lt; pipeHeight + pipe['y'] and abs(playerx - pipe['x']) &lt; GAME_SPRITES['pipe'][0].get_width()-20):\n            GAME_SOUNDS['hit'].play()\n            print(playerx, pipe['x'],)\n            \n            gameOver()\n            \n    #LOWER PIPE COLLISION\n    for pipe in lowerPipes:\n        if (playery + GAME_SPRITES['player'].get_height() > pipe['y']) and abs(playerx - pipe['x']) &lt; GAME_SPRITES['pipe'][0].get_width()-20:\n            GAME_SOUNDS['hit'].play()\n            \n            gameOver()\n            \n\n    return False<\/pre><\/div>\n\n\n\n<p> <\/p>\n\n\n\n<p>What we did is first we obtained the <strong>pipe height<\/strong> and then checked if <strong>playery <\/strong>is smaller than the <strong>sum of pipe height and pipe&#8217;s y<\/strong> and after then we checked if the <strong>absolute value<\/strong> of the <strong>difference of player x and pipe x<\/strong> is smaller than the <strong>upper pipe&#8217;s width &#8211; 20<\/strong>.<br><br>If yes, then we played the <strong>&#8216;hit sound effect&#8217;<\/strong> and called our <strong>gameOver <\/strong>function. The same goes with the <strong>lower pipe collision<\/strong>.<\/p>\n\n\n\n<p>So, we have successfully created the <strong>collision function<\/strong> for our game. Now, we&#8217;ll create the <strong>game over<\/strong> function that we have called after every collision.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-game-over-function\">CREATING GAME OVER FUNCTION<\/h2>\n\n\n\n<p>Now, we&#8217;ll create our <strong>game over <\/strong>function in this game over function, we would have some images and then we&#8217;ll give the player a choice to either <strong>retry or go home<\/strong>. So, let&#8217;s have a look at the whole code of this function.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">def gameOver():\n    SCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\n    pygame.display.set_caption('Flappy Bird With Sameer')\n    GAME_SPRITES['OVER'] = pygame.image.load('resources\/SPRITES\/gameover.png').convert_alpha()\n    GAME_SPRITES['RETRY'] = pygame.image.load('resources\/SPRITES\/retry.png').convert_alpha()\n    GAME_SPRITES['HOME'] = pygame.image.load('resources\/SPRITES\/Home.png').convert_alpha()\n    SCREEN.blit(GAME_SPRITES['background'],(0,0))\n    SCREEN.blit(GAME_SPRITES['base'],(0,GROUNDY))\n    SCREEN.blit(GAME_SPRITES['OVER'], (0,0))\n    SCREEN.blit(GAME_SPRITES['RETRY'], (30, 220))\n    SCREEN.blit(GAME_SPRITES['HOME'], (30, 280))\n    \n    pygame.display.update()\n\n    \n    while True: \n        for event in pygame.event.get():\n\n            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n \n            if event.type == KEYDOWN and event.key == K_SPACE:\n                mainGame()\n\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['RETRY'].get_width():\n                if pygame.mouse.get_pos()[1]>220 and pygame.mouse.get_pos()[1]&lt; 220+GAME_SPRITES['RETRY'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        \n                        mainGame()\n                      \n\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['HOME'].get_width():\n                if pygame.mouse.get_pos()[1]>280 and pygame.mouse.get_pos()[1]&lt; 280+GAME_SPRITES['HOME'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        welcomeScreen()<\/pre><\/div>\n\n\n\n<p>We first made the screen and then <strong>loaded our retry and home icons<\/strong> then we blitted all our necessary images for our <strong>game over<\/strong>.<\/p>\n\n\n\n<p>After then we made the <strong>while infinite loop <\/strong>and then gave the user to close the game and if the user presses the space bar then restart the game by calling the main game function.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"adding-buttons\">Adding Buttons<\/h3>\n\n\n\n<p>After then, here comes the logical part which is our <strong>restart button and home button<\/strong>. So, look at the code.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['RETRY'].get_width():\n                if pygame.mouse.get_pos()[1]>220 and pygame.mouse.get_pos()[1]&lt; 220+GAME_SPRITES['RETRY'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        \n                        mainGame()\n                      \n\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['HOME'].get_width():\n                if pygame.mouse.get_pos()[1]>280 and pygame.mouse.get_pos()[1]&lt; 280+GAME_SPRITES['HOME'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        welcomeScreen()\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['HOME'].get_width():\n                if pygame.mouse.get_pos()[1]>280 and pygame.mouse.get_pos()[1]&lt; 280+GAME_SPRITES['HOME'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        welcomeScreen()<\/pre><\/div>\n\n\n\n<p>First, we set the mouse cursor to an arrow because we&#8217;ll change it to a hand gesture when we&#8217;ll hover on <strong>retry<\/strong> and <strong>home buttons<\/strong>.<\/p>\n\n\n\n<p>After then, we checked if the mouse cursor&#8217;s <strong>x-coordinate<\/strong> is greater than <strong>30 <\/strong>and <strong>less than the width<\/strong> of the button which is <strong>home<\/strong> in this case and after that we checked if the mouse cursor&#8217;s <strong>y-coordinate<\/strong> is greater than <strong>220<\/strong> and less than the <strong>220 + height of the button<\/strong>. <br><br>The same logic goes with the home button but <strong>coordinates <\/strong>are different which you can see in the code.<\/p>\n\n\n\n<p>After then, we changed the mouse cursor to a hand gesture if the above statement is true. After it, we checked it the user clicked on the button if yes then gave them the desired result like if they click on the <strong>home button <\/strong>then return to the welcome screen by calling the <strong>welcome screen<\/strong> function and if they click on the <strong>retry button <\/strong>then start the game for them again by calling our <strong>main game<\/strong> function.<\/p>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<!--nextpage-->\n\n\n\n<h2 class=\"wp-block-heading\" id=\"adding-intro-and-background-music\">ADDING INTRO AND BACKGROUND MUSIC<\/h2>\n\n\n\n<p>Our game is completed but to add beauty and more entertainment we would like to have some background and intro music as well when we start to play the game. There is nothing complex it&#8217;s just a couple of lines of codes in the code of Flappy Bird In Python Pygame.<\/p>\n\n\n\n<p>First, we&#8217;ll add <strong>intro music<\/strong> then we&#8217;ll add <strong>background music<\/strong>. The <strong>intro music <\/strong>will be played till we start to play the game. As soon as we start to play the game then our <strong>intro music <\/strong>should stop and after then <strong>background music <\/strong>should play.<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\">import random #for generating random numbers\nimport sys #To Exit the game\nimport pygame\nfrom pygame.locals import * #Basic Pygame Imports\n\nFPS = 32\nSCREENWIDTH = 289\nSCREENHEIGHT = 511\nSCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\nGROUNDY = SCREENHEIGHT*0.8\nGAME_SPRITES = {}\nGAME_SOUNDS = {}\nPLAYER = 'resources\\SPRITES\\\\bird.png'\nBACKGROUND = 'resources\\SPRITES\\\\bg.jpeg'\nPIPE = 'resources\\SPRITES\\pipe.png '\n\ndef welcomeScreen():\n\n    #IT WIll Show Welcome Screen TO user to make the game more interactive and interesting\n    playerx = int(SCREENWIDTH\/5)\n    playery = int(SCREENHEIGHT - GAME_SPRITES['player'].get_height())\/2\n    messagex = int(SCREENWIDTH - GAME_SPRITES['message'].get_width())\/2\n    messagey = int(SCREENHEIGHT * 0.13)\n    basex = 0\n    \n    # Drawing Rectangle for playbutton\n    playbutton = pygame.Rect(108,222,68,65)\n\n    while True:\n        for event in pygame.event.get():\n             #If user clicks on Cross or presses the Escape button Close the Game\n            if event.type== QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            elif event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                return\n\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n            if pygame.mouse.get_pos()[0] > playbutton[0]  and pygame.mouse.get_pos()[0] &lt; playbutton[0] + playbutton[2]:\n                if pygame.mouse.get_pos()[1] > playbutton[1]  and pygame.mouse.get_pos()[1] &lt; playbutton[1] + playbutton[3]:\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n\n            if playbutton.collidepoint(pygame.mouse.get_pos()): #checking if mouse is collided with the play button\n            \n                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: #checking if mouse has been clicked\n                    mainGame()\n\n            else :\n                SCREEN.blit(GAME_SPRITES['background'],(0,0))\n                SCREEN.blit(GAME_SPRITES['player'],(playerx,playery))\n                SCREEN.blit(GAME_SPRITES['message'],(messagex,messagey))\n                SCREEN.blit(GAME_SPRITES['base'],(basex,GROUNDY))\n                #Adding INRO Music\n                pygame.mixer.music.load('resources\/AUDIO\/INTROMUSIC.mp3')\n                pygame.mixer.music.play()\n                pygame.display.update()\n                FPSCLOCK.tick(FPS)\n\ndef mainGame():\n    \n    #ADDING THE BACKGROUND MUSIC\n    pygame.mixer.music.stop()\n    pygame.mixer.music.load('resources\/AUDIO\/BGMUSIC.mp3')\n    pygame.mixer.music.play()\n    score = 0\n    playerx = int(SCREENWIDTH\/5)\n    playery = int (SCREENHEIGHT\/2)\n    basex = 0\n\n    #Creating upper and Lower Pipes for the game\n    newPipe1 = getRandomPipe()\n    newPipe2 = getRandomPipe()\n\n    # Upper pipe List\n    upperPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[0]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[0]['y']}\n    ]\n\n    #lists of Lower Pipe\n    lowerPipes = [\n        {'x':SCREENWIDTH + 200, 'y': newPipe1[1]['y']},\n        {'x':SCREENWIDTH + 200 + (SCREENWIDTH\/2), 'y': newPipe2[1]['y']}\n    ]\n\n    pipeVelX = -4\n    playerVelY = -9\n    playerMaxVelY = 10  \n    playerMinVelY = -8\n    playerAccY = 1\n\n    playerFlapAccv = -8 # velocity while flapping\n    playerFlapped = False # It is true only when the bird is flapping\n\n    while True:\n\n        for event in pygame.event.get():\n           \n            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n\n            if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):\n                if playery > 0:\n                    playerVelY = playerFlapAccv\n                    playerFlapped = True\n                    GAME_SOUNDS['wing'].play()\n\n        crashTest = isCollide(playerx, playery, upperPipes, lowerPipes) # This function will return true if the player is crashed\n        if crashTest:\n            return     \n\n        #check for score\n        playerMidPos = playerx + GAME_SPRITES['player'].get_width()\/2\n        for pipe in upperPipes:\n            pipeMidPos = pipe['x'] + GAME_SPRITES['pipe'][0].get_width()\/2\n            if pipeMidPos&lt;= playerMidPos &lt; pipeMidPos +4:\n                score +=1\n                print(f\"Your score is {score}\") \n                GAME_SOUNDS['point'].play()\n\n        if playerVelY &lt;playerMaxVelY and not playerFlapped:\n            playerVelY += playerAccY\n\n        if playerFlapped:\n            playerFlapped = False            \n        playerHeight = GAME_SPRITES['player'].get_height()\n        playery = playery + min(playerVelY, GROUNDY - playery - playerHeight)\n\n        # move pipes to the left\n        for upperPipe , lowerPipe in zip(upperPipes, lowerPipes):\n            upperPipe['x'] += pipeVelX\n            lowerPipe['x'] += pipeVelX\n\n        # Add a new pipe when the first is about to cross the leftmost part of the screen\n        if 0&lt;upperPipes[0]['x']&lt;5:\n            newpipe = getRandomPipe()\n            upperPipes.append(newpipe[0])\n            lowerPipes.append(newpipe[1])\n\n        # if the pipe is out of the screen, remove it\n        if upperPipes[0]['x'] &lt; -GAME_SPRITES['pipe'][0].get_width():\n            upperPipes.pop(0)\n            lowerPipes.pop(0)\n\n        # Lets blit our sprites now\n        SCREEN.blit(GAME_SPRITES['background'], (0, 0))\n        for upperPipe, lowerPipe in zip(upperPipes, lowerPipes):\n            SCREEN.blit(GAME_SPRITES['pipe'][0], (upperPipe['x'], upperPipe['y']))\n            SCREEN.blit(GAME_SPRITES['pipe'][1], (lowerPipe['x'], lowerPipe['y']))\n\n        SCREEN.blit(GAME_SPRITES['base'], (basex, GROUNDY))\n        SCREEN.blit(GAME_SPRITES['player'], (playerx, playery))\n        myDigits = [int(x) for x in list(str(score))]\n        width = 0\n        for digit in myDigits:\n            width += GAME_SPRITES['numbers'][digit].get_width()\n        Xoffset = (SCREENWIDTH - width)\/2\n\n        for digit in myDigits:\n            SCREEN.blit(GAME_SPRITES['numbers'][digit], (Xoffset, SCREENHEIGHT*0.12))\n            Xoffset += GAME_SPRITES['numbers'][digit].get_width()\n        pygame.display.update()\n        FPSCLOCK.tick(FPS)\n\ndef isCollide(playerx, playery, upperPipes, lowerPipes):\n    if playery> GROUNDY - 25  or playery&lt;0:\n        GAME_SOUNDS['hit'].play()\n        pygame.mixer.music.stop()\n        gameOver()\n\n    for pipe in upperPipes:\n        pipeHeight = GAME_SPRITES['pipe'][0].get_height()\n        if(playery &lt; pipeHeight + pipe['y'] and abs(playerx - pipe['x']) &lt; GAME_SPRITES['pipe'][0].get_width()-20):\n            GAME_SOUNDS['hit'].play()\n            print(playerx, pipe['x'],)\n            pygame.mixer.music.stop()\n            gameOver()\n            \n\n    for pipe in lowerPipes:\n        if (playery + GAME_SPRITES['player'].get_height() > pipe['y']) and abs(playerx - pipe['x']) &lt; GAME_SPRITES['pipe'][0].get_width()-20:\n            GAME_SOUNDS['hit'].play()\n            pygame.mixer.music.stop()\n            gameOver()\n\n    return False\n\n\ndef getRandomPipe():\n    \"\"\"\n    generating positions of the two pipes one upper pipe and other lower pipe \n    To blit on the Screen\n    \"\"\"\n                \n    pipeHeight = GAME_SPRITES['pipe'][0].get_height()\n    offset = SCREENHEIGHT\/4.5\n    y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES['base'].get_height() - 1.2 *offset))\n    pipeX = SCREENWIDTH + 10\n    y1 = pipeHeight - y2 + offset\n    pipe = [ \n        {'x': pipeX, 'y': -y1}, #Upper Pipes\n        {'x': pipeX, 'y': y2}   #Lower Pipes\n    ]\n    return pipe \n\ndef gameOver():\n    \n    SCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))\n    pygame.display.set_caption('Flappy Bird With Sameer')\n    GAME_SPRITES['OVER'] = pygame.image.load('resources\/SPRITES\/gameover.png').convert_alpha()\n    GAME_SPRITES['RETRY'] = pygame.image.load('resources\/SPRITES\/retry.png').convert_alpha()\n    GAME_SPRITES['HOME'] = pygame.image.load('resources\/SPRITES\/Home.png').convert_alpha()\n    SCREEN.blit(GAME_SPRITES['background'],(0,0))\n    SCREEN.blit(GAME_SPRITES['base'],(0,GROUNDY))\n    SCREEN.blit(GAME_SPRITES['OVER'], (0,0))\n    SCREEN.blit(GAME_SPRITES['RETRY'], (30, 220))\n    SCREEN.blit(GAME_SPRITES['HOME'], (30, 280))\n    \n    pygame.display.update()\n\n    while True:\n        for event in pygame.event.get():\n            \n            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):\n                pygame.quit()\n                sys.exit()\n \n            if event.type == KEYDOWN and event.key == K_SPACE:\n                mainGame()\n  \n            ### RETRY BUTTON\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['RETRY'].get_width():\n                if pygame.mouse.get_pos()[1]>220 and pygame.mouse.get_pos()[1]&lt; 220+GAME_SPRITES['RETRY'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        \n                        mainGame()\n                      \n            ### HOME BUTTON\n            if pygame.mouse.get_pos()[0]>30 and pygame.mouse.get_pos()[0]&lt; 30+GAME_SPRITES['HOME'].get_width():\n                if pygame.mouse.get_pos()[1]>280 and pygame.mouse.get_pos()[1]&lt; 280+GAME_SPRITES['HOME'].get_height():\n                    pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)\n                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:\n                        welcomeScreen()\n            pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)\n\n\n ### This is the point from Where Our Game is going to be Started ###\nif __name__ == \"__main__\":\n\n    pygame.init() #Initializing the Modules of Pygame \n    FPSCLOCK = pygame.time.Clock() #for controlling the FPS\n    pygame.display.set_caption('Flappy Bird With Sameer') #Setting the Caption of The Game\n\n    #### LOADING THE SPRITES ####\n\n    GAME_SPRITES['numbers'] = (\n        pygame.image.load('resources\\SPRITES\\\\0.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\1.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\2.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\3.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\4.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\5.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\6.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\7.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\8.png').convert_alpha(),\n        pygame.image.load('resources\\SPRITES\\\\9.png').convert_alpha(),\n    \n    ) \n    \n    \n    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert_alpha()\n    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()\n    GAME_SPRITES['message'] = pygame.image.load('resources\\SPRITES\\message.png').convert_alpha()\n    GAME_SPRITES['base'] = pygame.image.load('resources\\SPRITES\\\\base.png').convert_alpha()\n    GAME_SPRITES['pipe'] = (\n        \n        \n    pygame.transform.rotate(pygame.image.load(PIPE).convert_alpha(), 180), #### UPPER PIPES, WE JUST ROTATED THE PIPE BY 180deg\n    pygame.image.load(PIPE).convert_alpha()   #### LOWER PIPES  \n    )\n\n    #Game Sounds\n    GAME_SOUNDS['die'] = pygame.mixer.Sound('resources\\AUDIO\\die.wav')\n    GAME_SOUNDS['hit'] = pygame.mixer.Sound('resources\\AUDIO\\hit.wav')\n    GAME_SOUNDS['point'] = pygame.mixer.Sound('resources\\AUDIO\\point.wav')\n    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('resources\\AUDIO\\swoosh.wav')\n    GAME_SOUNDS['wing'] = pygame.mixer.Sound('resources\\AUDIO\\wing.wav')\n    while True:\n        welcomeScreen() #Shows a welcomescreen to the user until they starts the game\n        mainGame() #This is our main game funtion<\/pre><\/div>\n\n\n\n<p><br>FIRST, we loaded our intro music and then played the music in the welcome screen function, and then we went to the main game function first we stopped the music that we were already playing and then loaded our intro music and played that.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"wp-block-heading\">SUMMARY<\/h2>\n\n\n\n<p>So, we have completed this beautiful journey of creating the <strong>Flappy Bird In Python Pygame with source code.<\/strong> We covered every basic to the basic concept that we can and tried my best to explain it to you guys. <br><\/p>\n\n\n\n<p>Now I am thinking of shouldn&#8217;t have a quick recap of what we all did. I think yes because it was a long journey so if we have a quick recap then things will be more clear and will be easy to understand.<br>So let&#8217;s start don&#8217;t get bothered by it I&#8217;ll try to keep it as short as possible<\/p>\n\n\n\n<p>At first, our game has three parts which are welcome screen, main game, and game over. <br>The welcome screen as the name suggests is the entrance or we can say welcome door of the game. In this game, we have some intro music going on and we gave the user the right either to <strong>play the game or quit the game<\/strong>. We can move further or start playing the game by pressing the <strong>space bar<\/strong> or clicking on the <strong>play button<\/strong><\/p>\n\n\n\n<p>After then we enter into our main game which is the actual game. In this, we have two pipes that are obstacles for the player. These pipes come randomly by generating some random <strong>y&#8217;s<\/strong> for pipes. We have some gap between the pipes which we call <strong>offse<\/strong>t. And our player has to pass the pipe without colliding with it safely through the <strong>offset<\/strong>. We can play the game by pressing the <strong>space bar or up arrow key.<\/strong><\/p>\n\n\n\n<p>After every successful passing between the pipes, we got the points and our score increased. And we displayed this score on the screen also.<\/p>\n\n\n\n<p>We also have some very interesting sound effects such as birds flapping, if we got the point and if we hit some obstacles, and also the background music is going on.<\/p>\n\n\n\n<p>After then we check for the collision we have 4 types of collision. The first and second collision is between the ground and the upmost layer of the screen. After then, the 3rd and 4th are the collisions between the pipes.<\/p>\n\n\n\n<p>If our bird collided with any of these, the hit sound effect will play and then we call the gameover function.<br>In the game over function, we gave the user again either to play the game or go back to the home screen.<br>And then boom our game is ready.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OUTRO<\/h2>\n\n\n\n<p>First of all, I want to thank you as well as congratulate you for making this wonderful game and thank you all for giving your patience and time, and for staying connected with me till this point. But I&#8217;m damn sure you won&#8217;t regret giving this time as I promised you will have a wonderful project with you so, I kept my promise by presenting Flappy Bird In Python Pygame<\/p>\n\n\n\n<p>And now it&#8217;s your time to show some creativity of your own and let me give you one task. Update the highscore feature in the game and then display the score and highscore at the end of the game, I mean in the game over function.<\/p>\n\n\n\n<p>Now, I&#8217;m finalizing this beautiful journey hope you all liked my effort, and if you have any queries or any problems related to the game you can reach me at <a href=\"https:\/\/telegram.me\/expert_in_python\" target=\"_blank\" rel=\"noreferrer noopener\">@expert_in_python<\/a> and <a href=\"https:\/\/www.instagram.com\/python.hub\/\" target=\"_blank\" rel=\"noreferrer noopener\">@python.hub<\/a> on Instagram. <br>You can also send us the updated version of the game we would appreciate your efforts.<\/p>\n\n\n\n<p>Thanks again till then keep coding and keep visiting <a href=\"https:\/\/copyassignment.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">copyassignment<\/a> a place to learn to code easily and quickly.<\/p>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<h2 class=\"has-pale-pink-background-color has-background wp-block-heading\"><a href=\"https:\/\/drive.google.com\/drive\/folders\/1QMbd2b-l_dsE38nhIw_g9gOvSzbUj_9R?usp=sharing\" target=\"_blank\" rel=\"noreferrer noopener\">FLAPPY BIRD SOURCE CODE SPRITES AND MUSIC<\/a><\/h2>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Tags-&gt; Flappy Bird In Python, Pygame Flappy Bird In Pygame Python, Flappy Bird In Pygame Python with source code, the project for class 12th, python project with source code, flappy bird game in python, the game of flappy bird using python.<\/p>\n\n\n\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9886351916045880\"\n     crossorigin=\"anonymous\"><\/script>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-9886351916045880\"\n     data-ad-slot=\"7933252109\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><strong>Also Read:<\/strong><\/p>\n\n\n<ul class=\"wp-block-latest-posts__list is-grid columns-3 wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/you-can-now-run-ai-fully-offline-on-your-phone-googles-gemma-4-just-changed-everything\/\">You Can Now Run AI Fully Offline on Your Phone \u2014 Google\u2019s Gemma 4 Just Changed Everything<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/i-built-a-24x7-ai-blogging-system-for-wordpress-using-python-free-full-code-inside\/\">I Built a 24\u00d77 AI Blogging System for WordPress Using Python (Free) \u2014 Full Code Inside<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/this-reddit-user-hacked-ai-with-simple-tricks-and-the-results-are-insane\/\">This Reddit User \u201cHacked\u201d AI With Simple Tricks\u2026 And The Results Are Insane<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/one-rm-rf-command-almost-wiped-out-100-million-worth-of-toy-story-2\/\">One \u201crm -rf\u201d Command Almost Wiped Out $100 Million Worth of Toy Story 2<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/how-to-make-money-with-chatgpt-in-2026-a-real-guide-that-still-works\/\">How to Make Money with ChatGPT in 2026: A Real Guide That Still Works<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/picoclaw-vs-openclaw-the-tiny-ai-that-could-replace-powerful-ai-agents\/\">PicoClaw vs OpenClaw: The Tiny AI That Could Replace Powerful AI Agents<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/oracle-layoffs-2026-people-woke-up-to-an-email-and-lost-their-jobs-instantly\/\">Oracle Layoffs 2026: People Woke Up to an Email\u2026 and Lost Their Jobs Instantly<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/x-new-video-update-is-breaking-a-basic-feature-and-users-are-not-happy\/\">X\u2019s New Video Update Is Breaking a Basic Feature \u2014 And Users Are Not Happy<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/the-most-shocking-military-tech-yet-robot-soldiers-that-could-change-warfare-forever\/\">The Most Shocking Military Tech Yet: Robot Soldiers That Could Change Warfare Forever<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/sora-shutdown-the-reality-check-that-shook-ai-video-and-what-comes-next\/\">Sora Shutdown: The Reality Check That Shook AI Video \u2014 And What Comes Next<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/aya-expanse-supports-multiple-languages-for-diverse-global-applications\/\">Aya Expanse supports multiple languages for diverse global applications<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/alibaba-releases-page-agent-on-github-for-public-access\/\">Alibaba releases Page Agent on GitHub for public access<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/google-sheets-gemini-reaches-new-levels-of-performance-and-accuracy\/\">Google Sheets Gemini reaches new levels of performance and accuracy<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/artificial-intelligence-boosts-cardiac-care-in-rural-australian-communities\/\">Artificial intelligence boosts cardiac care in rural Australian communities<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/nvidia-gtc-2026-offers-insights-into-future-artificial-intelligence-developments\/\">NVIDIA GTC 2026 Offers Insights into Future Artificial Intelligence Developments<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/google-deepmind-updates-satellite-embedding-dataset-with-2025-data\/\">Google DeepMind Updates Satellite Embedding Dataset with 2025 Data<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/enhancing-hierarchical-instruction-in-advanced-large-language-models\/\">Enhancing hierarchical instruction in advanced large language models<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/meta-supports-community-development-near-its-data-centers-through-grants\/\">Meta supports community development near its data centers through grants<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/exploring-the-world-of-underwater-robotics-through-coding-techniques\/\">Exploring the world of underwater robotics through coding techniques<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/abb-robotics-partners-with-nvidia-for-large-scale-physical-ai-solutions\/\">ABB Robotics partners with NVIDIA for large scale physical AI solutions<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/why-all-ai-models-are-slowly-becoming-the-same-model\/\">Why All AI Models Are Slowly Becoming the Same Model<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/aam-aadmi-vs-corrupt-system-how-chatgpt-helped-one-guy-expose-govt-fraud-the-story-ravi-and-the-missing-light-pole\/\">Aam Aadmi vs Corrupt System: How ChatGPT Helped One Guy Expose Govt Fraud, The Story: \u201cRavi and The Missing Light Pole\u201d<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/chatgpt-asked-a-person-to-commit-suicide-to-solve-the-problem\/\">ChatGPT Asked a person to commit suicide to solve the problem<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/viral-moment-chinas-agibot-x2-makes-history-with-worlds-first-webster-backflip\/\">Viral Moment: China\u2019s AgiBot X2 Makes History With World\u2019s First Webster Backflip<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/copyassignment.com\/terminator-rising-albania-hands-power-to-ai-echoing-a-nightmare-of-human-extinction\/\">Terminator Rising: Albania Hands Power to AI, Echoing a Nightmare of Human Extinction<\/a><\/li>\n<\/ul>\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OVERVIEW OF THE PROJECT Hi there, welcome to the copyassignment hope you all are doing wonderful. Today, we are here to make a very interesting&#8230;<\/p>\n","protected":false},"author":62,"featured_media":9098,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,1060,1061,1147],"tags":[1383,1382,1378,1377,1379,1380,1381],"class_list":["post-8955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allcategorites","category-game-in-python","category-gui-python-projects","category-pygame-tutorial","tag-class-12","tag-class-12th","tag-flappy-bird","tag-flappy-bird-in-pygame-python","tag-game-in-python","tag-game-using-python","tag-project-in-python","wpcat-22-id","wpcat-1060-id","wpcat-1061-id","wpcat-1147-id"],"_links":{"self":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/8955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/comments?post=8955"}],"version-history":[{"count":0,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/8955\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media\/9098"}],"wp:attachment":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media?parent=8955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/categories?post=8955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/tags?post=8955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}