Flappy Bird in 30 Lines with Python | Pygame |#python #programming #coding #pygame #flappybird

preview_player
Показать описание
The Flappy Bird game is written in 30 lines of Python code and uses the Pygame graphics module.

Pygame is an easy-to-use toolkit for presenting graphical information and developing simple games, making it ideal for Python beginners.

To install Pygame, put the following into a terminal and hit Enter: "pip install pygame" (without quotes).
Рекомендации по теме
Комментарии
Автор

Code is below ↓↓↓:

import pygame, sys, random
pygame.init(); size, g, gap = 400, 50, 150
screen = pygame.display.set_mode((size, size)); bird = pygame.Rect(50, size // 2, 30, 30)
bird_speed, gravity, pipe_timer, pipe_interval, pipes, score = 0, 0.5, 0, 100, [], 0; clock, font = pygame.time.Clock(), pygame.font.Font(None, 36)
def draw():
screen.fill((135, 206, 235))
pygame.draw.rect(screen, (255, 255, 0), bird)
for p in pipes: pygame.draw.rect(screen, (0, 255, 0), p)
{score}", True, (255, 255, 255)), (10, 10))
pygame.display.flip()
def update():
global bird_speed, pipe_timer, score
bird_speed += gravity
bird.y = max(0, min(bird.y + bird_speed, size - g))
if (pipe_timer := pipe_timer + 1) > pipe_interval:
pipe_timer, y = 0, random.randint(50, size - g - gap - 50)
pipes.extend([pygame.Rect(size, 0, 50, y), pygame.Rect(size, y + gap, 50, size - g - y - gap)])
score += 1
pipes[:] = [p.move(-5, 0) for p in pipes if p.x > -50]
def check_collision():
return bird.colliderect(pygame.Rect(0, size - g, size, g)) or any(bird.colliderect(p) for p in pipes)
while True:
for e in pygame.event.get():
if e.type == pygame.QUIT: pygame.quit(); sys.exit()
if e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE: bird_speed = -10
update()
if check_collision(): bird, bird_speed, pipes, score = pygame.Rect(50, size // 2, 30, 30), 0, [], 0
draw()
clock.tick(30)

ninjabotics
Автор

Very nice excellent job good congratulations

ArjunSharma-ijqy
Автор

meanwhile me : "hello world"

AryanVij-xm
Автор

bro thought we wouldnt see pong on top. tuff tho

Donavon-cu