forked from hhhrrrttt222111/PyBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlappy.txt
More file actions
84 lines (62 loc) · 1.46 KB
/
Flappy.txt
File metadata and controls
84 lines (62 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This game is from the official documentation of freegames
# https://pypi.org/project/freegames/
# pip install freegames
# Click on screen to control ball
# import modules
from random import *
import turtle as t
from freegames import vector
# Set window title, color and icon
t.title("Flappy Ball")
root = t.Screen()._root
root.iconbitmap("logo-ico.ico")
t.bgcolor('#80ffd4')
bird = vector(0, 0)
balls = []
# Functions
# Move bird up in response to screen tap
def tap(x, y):
up = vector(0, 30)
bird.move(up)
# Return True if point on screen
def inside(point):
return -200 < point.x < 200 and -200 < point.y < 200
# Draw screen objects
def draw(alive):
t.clear()
t.goto(bird.x, bird.y)
if alive:
t.dot(13, 'green')
else:
t.dot(13, 'red')
for ball in balls:
t.goto(ball.x, ball.y)
t.dot(20, '#862d2d')
t.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)
t.ontimer(move, 50)
t.setup(420, 420, 370, 0)
t.hideturtle()
t.up()
t.tracer(False)
t.onscreenclick(tap)
move()
t.done()