6.2 배우들의 움직임 구현하기
TITLE = 'Breakout'
WIDTH = 800
HEIGHT = 600
GAP_FROM_SCREEN = 50
ball = Actor('ball', (WIDTH / 2, HEIGHT / 2))
bar = Actor('bar', (WIDTH / 2, HEIGHT - GAP_FROM_SCREEN))
# 4행*8열짜리 블록더미 만들기
blocks = []
for block_row in range(4):
for block_col in range(8):
block = Actor(
'block',
(block_col * 100, block_row * 32 + GAP_FROM_SCREEN),
anchor=('left', 'top')
)
blocks.append(block)
def draw():
screen.blit('space', (0, 0))
ball.draw()
bar.draw()
for block in blocks:
block.draw()
def update():
# 반사판의 이동을 화면 안에 안에 가두기
if bar.left < 0:
bar.left = 0
if bar.right > WIDTH:
bar.right = WIDTH
def on_mouse_move(pos):
x, y = pos
bar.centerx = xLast updated