Python
69 ~35 dk

Oyun Geliştirme (Pygame) - 2

Top Yakalama Oyunu

import pygame, random, sys

pygame.init()
W, H = 800, 600
ekran = pygame.display.set_mode((W, H))
font = pygame.font.Font(None, 36)
saat = pygame.time.Clock()

# Oyuncu
oyuncu = pygame.Rect(W//2-40, H-60, 80, 20)
puan = 0

# Top
top = pygame.Rect(random.randint(0, W-20), 0, 20, 20)
top_hiz = 3

while True:
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            pygame.quit(); sys.exit()
    
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT] and oyuncu.x > 0: oyuncu.x -= 7
    if keys[pygame.K_RIGHT] and oyuncu.x < W-80: oyuncu.x += 7
    
    top.y += top_hiz
    
    if top.colliderect(oyuncu):
        puan += 1
        top_hiz += 0.2
        top.x = random.randint(0, W-20)
        top.y = 0
    
    if top.y > H:
        top.x = random.randint(0, W-20)
        top.y = 0
    
    ekran.fill((20, 20, 40))
    pygame.draw.rect(ekran, (0, 200, 100), oyuncu)
    pygame.draw.circle(ekran, (255, 80, 80), top.center, 10)
    ekran.blit(font.render(f"Puan: {puan}", True, (255,255,255)), (10, 10))
    pygame.display.flip()
    saat.tick(60)

🎯 Alıştırmalar

  1. Yılan oyunu (Snake) geliştirin
  2. Uzay gemisi oyunu (düşmanlardan kaçma)

Yorumlar 0

Giriş yapın — Yorumlarınız hemen yayınlansın
Henüz yorum yapılmamış. İlk yorumu siz yapın!