catgame / app.py
arxivgpt kim
Update app.py
811a908 verified
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()