flappy.py

Created by gaetan-etienne35

Created on September 22, 2025

1.51 KB


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

# Paramètres du jeu
bird_y = 100
bird_v = 0
gravity = 2
jump = -6
score = 0

pipes = []
pipe_gap = 35
pipe_speed = 3
pipe_interval = 50
frame = 0

def draw_bird(y):
    fill_rect(20, y, 8, 8, (255, 255, 0))

def draw_pipes(pipes):
    for x, h in pipes:
        fill_rect(x, 0, 20, h, (0, 200, 0))
        fill_rect(x, h + pipe_gap, 20, 240, (0, 200, 0))

while True:
    # Efface écran
    fill_rect(0, 0, 320, 240, (135, 206, 235))

    # Gestion du saut
    if keydown(KEY_UP):
        bird_v = jump

    # Applique gravité
    bird_v += gravity
    bird_y += bird_v

    # Gère tuyaux
    if frame % pipe_interval == 0:
        h = randint(30, 150)
        pipes.append([320, h])

    new_pipes = []
    for x, h in pipes:
        x -= pipe_speed
        if x + 20 > 0:
            new_pipes.append([x, h])
            if x == 20:
                score += 1
    pipes = new_pipes

    # Dessin
    draw_bird(bird_y)
    draw_pipes(pipes)
    draw_string("Score: " + str(score), 5, 5, (0,0,0), (255,255,255))

    # Collision
    for x, h in pipes:
        if 20+8 > x and 20 < x+20:
            if bird_y < h or bird_y+8 > h+pipe_gap:
                draw_string("GAME OVER", 110, 120, (255,0,0), (255,255,255))
                sleep(2)
                quit()
    if bird_y < 0 or bird_y+8 > 240:
        draw_string("GAME OVER", 110, 120, (255,0,0), (255,255,255))
        sleep(2)
        quit()

    sleep(0.05)
    frame += 1

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.