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()