flappybird.py

Created by 4223

Created on August 28, 2025

1.84 KB

flappy


from kandinsky import *
from ion import *
from time import sleep
from random import randint

# Schermgrootte
WIDTH, HEIGHT = 320, 222

# Kleuren
WHITE = color(255,255,255)
BLACK = color(0,0,0)
GREEN = color(0,255,0)
RED = color(255,0,0)

# Vogel
bird_x = 50
bird_y = 100
bird_speed = 0
gravity = 1
jump = -8

# Pijpen
pipe_width = 40
pipe_gap = 60
pipes = []
pipe_speed = 3

# Score
score = 0

# Start
for i in range(3):
    x = WIDTH + i*120
    gap_y = randint(40, HEIGHT-40-pipe_gap)
    pipes.append([x, gap_y])

def draw_bird():
    fill_rect(bird_x, bird_y, 10, 10, RED)

def draw_pipes():
    for x,gap_y in pipes:
        fill_rect(x,0,pipe_width,gap_y,GREEN)
        fill_rect(x,gap_y+pipe_gap,pipe_width,HEIGHT-(gap_y+pipe_gap),GREEN)

def game_over():
    fill_rect(0,0,WIDTH,HEIGHT,BLACK)
    draw_string("GAME OVER",100,100,WHITE,BLACK)
    draw_string("Score: "+str(score),110,130,WHITE,BLACK)

while True:
    # Besturing
    if keydown(KEY_OK) or keydown(KEY_UP):
        bird_speed = jump

    # Beweging vogel
    bird_speed += gravity
    bird_y += bird_speed

    # Botsing met boven/onder
    if bird_y < 0 or bird_y > HEIGHT-10:
        game_over()
        break

    # Beweging pijpen
    for p in pipes:
        p[0] -= pipe_speed

    # Nieuwe pijp toevoegen
    if pipes[0][0] < -pipe_width:
        pipes.pop(0)
        x = pipes[-1][0] + 120
        gap_y = randint(40, HEIGHT-40-pipe_gap)
        pipes.append([x, gap_y])
        score += 1

    # Botsing met pijpen
    for x,gap_y in pipes:
        if bird_x+10 > x and bird_x < x+pipe_width:
            if bird_y < gap_y or bird_y+10 > gap_y+pipe_gap:
                game_over()
                quit()

    # Tekenen
    fill_rect(0,0,WIDTH,HEIGHT,BLACK)
    draw_bird()
    draw_pipes()
    draw_string("Score: "+str(score),5,5,WHITE,BLACK)

    sleep(0.05)
# Type your text here

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.