- Bağlantıyı al
- X
- E-posta
- Diğer Uygulamalar
İşte basit bir Flappy Bird klonunun Python ile yapılmış örneği. Bu proje için pygame kütüphanesini kullanacağız. Eğer pygame yüklü değilse önce şu komutu çalıştırarak yükleyin:
pip install pygame
oyun.py dosyası oluştur.
import pygame
import random
# Ekran boyutu
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
# Renkler
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
# Başlat
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()
font = pygame.font.SysFont(None, 48)
# Kuş
bird_x = 50
bird_y = 300
bird_radius = 20
bird_velocity = 0
gravity = 0.5
jump_strength = -10
# Borular
pipe_width = 70
pipe_gap = 150
pipe_speed = 3
pipes = []
def create_pipe():
height = random.randint(100, 400)
return {'x': SCREEN_WIDTH, 'height': height}
# Skor
score = 0
# Ana döngü
running = True
pipes.append(create_pipe())
while running:
screen.fill(WHITE)
# Etkinlikler
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_velocity = jump_strength
# Kuş fiziği
bird_velocity += gravity
bird_y += bird_velocity
# Boruları güncelle
for pipe in pipes:
pipe['x'] -= pipe_speed
# Yeni boru oluştur
if pipes[-1]['x'] < SCREEN_WIDTH - 200:
pipes.append(create_pipe())
# Boru çarpışmaları ve skor
for pipe in pipes:
top_rect = pygame.Rect(pipe['x'], 0, pipe_width, pipe['height'])
bottom_rect = pygame.Rect(pipe['x'], pipe['height'] + pipe_gap, pipe_width, SCREEN_HEIGHT)
pygame.draw.rect(screen, GREEN, top_rect)
pygame.draw.rect(screen, GREEN, bottom_rect)
if top_rect.collidepoint(bird_x, bird_y) or bottom_rect.collidepoint(bird_x, bird_y):
running = False
if pipe['x'] + pipe_width < bird_x and not pipe.get('scored'):
score += 1
pipe['scored'] = True
# Ekran dışına çıkarsa
if bird_y > SCREEN_HEIGHT or bird_y < 0:
running = False
# Kuşu çiz
pygame.draw.circle(screen, BLUE, (bird_x, int(bird_y)), bird_radius)
# Skoru yaz
score_text = font.render(str(score), True, (0, 0, 0))
screen.blit(score_text, (SCREEN_WIDTH // 2, 20))
# Ekranı güncelle
pygame.display.flip()
clock.tick(60)
pygame.quit()
- Bağlantıyı al
- X
- E-posta
- Diğer Uygulamalar
Yorumlar
Yorum Gönder