Flying Bird Game Using Python Project on Flying Bird Using Python Submitted by : Akhil 237R1A6704 Sravan 237R1A6712 Venkatesh 237R1A6740 SaiGanesh 237R1A6763 DATA STRUCTURE MINI PROJECT
Introduction Flappy Bird is an arcade based mobile game developed by Dong Nyugen in 2013 May. It was released in May 2013 but got sudden rise in popularity in 2014. It was designed for iOS at first but was adapted as android game also due to rise in popularity.
Objective(s): To apply Computer Graphics to get familiar with drawing pixels, image processing, etc. To re-create the popular arcade game “Flappy Bird” using pygame module .
Algorithm: Step 1: Start Step 2: Run the main Loop Step 3: Run the game If loaded: Draw Bird Draw Background Draw Pipes
Cont... Step 4: While running: If Collision Detected: Go to Step 6 Else: Go to Step 3 Step 5: While paused: Display Score If resumed: Go to step 3 Step 6: EXIT
Flowchart of Flappy Bird
Working Principle Flappy Bird is a side-scroller game meaning that it works on left to right order. The player controls the bird by pressing space bar. Random height vertical pipes are generated from top and bottom of the screen with little gap in between. The player needs to control the bird such that it won’t collide with the vertical pipes. The bird falls at a given acceleration if space bar is not pressed.
CODE: import time import random import os # Function to clear the screen def clear_screen (): os.system (' cls ' if os.name == ' nt ' else 'clear') # Function to print the game interface def print_game ( bird_pos , pipe_gap ): print('\n' * ( bird_pos - 1)) print(' ' * 20 + '@' + ' ' * 10) print('_' * 30) print(' ' * 25 + '|' * pipe_gap ) print('_' * 30) print('\n' * (10 - bird_pos )) # Function to move the bird up def move_bird ( bird_pos ): return bird_pos - 1
CONT… # Function to move the pipes def move_pipes ( pipe_gap ): pipe_gap -= 1 if pipe_gap < 0: pipe_gap = 30 return pipe_gap # Function to check collision def check_collision ( bird_pos , pipe_gap ): if bird_pos == 1 or bird_pos == 10: return True if pipe_gap > 20 and bird_pos < 6: return True if pipe_gap <= 20 and bird_pos > 5: return True return False # Main function def main(): bird_pos = 5 pipe_gap = 30 score = 0 game_over = False while not game_over : clear_screen () print_game ( bird_pos , pipe_gap ) command = input("Press 'Enter' to flap or 'Q' to quit: ").lower() if command == 'q': game_over = True continue bird_pos = move_bird ( bird_pos ) pipe_gap = move_pipes ( pipe_gap ) score += 1 game_over = check_collision ( bird_pos , pipe_gap ) print("Game Over!") print("Your score:", score) if __name__ == "__main__": main()
Future plans The current version of our project is offline, we are planning to make it online. We are planning to add the global leader boards functionality so that players can compete online.
Conclusion Flappy Bird can be created using any programming language. We chose the Python language, pygame module because it is easy to use and is easy to implement game logic in pygame. Our project is 2D game, as pygame is specifically made for 2D games it was easy for us to create flappy bird with its user-friendly modules and methods.