File size: 1,725 Bytes
a2888c8
 
 
 
811a908
 
 
 
a2888c8
 
 
 
 
811a908
a2888c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
811a908
a2888c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1eebdd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pygame
import random
import sys

# ์˜ค๋””์˜ค ๋ชจ๋“ˆ ๋น„ํ™œ์„ฑํ™”
pygame.mixer.quit()

# pygame ์ดˆ๊ธฐํ™”
pygame.init()

# ๊ฒŒ์ž„ ํ™”๋ฉด ์„ค์ •
screen_width, screen_height = 800, 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Cat Ball Game")

# ์ƒ‰์ƒ ์„ค์ •
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]

# ๊ณต ์„ค์ •
balls = []
for _ in range(3):
    x = random.randint(20, screen_width - 20)
    y = random.randint(20, screen_height - 20)
    vx, vy = random.choice([-5, -4, -3, 3, 4, 5]), random.choice([-5, -4, -3, 3, 4, 5])
    color = random.choice(colors)
    balls.append([x, y, vx, vy, color])

clock = pygame.time.Clock()

def draw_balls():
    for ball in balls:
        pygame.draw.circle(screen, ball[4], (ball[0], ball[1]), 20)

def move_balls():
    for ball in balls:
        ball[0] += ball[2]
        ball[1] += ball[3]
        if ball[0] <= 20 or ball[0] >= screen_width - 20:
            ball[2] = -ball[2]
        if ball[1] <= 20 or ball[1] >= screen_height - 20:
            ball[3] = -ball[3]

def remove_ball(pos):
    for ball in balls:
        distance = ((ball[0] - pos[0]) ** 2 + (ball[1] - pos[1]) ** 2) ** 0.5
        if distance < 20:
            balls.remove(ball)
            break  # ๊ณต์ด ์ œ๊ฑฐ๋œ ํ›„ ์ƒˆ ๊ณต์„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์Œ

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            remove_ball(pygame.mouse.get_pos())

    screen.fill((255,255,255))
    draw_balls()
    move_balls()
    pygame.display.flip()
    clock.tick(60)  # FPS๋ฅผ 60์œผ๋กœ ์„ค์ •

pygame.quit()
sys.exit()