repl.it
@jajoosam/

flappy bird

Pygame

with python play!

fork
loading
Files
  • main.py
  • nohup.out
  • Packager files
  • requirements.txt
main.py
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
import play

bird = play.new_circle(
    color='yellow',
    x=play.screen.left + 100,
    y=play.screen.top - 40,
    radius=30,
)

# adding gravity and lotsa other physics to our bird
bird.start_physics(bounciness=0.4)

boxes = []


@play.repeat_forever
def do():
    if play.key_is_pressed('up', 'w'):
        # if the up key is pressed, make the bird jump
        bird.y += 7.5

    for box in boxes:

        # if the box is out of the screen, lets delete it
        if (box.x < (play.screen.left - 50)):
            boxes.remove(box)
            box.remove()

        # detect if the bird is touching any box
        if bird.is_touching(box):
            box.color = "red"

        # make the box move to the left
        box.x -= 1


@play.repeat_forever
async def block():
    # height of the top block
    top = play.random_number(lowest=300, highest=500)
    # height of the bottom block
    bottom = play.random_number(lowest=300, highest=500)

    # creating the top box of width 100, emerging from behind the current screen
    boxes.append(
        play.new_box(
            color="blue",
            y=play.screen.top,
            x=play.screen.right + 50,
            width=50,
            height=top))
    # creating the bottom box of width 100, emerging from behind the current screen
    boxes.append(
        play.new_box(
            color="blue",
            y=play.screen.bottom,
            x=play.screen.right + 50,
            width=50,
            height=bottom))

    # creating the next box after a random duration between 2 and 5 seconds
    await play.timer(seconds=play.random_number(1.0, 4.0))


play.start_program()