kodlama bilmeden yapay zeka ile tasarladığım basit bir oyun sizler ile paylaşmak istedim
top_oyunu.py
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GRAY = (50, 50, 50)
BLUE = (0, 0, 255)
# Ball dimensions
BALL_SIZE = 20
# Paddle dimensions
PADDLE_WIDTH = 100
PADDLE_HEIGHT = 20
# Create screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Top Oyunu")
# Hide mouse cursor
pygame.mouse.set_visible(False)
# Ball class
class Ball:
def __init__(self):
self.x = random.randint(0, SCREEN_WIDTH - BALL_SIZE)
self.y = random.randint(0, SCREEN_HEIGHT // 2)
self.dx = 5
self.dy = 5
def move(self):
self.x += self.dx
self.y += self.dy
if self.x <= 0 or self.x >= SCREEN_WIDTH - BALL_SIZE:
self.dx = -self.dx
if self.y <= 0:
self.dy = -self.dy
def draw(self):
# Draw shadow
pygame.draw.ellipse(screen, GRAY, [self.x + 5, self.y + 5, BALL_SIZE, BALL_SIZE])
# Draw ball
pygame.draw.ellipse(screen, RED, [self.x, self.y, BALL_SIZE, BALL_SIZE])
# Paddle class
class Paddle:
def __init__(self):
self.x = (SCREEN_WIDTH - PADDLE_WIDTH) // 2
self.y = SCREEN_HEIGHT - PADDLE_HEIGHT - 60 # 50 piksel yukarıya aldık
self.dx = 10
def move_left(self):
self.x -= self.dx
if self.x < 0:
self.x = 0
def move_right(self):
self.x += self.dx
if self.x > SCREEN_WIDTH - PADDLE_WIDTH:
self.x = SCREEN_WIDTH - PADDLE_WIDTH
def draw(self):
# Draw shadow
pygame.draw.rect(screen, GRAY, [self.x + 5, self.y + 5, PADDLE_WIDTH, PADDLE_HEIGHT])
# Draw paddle
pygame.draw.rect(screen, BLUE, [self.x, self.y, PADDLE_WIDTH, PADDLE_HEIGHT])
def game_over():
font = pygame.font.Font(None, 74)
text = font.render("Oyun Bitti", True, RED)
screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2))
pygame.display.flip()
pygame.time.wait(2000)
def pause_menu():
while True:
screen.fill(BLACK)
font = pygame.font.Font(None, 74)
text = font.render("Devam Etmek İster misiniz?", True, WHITE)
screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2 - 50))
font = pygame.font.Font(None, 36)
text_continue = font.render("Devam (D)", True, WHITE)
text_quit = font.render("Çık (Q)", True, WHITE)
screen.blit(text_continue, (SCREEN_WIDTH // 2 - text_continue.get_width() // 2, SCREEN_HEIGHT // 2 - text_continue.get_height() // 2 + 50))
screen.blit(text_quit, (SCREEN_WIDTH // 2 - text_quit.get_width() // 2, SCREEN_HEIGHT // 2 - text_quit.get_height() // 2 + 100))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_d:
return True
if event.key == pygame.K_q:
return False
def main_menu():
# Load the Pardus logo image
pardus_logo = pygame.image.load("pardus_logo.png")
pardus_logo = pygame.transform.scale(pardus_logo, (100, 100)) # Resize if necessary
while True:
screen.fill(BLACK)
font = pygame.font.Font(None, 74)
text = font.render("Ne yapmak istersiniz?", True, WHITE)
screen.blit(text, (SCREEN_WIDTH // 2 - text.get_width() // 2, SCREEN_HEIGHT // 2 - text.get_height() // 2 - 50))
font = pygame.font.Font(None, 36)
text_start = font.render("Başlat (E)", True, WHITE)
text_quit = font.render("Çık (Q)", True, WHITE)
screen.blit(text_start, (SCREEN_WIDTH // 2 - text_start.get_width() // 2, SCREEN_HEIGHT // 2 - text_start.get_height() // 2 + 50))
screen.blit(text_quit, (SCREEN_WIDTH // 2 - text_quit.get_width() // 2, SCREEN_HEIGHT // 2 - text_quit.get_height() // 2 + 100))
# Display the Pardus logo at the top right corner
screen.blit(pardus_logo, (SCREEN_WIDTH - pardus_logo.get_width() - 10, 10))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
return True
if event.key == pygame.K_q:
pygame.quit()
sys.exit()
def main():
while True:
if not main_menu():
break
ball = Ball()
paddle = Paddle()
running = True
paused = False
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused = True
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
paddle.move_left()
if keys[pygame.K_d]:
paddle.move_right()
if not paused:
ball.move()
if ball.y >= SCREEN_HEIGHT - BALL_SIZE:
if paddle.x <= ball.x <= paddle.x + PADDLE_WIDTH:
ball.dy = -ball.dy
else:
game_over()
running = False
# Topun sütuna değdiğinde geri sekmesi
if paddle.y <= ball.y + BALL_SIZE <= paddle.y + PADDLE_HEIGHT:
if paddle.x <= ball.x <= paddle.x + PADDLE_WIDTH:
ball.dy = -ball.dy
ball.y = paddle.y - BALL_SIZE # Topun paddle'ın üstünde kalmasını sağla
# Sütunun alt izdüşümüne gelen top olursa oyun bitmesi
if ball.y >= SCREEN_HEIGHT - BALL_SIZE:
game_over()
running = False
screen.fill(BLACK)
ball.draw()
paddle.draw()
pygame.display.flip()
pygame.time.Clock().tick(60)
if paused:
if not pause_menu():
pygame.quit()
sys.exit()
paused = False
if __name__ == "__main__":
main()