Flappy bird game using Python

Flappy bird game on Python

Flappy bird is a common and mostly used game by the kids. Most of the people love to play these sort of games. The game is particularly made with Unity or Unreal. You should have a knowledge on designing for the layout of the characters in a game.
The game mostly consists of characters and the obstacles they are facing to clear the step. This kind of games is 2D games which have only got a single background and the continuous random obstacles. We use coding as well as the software to make the games but you don’t need them if you want a simple game.
In this game, I have used a small green circle as a flappy bird and big black circle as an obstacle which the flappy bird has to dough it every time or the game may over.


Like you can see from the above picture that there are lots of random dots and to dough it, you should click on lift mouse button.

Things you need to install to run this project.
  1. Install python 2.7 or python 3
  2. Install python libraries that are random, turtle and freegames.
  3. You can install these libraries by typing sudo pip / pip3 install and the library name.

The codes seem like this:

from random import *
from turtle import *
from freegames import vector
bird = vector(0, 0)
balls = []
def tap(x, y):
 "Move bird up in response to screen tap."
 up = vector(0, 30)
 bird.move(up)
def inside(point):
 "Return True if point on screen."
 return -200 < point.x < 200 and -200 < point.y < 200
def draw(alive):
 "Draw screen objects."
 clear()
goto(bird.x, bird.y)
if alive:
 dot(10, 'green')
 else:
 dot(10, 'red')
for ball in balls:
 goto(ball.x, ball.y)
 dot(20, 'black')
update()
def move():
 "Update object positions."
 bird.y -= 5
for ball in balls:
 ball.x -= 3
if randrange(10) == 0:
 y = randrange(-199, 199)
 ball = vector(199, y)
 balls.append(ball)
while len(balls) > 0 and not inside(balls[0]):
 balls.pop(0)
if not inside(bird):
 draw(False)
 return
for ball in balls:
 if abs(ball - bird) < 15:
 draw(False)
 return
draw(True)
 ontimer(move, 50)
setup(420, 420, 370, 0)
update()
def move():
 "Update object positions."
 bird.y -= 5
for ball in balls:
 ball.x -= 3
if randrange(10) == 0:
 y = randrange(-199, 199)
 ball = vector(199, y)
 balls.append(ball)
while len(balls) > 0 and not inside(balls[0]):
 balls.pop(0)
if not inside(bird):
 draw(False)
 return
for ball in balls:
 if abs(ball - bird) < 15:
 draw(False)
 return
draw(True)
 ontimer(move, 50)
setup(420, 420, 370, 0)
hideturtle()

Click on below button to download this whole project:
Download
Thank you

You may also like...

Leave a Reply

avatar
  Subscribe  
Notify of