Flappy Bird tarzında bir oyun oluşturabilirsiniz ve her seviyeyi geçtiğinizde renklerin değişmesi için Python'un pygame kütüphanesini kullanabilirsiniz. Aşağıda basit bir örnek kod bulacaksınız. Bu kod, her seviyeyi geçtiğinizde arka plan rengini değiştirecek şekilde ayarlanmıştır:
import pygame
import sys
import random
# Pygame'i başlat
pygame.init()
# Renkler
COLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255)]
# Ekran boyutları
SCREEN_WIDTH, SCREEN_HEIGHT = 400, 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Saat
clock = pygame.time.Clock()
# Kuş özellikleri
bird_x, bird_y = 50, SCREEN_HEIGHT // 2
bird_speed = 0
gravity = 0.5
# Boru özellikleri
pipe_width = 70
pipe_gap = 150
pipe_speed = 3
pipes = []
# Oyun rengi
current_color_index = 0
def draw_bird():
pygame.draw.circle(screen, (255, 255, 255), (bird_x, int(bird_y)), 15)
def draw_pipes():
for pipe in pipes:
pygame.draw.rect(screen, (255, 255, 255), pipe)
def update_pipes():
global current_color_index
for pipe in pipes:
pipe.x -= pipe_speed
if len(pipes) > 0 and pipes[0].x < -pipe_width:
pipes.pop(0)
# Renk değiştirme koşulu
if len(pipes) > 0 and pipes[-1].x < SCREEN_WIDTH - 400:
new_pipe_height = random.randint(50, SCREEN_HEIGHT - pipe_gap - 50)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, pipe_width, new_pipe_height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, new_pipe_height + pipe_gap, pipe_width, SCREEN_HEIGHT - new_pipe_height - pipe_gap)
pipes.append(top_pipe)
pipes.append(bottom_pipe)
# Renk değiştirme
current_color_index = (current_color_index + 1) % len(COLORS)
# Başlangıçtaki ilk boruları ekle
update_pipes()
def check_collision():
bird_rect = pygame.Rect(bird_x - 15, bird_y - 15, 30, 30)
for pipe in pipes:
if bird_rect.colliderect(pipe):
return True
return False
# Oyun döngüsü
running = True
while running:
screen.fill(COLORS[current_color_index])
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bird_speed = -10
bird_speed += gravity
bird_y += bird_speed
if bird_y > SCREEN_HEIGHT:
bird_y = SCREEN_HEIGHT
bird_speed = 0
draw_bird()
draw_pipes()
update_pipes()
if check_collision():
running = False
pygame.display.flip()
clock.tick(30)
pygame.quit()
sys.exit()
Bu basit örnek, bir Flappy Bird oyununu temel alıyor ve her seviyeyi geçtiğinizde arka plan rengini değiştiriyor. Renkler COLORS listesinden sırayla seçiliyor. Borular, ekranın dışına çıktıklarında yeni borular oluşturuluyor ve belirli bir mesafeye gelince arka plan rengi değişiyor. Başlatmak için Python'un pygame kütüphanesinin yüklü olduğundan emin olun (pip install pygame).