0% found this document useful (0 votes)
16 views3 pages

Daire 4

Uploaded by

karsu22222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Daire 4

Uploaded by

karsu22222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

# -*- coding:utf-8 -*-

import pygame
import random
import math

# Ekran boyutlar
SCREEN_WIDTH = 1980
SCREEN_HEIGHT = 1080

# Renkler
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)

# Oyun ayarlar
PLAYER_SIZE = 40
PLAYER_SPEED = 6
BALLOON_COUNT = 220
BALLOON_RADIUS = 15
BALLOON_SPEED = 3
COLOR_CHANGE_INTERVAL = 3000 # 5 saniyede bir renk demi

pygame.init()

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))


pygame.display.set_caption('Balloon Collector')

clock = pygame.time.Clock()

# Oyuncu ve baloncuklar
player_x = SCREEN_WIDTH // 2
player_y = SCREEN_HEIGHT // 2
player_radius = PLAYER_SIZE // 2

balloons = []
for _ in range(BALLOON_COUNT):
bx = random.randint(0, SCREEN_WIDTH)
by = random.randint(0, SCREEN_HEIGHT)
balloons.append([bx, by, random.randint(-1, 1), random.randint(-1, 1), RED]) #
[x, y, x_direction, y_direction, color]

def draw_game():
screen.fill(WHITE)
pygame.draw.circle(screen, BLUE, (player_x, player_y), player_radius)

for balloon in balloons:


pygame.draw.circle(screen, balloon[4], (balloon[0], balloon[1]),
BALLOON_RADIUS)

pygame.display.flip()

def main():
global player_x, player_y, player_radius # Global olarak tanoruz

last_color_change_time = pygame.time.get_ticks()

running = True
while running:
current_time = pygame.time.get_ticks()
if current_time - last_color_change_time >= COLOR_CHANGE_INTERVAL:
for balloon in balloons:
if balloon[4] == RED:
balloon[4] = BLACK
else:
balloon[4] = RED
last_color_change_time = current_time

for event in pygame.event.get():


if event.type == pygame.QUIT:
running = False

keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
player_x -= PLAYER_SPEED
if keys[pygame.K_RIGHT]:
player_x += PLAYER_SPEED
if keys[pygame.K_UP]:
player_y -= PLAYER_SPEED
if keys[pygame.K_DOWN]:
player_y += PLAYER_SPEED

# Oyuncunun boyutunu baloncuklar toplayaraktme


for balloon in balloons[:]: # [:] kullanarak kopyasruz
bx, by, dx, dy, color = balloon
distance = math.sqrt((bx - player_x) ** 2 + (by - player_y) ** 2)
if distance < player_radius + BALLOON_RADIUS:
if color == BLACK:
running = False # Oyunu bitir
balloons.remove(balloon)
player_radius += 3

# Balonun hareketi
bx += dx * BALLOON_SPEED
by += dy * BALLOON_SPEED

# Duvar
if bx < 0:
bx = 0
dx = random.randint(0, 1) # Yir
elif bx > SCREEN_WIDTH:
bx = SCREEN_WIDTH
dx = random.randint(-1, 0) # Ytir

if by < 0:
by = 0
dy = random.randint(0, 1) # Yir
elif by > SCREEN_HEIGHT:
by = SCREEN_HEIGHT
dy = random.randint(-1, 0) # Yir

balloon[0] = bx
balloon[1] = by
balloon[2] = dx
balloon[3] = dy

draw_game()
clock.tick(60)
pygame.quit()

if __name__ == '__main__':
main()

You might also like