import pygame
import random
pygame.init()

width, height = 450, 768
ecran = pygame.display.set_mode((width, height))
pygame.display.set_caption("FLAPPY BIRD")

pixel_font = pygame.font.Font("PixelifySans-VariableFont_wght.ttf", 36)
text_surface = pixel_font.render("YOU LOSE", False, (255, 0, 0))
replay_button_rect = pygame.Rect(125, 450, 200, 50)
button_font = pygame.font.Font("PixelifySans-VariableFont_wght.ttf", 20)
button_text = button_font.render("REPLAY", False, (255, 255, 255))

fond = pygame.transform.scale(pygame.image.load("true sky.png").convert(), (width, height))
image_tuyau_haut = pygame.image.load("block90.png").convert_alpha()
image_tuyau_bas = pygame.image.load("block-90.png").convert_alpha()
bird = pygame.transform.scale(pygame.image.load("flappybird.png").convert_alpha(), (40, 40))
bird_rect = bird.get_rect(topleft=(60, 300))

horloge = pygame.time.Clock()
velocity_y, gravity, LARGEUR_TUYAU, ecart = 0, 0.4, 123, 180
rungame, game_over = True, False
score = 0
passe_tuyau = False

def generer_tuyaux():
    trou = random.randint(100, 500)
    th = pygame.transform.scale(image_tuyau_haut, (LARGEUR_TUYAU, trou))
    tb = pygame.transform.scale(image_tuyau_bas, (LARGEUR_TUYAU, height - (trou + ecart)))
    return th, th.get_rect(topleft=(400, 0)), tb, tb.get_rect(topleft=(400, trou + ecart))

block90, block90_rect, blockb90, blockb90_rect = generer_tuyaux()

while rungame:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            rungame = False
        if event.type == pygame.MOUSEBUTTONDOWN and game_over:
            if event.button == 1 and replay_button_rect.collidepoint(event.pos):
                game_over, velocity_y, score, passe_tuyau = False, 0, 0, False
                bird_rect.topleft = (60, 300)
                block90, block90_rect, blockb90, blockb90_rect = generer_tuyaux()

    if not game_over:
        if pygame.key.get_pressed()[pygame.K_UP]:
            velocity_y = -7
        velocity_y += gravity
        bird_rect.y += int(velocity_y)
        bird_rect.y = max(bird_rect.y, 0)
        block90_rect.x -= 5
        blockb90_rect.x -= 5

        if block90_rect.left < bird_rect.x and not passe_tuyau:
            score += 1
            passe_tuyau = True

        if block90_rect.right < 0:
            block90, block90_rect, blockb90, blockb90_rect = generer_tuyaux()
            passe_tuyau = False

        if bird_rect.y > height or bird_rect.colliderect(block90_rect) or bird_rect.colliderect(blockb90_rect):
            game_over = True

    ecran.blit(fond, (0, 0))
    ecran.blit(block90, block90_rect)
    ecran.blit(blockb90, blockb90_rect)
    ecran.blit(bird, bird_rect)
    
    score_surf = pixel_font.render(str(score), False, (255, 255, 255))
    ecran.blit(score_surf, (width // 2 - score_surf.get_width() // 2, 50))

    if game_over:
        ecran.blit(text_surface, (width // 2 - text_surface.get_width() // 2, 300))
        pygame.draw.rect(ecran, (100, 100, 100), replay_button_rect, border_radius=5)
        pygame.draw.rect(ecran, (255, 255, 255), replay_button_rect, 3, border_radius=5)
        ecran.blit(button_text, (replay_button_rect.x + 55, replay_button_rect.y + 12))

    pygame.display.flip()
    horloge.tick(60)
pygame.quit()

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: