File size: 2,161 Bytes
2376690
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import pygame
import random

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

# ํ™”๋ฉด ์„ค์ •
width = 800
height = 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("๋ธ”๋ก ๊ฒŒ์ž„")

# ์ƒ‰์ƒ
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)

# ๋ธ”๋ก ์„ค์ •
block_width = 50
block_height = 20
block_rows = 5
block_cols = 10

# ํŒจ๋“ค ์„ค์ •
paddle_width = 100
paddle_height = 10
paddle_x = width // 2 - paddle_width // 2
paddle_y = height - 40

# ๊ณต ์„ค์ •
ball_radius = 10
ball_x = width // 2
ball_y = height // 2
ball_dx = 3
ball_dy = -3

# ๋ธ”๋ก ์ƒ์„ฑ
blocks = []
for row in range(block_rows):
    for col in range(block_cols):
        block = pygame.Rect(col * (block_width + 5) + 50, 
                            row * (block_height + 5) + 50, 
                            block_width, block_height)
        blocks.append(block)

# ๊ฒŒ์ž„ ๋ฃจํ”„
running = True
clock = pygame.time.Clock()

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

    # ํŒจ๋“ค ์ด๋™
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT] and paddle_x > 0:
        paddle_x -= 5
    if keys[pygame.K_RIGHT] and paddle_x < width - paddle_width:
        paddle_x += 5

    # ๊ณต ์ด๋™
    ball_x += ball_dx
    ball_y += ball_dy

    # ๋ฒฝ ์ถฉ๋Œ ๊ฒ€์‚ฌ
    if ball_x <= 0 or ball_x >= width:
        ball_dx *= -1
    if ball_y <= 0:
        ball_dy *= -1
    if ball_y >= height:
        running = False

    # ํŒจ๋“ค ์ถฉ๋Œ ๊ฒ€์‚ฌ
    if ball_y + ball_radius >= paddle_y and ball_x >= paddle_x and ball_x <= paddle_x + paddle_width:
        ball_dy *= -1

    # ๋ธ”๋ก ์ถฉ๋Œ ๊ฒ€์‚ฌ
    for block in blocks[:]:
        if block.collidepoint(ball_x, ball_y):
            blocks.remove(block)
            ball_dy *= -1
            break

    # ํ™”๋ฉด ๊ทธ๋ฆฌ๊ธฐ
    screen.fill(BLACK)
    pygame.draw.rect(screen, WHITE, (paddle_x, paddle_y, paddle_width, paddle_height))
    pygame.draw.circle(screen, WHITE, (int(ball_x), int(ball_y)), ball_radius)
    for block in blocks:
        pygame.draw.rect(screen, RED, block)

    pygame.display.flip()
    clock.tick(60)

pygame.quit()