Course Content
  • 1. Python Tutorials Teaser
    Free YouTube Video
  • 2. What Is Programming and Why Python?
    Free YouTube Video
  • 3. Downloading Python and Pycharm Installation
    Free YouTube Video
  • 4. Using Modules & Pip In Python
    Free YouTube Video
  • 5. Writing Our First Python Program
    Free YouTube Video
  • 6. Using Python As A Calculator
    Free YouTube Video
  • 7. Comments, Escape Sequences & Print Statement
    Free YouTube Video
  • 8. Variables, Datatypes and Typecasting
    Free YouTube Video
  • 9. String Slicing And Other Functions In Python
    Free YouTube Video
  • 10. Python Lists And List Functions
    Free YouTube Video
  • 11. Dictionary & Its Functions Explained
    Free YouTube Video
  • 12. Python Exercise 1 - Apni Dictionary
    Free YouTube Video
  • 13. Sets In Python
    Free YouTube Video
  • 14. If Else & Elif Conditionals In Python
    Free YouTube Video
  • 15. Exercise 1 - Solution And Your Answers
    Free YouTube Video
  • 16. Python Exercise 2 - Faulty Calculator
    Free YouTube Video
  • 17. For Loops In Python
    Free YouTube Video
  • 18. While Loops In Python
    Free YouTube Video
  • 19. Break & Continue Statements In Python
    Free YouTube Video
  • 20. Python Exercise 2: Faulty Calculator Solution
    Free YouTube Video
  • 21. Python Exercise 3 - Guess The Number
    Free YouTube Video
  • 22. Operators In Python
    Free YouTube Video
  • 23. Short Hand If Else Notation In Python
    Free YouTube Video
  • 24. Functions And Docstrings
    Free YouTube Video
  • 25. Try Except Exception Handling In Python
    Free YouTube Video
  • 26. Python File IO Basics
    Free YouTube Video
  • 27. Open(), Read() & Readline() For Reading File
    Free YouTube Video
  • 28. Python Exercise 3: Solution
    Free YouTube Video
  • 29. Writing And Appending To A File
    Free YouTube Video
  • 30. Python Exercise 4: Astrologer's Stars
    Free YouTube Video
  • 31. Seek(), tell() & More On Python Files
    Free YouTube Video
  • 32. Using With Block To Open Python Files
    Free YouTube Video
  • 33. Exercise 5: Health Management System
    Free YouTube Video
  • 34. Scope, Global Variables and Global Keyword
    Free YouTube Video
  • 35. Recursions: Recursive Vs Iterative Approach
    Free YouTube Video
  • 36. Exercise 4: Solution And First Solver
    Free YouTube Video
  • 37. Anonymous/Lambda Functions In Python
    Free YouTube Video
  • 38. Exercise 5: Solution And First Solver
    Free YouTube Video
  • 39. Using Python External & Built In Modules
    Free YouTube Video
  • 40. F-Strings & String Formatting In Python
    Free YouTube Video
  • 41. Exercise 6: Game Development: Snake Water Gun
    Free YouTube Video
  • 42. *args and **kwargs In Python
    Free YouTube Video
  • 43. Time Module In Python
    Free YouTube Video
  • 44. Virtual Environment & Requirements.txt
    Free YouTube Video
  • 45. Enumerate Function
    Free YouTube Video
  • 46. How Import Works In Python?
    Free YouTube Video
  • 47. If __name__==__main__ usage & necessity
    Free YouTube Video
  • 48. Join Function In Python
    Free YouTube Video
  • 49. Map, Filter & Reduce
    Free YouTube Video
  • 50. Exercise 6 Solution & First Solver
    Free YouTube Video
  • 51. Exercise 7: Healthy Programmer
    Free YouTube Video
  • 52. Decorators In Python
    Free YouTube Video
  • 53. Classes & Objects (OOPS)
    Free YouTube Video
  • 54. Creating Our First Class In Python
    Free YouTube Video
  • 55. Instance & Class Variables | Python Tutorials For Absolute Beginners In Hindi #54
    Free YouTube Video
  • 56. Self & __init__() (Constructors) | Python Tutorials For Absolute Beginners In Hindi #55
    Free YouTube Video
  • 57. Class Methods In Python | Python Tutorials For Absolute Beginners In Hindi #56
    Free YouTube Video
  • 58. Class Methods As Alternative Constructors | Python Tutorials For Absolute Beginners In Hindi #57
    Free YouTube Video
  • 59. Static Methods In Python | Python Tutorials For Absolute Beginners In Hindi #58
    Free YouTube Video
  • 60. Abstraction & Encapsulation | Python Tutorials For Absolute Beginners In Hindi #59
    Free YouTube Video
  • 61. Single Inheritance | Python Tutorials For Absolute Beginners In Hindi #60
    Free YouTube Video
  • 62. Multiple Inheritance | Python Tutorials For Absolute Beginners In Hindi #61
    Free YouTube Video
  • 63. Multilevel Inheritance | Python Tutorials For Absolute Beginners In Hindi #62
    Free YouTube Video
  • 64. Public, Private & Protected Access Specifiers | Python Tutorials For Absolute Beginners In Hindi #63
    Free YouTube Video
  • 65. Polymorphism In Python | Python Tutorials For Absolute Beginners In Hindi #64
    Free YouTube Video
  • 66. Super() and Overriding In Classes | Python Tutorials For Absolute Beginners In Hindi #65
    Free YouTube Video
  • 67. Diamond Shape Problem In Multiple Inheritance | Python Tutorials For Absolute Beginners In Hindi #66
    Free YouTube Video
  • 68. Operator Overloading & Dunder Methods | Python Tutorials For Absolute Beginners In Hindi #67
    Free YouTube Video
  • 69. Abstract Base Class & @abstractmethod | Python Tutorials For Absolute Beginners In Hindi #68
    Free YouTube Video
  • 70. Setters & Property Decorators | Python Tutorials For Absolute Beginners In Hindi #69
    Free YouTube Video
  • 71. Object Introspection | Python Tutorials For Absolute Beginners In Hindi #70
    Free YouTube Video
  • 72. Python Mini Project #1 | Python Tutorials For Absolute Beginners In Hindi #71
    Free YouTube Video
  • 73. Generators In Python | Python Tutorials For Absolute Beginners In Hindi #72
    Free YouTube Video
  • 74. Python Comprehensions | Python Tutorials For Absolute Beginners In Hindi #73
    Free YouTube Video
  • 75. Using Else With For Loops | Python Tutorials For Absolute Beginners In Hindi #74
    Free YouTube Video
  • 76. Function Caching In Python | Python Tutorials For Absolute Beginners In Hindi #75
    Free YouTube Video
  • 77. Else & Finally In Try Except | Python Tutorials For Absolute Beginners In Hindi #76
    Free YouTube Video
  • 78. Coroutines In Python | Python Tutorials For Absolute Beginners In Hindi #77
    Free YouTube Video
  • 79. Exercise 7: Solution & First Solver | Python Tutorials For Absolute Beginners In Hindi #78
    Free YouTube Video
  • 80. Os Module | Python Tutorials For Absolute Beginners In Hindi #79
    Free YouTube Video
  • 81. Exercise 8: Oh Soldier Prettify My Folder| Python Tutorials For Absolute Beginners In Hindi #80
    Free YouTube Video
  • 82. Requests Module For HTTP Requests | Python Tutorials For Absolute Beginners In Hindi #81
    Free YouTube Video
  • 83. Json Module | Python Tutorials For Absolute Beginners In Hindi #82
    Free YouTube Video
  • 84. Exercise 9: Akhbaar Padhke Sunaao | Python Tutorials For Absolute Beginners In Hindi #83
    Free YouTube Video
  • 85. Pickle Module | Python Tutorials For Absolute Beginners In Hindi #84
    Free YouTube Video
  • 86. Exercise 10: Pickling Iris | Python Tutorials For Absolute Beginners In Hindi #85
    Free YouTube Video
  • 87. Regular Expressions | Python Tutorials For Absolute Beginners In Hindi #86
    Free YouTube Video
  • 88. Converting .py to .exe | Python Tutorials For Absolute Beginners In Hindi #87
    Free YouTube Video
  • 89. Python Exercise 8: Solution + Tips | Python Tutorials For Absolute Beginners In Hindi #88
    Free YouTube Video
  • 90. Raise In Python + Examples | Python Tutorials For Absolute Beginners In Hindi #89
    Free YouTube Video
  • 91. Python 'is' vs '==': What's The Difference? | Python Tutorials For Absolute Beginners In Hindi #90
    Free YouTube Video
  • 92. Python 2.x Vs Python 3.x | Python Tutorials For Absolute Beginners In Hindi #91
    Free YouTube Video
  • 93. Python Exercise 9 Solution + Shoutouts | Python Tutorials For Absolute Beginners In Hindi #92
    Free YouTube Video
  • 94. Creating a Command Line Utility In Python | Python Tutorials For Absolute Beginners In Hindi #93
    Free YouTube Video
  • 95. Exercise 10: Solution + Shoutouts | Python Tutorials For Absolute Beginners In Hindi #94
    Free YouTube Video
  • 96. Creating a Python Package Using Setuptools | Python Tutorials For Absolute Beginners In Hindi #95
    Free YouTube Video
  • 97. Python Exercise 11: Regex Email Extractor | Python Tutorials For Absolute Beginners In Hindi #96
    Free YouTube Video
  • 98. Learning Path For Python Web Development | Python Tutorials For Absolute Beginners In Hindi #97
    Free YouTube Video
  • 99. Python GUI Development - Learning Path | Python Tutorials For Absolute Beginners In Hindi #98
    Free YouTube Video
  • 100. Machine Learning & Data Science Learning Path | Python Tutorials For Absolute Beginners In Hindi #99
    Free YouTube Video
  • 101. Regex Exercise 11 Solutions | Python Tutorials For Absolute Beginners In Hindi #100
    Free YouTube Video
  • 102. Mini Project 1 (OOPs Library) Solution | Python Tutorials For Absolute Beginners In Hindi #101
    Free YouTube Video
  • 103. Conclusion & Way Forward | Python Tutorials For Absolute Beginners In Hindi #102
    Free YouTube Video
  • 104. Practice Problem 1 (Easy) | Python Tutorials For Absolute Beginners In Hindi #103
    Free YouTube Video
  • 105. Python Practice 1 Solution | Python Tutorials For Absolute Beginners In Hindi #104
    Free YouTube Video
  • 106. Practice Problem 2 (Easy) | Python Tutorials For Absolute Beginners In Hindi #105
    Free YouTube Video
  • 107. Python Practice 2 Solution | Python Tutorials For Absolute Beginners In Hindi #106
    Free YouTube Video
  • 108. Python Practice 3 | Python Tutorials For Absolute Beginners In Hindi #107
    Free YouTube Video
  • 109. Python Problem 3: Solution | Python Tutorials For Absolute Beginners In Hindi #108
    Free YouTube Video
  • 110. Python Problem 4 | Python Tutorials For Absolute Beginners In Hindi #109
    Free YouTube Video
  • 111. Python Problem 4: Solution | Python Tutorials For Absolute Beginners In Hindi #110
    Free YouTube Video
  • 112. Python Problem 5 | Python Tutorials For Absolute Beginners In Hindi #111
    Free YouTube Video
  • 113. Python Problem 5: Solution | Python Tutorials For Absolute Beginners In Hindi #112
    Free YouTube Video
  • 114. Python Problem 6 | Python Tutorials For Absolute Beginners In Hindi #113
    Free YouTube Video
  • 115. Python Problem 6: Solution | Python Tutorials For Absolute Beginners In Hindi #114
    Free YouTube Video
  • 116. Python Problem 7 | Python Tutorials For Absolute Beginners In Hindi #115
    Free YouTube Video
  • 117. Python Problem 7: Solution | Python Tutorials For Absolute Beginners In Hindi #116
    Free YouTube Video
  • 118. Python Problem 8: Fake Multiplication Tables | Python Tutorials For Absolute Beginners In Hindi #117
    Free YouTube Video
  • 119. Python Problem 8: Solution | Python Tutorials For Absolute Beginners In Hindi #118
    Free YouTube Video
  • 120. Python Problem 9: Jumbled Funny Names | Python Tutorials For Absolute Beginners In Hindi #119
    Free YouTube Video
  • 121. Project 1: Iron Man Jarvis AI Desktop Voice Assistant | Python Tutorials For Absolute Beginners #120
    Free YouTube Video
  • 122. Project 2: Coding Flappy Bird Game (With Source Code) | Python Tutorials For Absolute Beginners #122
    Free YouTube Video
  • 123. Project 3: Third Umpire Decision Review System (DRS Gully Cricket) | Python Tutorials in Hindi #123
    Free YouTube Video
  • 124. Project 4: Indian Railways Announcement Software | Python Tutorials For Absolute Beginners #124
    Free YouTube Video
  • 125. CoronaVirus: Python Programming Solution to the Problem
    Free YouTube Video
  • 126. Covid -19: Creating a Realtime CoronaVirus Outbreak Notification System Using Python Programming
    Free YouTube Video
  • 127. Django Tutorial In Hindi
    Free YouTube Video
  • 128. I automated Dinosaur Game in Chrome
    Free YouTube Video
  • 129. VS Code Tutorial + Python Setup | Python Tutorials For Absolute Beginners In Hindi #121
    Free YouTube Video

Project 2: Coding Flappy Bird Game (With Source Code) | Python Tutorials For Absolute Beginners #122

In this tutorial, we are going to create a “Flappy Bird Game”. This video is going to be very practical and will help you in learning new concepts. So, do not skip this video because if you do so, you are gonna miss a very interesting part of this python series.

Prerequisite:-

The prerequisite of this project is the basic knowledge of python.

For this project, we are going to use the Virtual Studio Code IDE and the pygame module. Pygame is a library that is used in creating games in Python. It has four important things.

  • Game Loop
  • Events
  • Sprites
  • Sound

All of these four topics will be discussed in this tutorial.

When you complete this project, you will be able to create more games with more interesting features and concepts. After completing this project, you will be able to create its executable file which you can share with your friends or even use in interviews for showing your python skills.

This video is a part of python series. If you have not watched my python tutorial for absolute beginners, then what are you waiting for.  Click on the link below and start learning!

Python Tutorials For Absolute Beginners In Hindi

If you have ever tried a programming challenge, then you know they are fun. A great way to improve your coding skills is by solving coding challenges. Solving different types of challenges and puzzles can help you become a better problem solver. So, keep yourself motivated and stay up to date with codewithharry

 

Full Source Code with all the Images and Sounds is here: Click Here To Download

 

Code as described/written in the video

import random # For generating random numbers
import sys # We will use sys.exit to exit the program
import pygame
from pygame.locals import * # Basic pygame imports

# Global Variables for the game
FPS = 32
SCREENWIDTH = 289
SCREENHEIGHT = 511
SCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))
GROUNDY = SCREENHEIGHT * 0.8
GAME_SPRITES = {}
GAME_SOUNDS = {}
PLAYER = 'gallery/sprites/bird.png'
BACKGROUND = 'gallery/sprites/background.png'
PIPE = 'gallery/sprites/pipe.png'

def welcomeScreen():
    """
    Shows welcome images on the screen
    """

    playerx = int(SCREENWIDTH/5)
    playery = int((SCREENHEIGHT - GAME_SPRITES['player'].get_height())/2)
    messagex = int((SCREENWIDTH - GAME_SPRITES['message'].get_width())/2)
    messagey = int(SCREENHEIGHT*0.13)
    basex = 0
    while True:
        for event in pygame.event.get():
            # if user clicks on cross button, close the game
            if event.type == QUIT or (event.type==KEYDOWN and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()

            # If the user presses space or up key, start the game for them
            elif event.type==KEYDOWN and (event.key==K_SPACE or event.key == K_UP):
                return
            else:
                SCREEN.blit(GAME_SPRITES['background'], (0, 0))    
                SCREEN.blit(GAME_SPRITES['player'], (playerx, playery))    
                SCREEN.blit(GAME_SPRITES['message'], (messagex,messagey ))    
                SCREEN.blit(GAME_SPRITES['base'], (basex, GROUNDY))    
                pygame.display.update()
                FPSCLOCK.tick(FPS)

def mainGame():
    score = 0
    playerx = int(SCREENWIDTH/5)
    playery = int(SCREENWIDTH/2)
    basex = 0

    # Create 2 pipes for blitting on the screen
    newPipe1 = getRandomPipe()
    newPipe2 = getRandomPipe()

    # my List of upper pipes
    upperPipes = [
        {'x': SCREENWIDTH+200, 'y':newPipe1[0]['y']},
        {'x': SCREENWIDTH+200+(SCREENWIDTH/2), 'y':newPipe2[0]['y']},
    ]
    # my List of lower pipes
    lowerPipes = [
        {'x': SCREENWIDTH+200, 'y':newPipe1[1]['y']},
        {'x': SCREENWIDTH+200+(SCREENWIDTH/2), 'y':newPipe2[1]['y']},
    ]

    pipeVelX = -4

    playerVelY = -9
    playerMaxVelY = 10
    playerMinVelY = -8
    playerAccY = 1

    playerFlapAccv = -8 # velocity while flapping
    playerFlapped = False # It is true only when the bird is flapping


    while True:
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN and (event.key == K_SPACE or event.key == K_UP):
                if playery > 0:
                    playerVelY = playerFlapAccv
                    playerFlapped = True
                    GAME_SOUNDS['wing'].play()


        crashTest = isCollide(playerx, playery, upperPipes, lowerPipes) # This function will return true if the player is crashed
        if crashTest:
            return     

        #check for score
        playerMidPos = playerx + GAME_SPRITES['player'].get_width()/2
        for pipe in upperPipes:
            pipeMidPos = pipe['x'] + GAME_SPRITES['pipe'][0].get_width()/2
            if pipeMidPos<= playerMidPos < pipeMidPos +4:
                score +=1
                print(f"Your score is {score}") 
                GAME_SOUNDS['point'].play()


        if playerVelY <playerMaxVelY and not playerFlapped:
            playerVelY += playerAccY

        if playerFlapped:
            playerFlapped = False            
        playerHeight = GAME_SPRITES['player'].get_height()
        playery = playery + min(playerVelY, GROUNDY - playery - playerHeight)

        # move pipes to the left
        for upperPipe , lowerPipe in zip(upperPipes, lowerPipes):
            upperPipe['x'] += pipeVelX
            lowerPipe['x'] += pipeVelX

        # Add a new pipe when the first is about to cross the leftmost part of the screen
        if 0<upperPipes[0]['x']<5:
            newpipe = getRandomPipe()
            upperPipes.append(newpipe[0])
            lowerPipes.append(newpipe[1])

        # if the pipe is out of the screen, remove it
        if upperPipes[0]['x'] < -GAME_SPRITES['pipe'][0].get_width():
            upperPipes.pop(0)
            lowerPipes.pop(0)
        
        # Lets blit our sprites now
        SCREEN.blit(GAME_SPRITES['background'], (0, 0))
        for upperPipe, lowerPipe in zip(upperPipes, lowerPipes):
            SCREEN.blit(GAME_SPRITES['pipe'][0], (upperPipe['x'], upperPipe['y']))
            SCREEN.blit(GAME_SPRITES['pipe'][1], (lowerPipe['x'], lowerPipe['y']))

        SCREEN.blit(GAME_SPRITES['base'], (basex, GROUNDY))
        SCREEN.blit(GAME_SPRITES['player'], (playerx, playery))
        myDigits = [int(x) for x in list(str(score))]
        width = 0
        for digit in myDigits:
            width += GAME_SPRITES['numbers'][digit].get_width()
        Xoffset = (SCREENWIDTH - width)/2

        for digit in myDigits:
            SCREEN.blit(GAME_SPRITES['numbers'][digit], (Xoffset, SCREENHEIGHT*0.12))
            Xoffset += GAME_SPRITES['numbers'][digit].get_width()
        pygame.display.update()
        FPSCLOCK.tick(FPS)

def isCollide(playerx, playery, upperPipes, lowerPipes):
    if playery> GROUNDY - 25  or playery<0:
        GAME_SOUNDS['hit'].play()
        return True
    
    for pipe in upperPipes:
        pipeHeight = GAME_SPRITES['pipe'][0].get_height()
        if(playery < pipeHeight + pipe['y'] and abs(playerx - pipe['x']) < GAME_SPRITES['pipe'][0].get_width()):
            GAME_SOUNDS['hit'].play()
            return True

    for pipe in lowerPipes:
        if (playery + GAME_SPRITES['player'].get_height() > pipe['y']) and abs(playerx - pipe['x']) < GAME_SPRITES['pipe'][0].get_width():
            GAME_SOUNDS['hit'].play()
            return True

    return False

def getRandomPipe():
    """
    Generate positions of two pipes(one bottom straight and one top rotated ) for blitting on the screen
    """
    pipeHeight = GAME_SPRITES['pipe'][0].get_height()
    offset = SCREENHEIGHT/3
    y2 = offset + random.randrange(0, int(SCREENHEIGHT - GAME_SPRITES['base'].get_height()  - 1.2 *offset))
    pipeX = SCREENWIDTH + 10
    y1 = pipeHeight - y2 + offset
    pipe = [
        {'x': pipeX, 'y': -y1}, #upper Pipe
        {'x': pipeX, 'y': y2} #lower Pipe
    ]
    return pipe






if __name__ == "__main__":
    # This will be the main point from where our game will start
    pygame.init() # Initialize all pygame's modules
    FPSCLOCK = pygame.time.Clock()
    pygame.display.set_caption('Flappy Bird by CodeWithHarry')
    GAME_SPRITES['numbers'] = ( 
        pygame.image.load('gallery/sprites/0.png').convert_alpha(),
        pygame.image.load('gallery/sprites/1.png').convert_alpha(),
        pygame.image.load('gallery/sprites/2.png').convert_alpha(),
        pygame.image.load('gallery/sprites/3.png').convert_alpha(),
        pygame.image.load('gallery/sprites/4.png').convert_alpha(),
        pygame.image.load('gallery/sprites/5.png').convert_alpha(),
        pygame.image.load('gallery/sprites/6.png').convert_alpha(),
        pygame.image.load('gallery/sprites/7.png').convert_alpha(),
        pygame.image.load('gallery/sprites/8.png').convert_alpha(),
        pygame.image.load('gallery/sprites/9.png').convert_alpha(),
    )

    GAME_SPRITES['message'] =pygame.image.load('gallery/sprites/message.png').convert_alpha()
    GAME_SPRITES['base'] =pygame.image.load('gallery/sprites/base.png').convert_alpha()
    GAME_SPRITES['pipe'] =(pygame.transform.rotate(pygame.image.load( PIPE).convert_alpha(), 180), 
    pygame.image.load(PIPE).convert_alpha()
    )

    # Game sounds
    GAME_SOUNDS['die'] = pygame.mixer.Sound('gallery/audio/die.wav')
    GAME_SOUNDS['hit'] = pygame.mixer.Sound('gallery/audio/hit.wav')
    GAME_SOUNDS['point'] = pygame.mixer.Sound('gallery/audio/point.wav')
    GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('gallery/audio/swoosh.wav')
    GAME_SOUNDS['wing'] = pygame.mixer.Sound('gallery/audio/wing.wav')

    GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert()
    GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()

    while True:
        welcomeScreen() # Shows welcome screen to the user until he presses a button
        mainGame() # This is the main game function 

You need to be logged in to post a comment!

Comments

thakkarprince100 Jul 3, 2021
Bhai in jarvis ai program it is showing that there is unresolved reference for name
cliff Jan 14, 2021
harry bhai which software you have used for trimming audio files you forgot to say that in video
henilraj Sep 1, 2020
I get error in line 47 image wali ma
Morewin81 May 24, 2020
Harry Bhai please help me My Macbook Pro can not detect sound Traceback (most recent call last): File "/Users/vishalsharda/Desktop/Coding Folder/Flappy Bird/Flappy Bird.py", line 44, in <module> GAME_SOUNDS['die'] = pygame.mixer.Sound("Gallery/Audio/die.mp3") pygame.error: Unable to open file 'Gallery/Audio/die.mp3' I need help ASAP
anshul1012 May 16, 2020
Harry Sir, I have first time seen these projects. I like the Jarvis AI the most......

Resources

No resource files associated with this project

Course Announcements

Any Course related announcements will be posted here