Skip to content

Commit

Permalink
Merge pull request tarunsinghofficial#683 from SanskarGupta007/patch-6
Browse files Browse the repository at this point in the history
Flappy Game
  • Loading branch information
tarunsinghofficial committed Oct 22, 2020
2 parents 58d1026 + c474c22 commit b6d6260
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Flappy Game
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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)
hideturtle()
up()
tracer(False)
onscreenclick(tap)
move()
done()

0 comments on commit b6d6260

Please sign in to comment.