5.5 플래피버드와 파이프의 충돌 구현하기
TITLE = 'Flappy Bird'
WIDTH = 400
HEIGHT = 708
GRAVITY = 0.3
drop_speed = 0
GAP = 140
PIPE_SPEED = -3
bird_alive = True
# Actor 객체들
flappy_bird = Actor('bird1', (75, 350))
top_pipe = Actor('top', (350,0))
bottom_pipe = Actor('bottom', (350, top_pipe.height + GAP))
def draw():
screen.blit('background', (0, 0))
flappy_bird.draw()
top_pipe.draw()
bottom_pipe.draw()
def update():
global drop_speed, bird_alive
drop_speed += GRAVITY
flappy_bird.y += drop_speed
top_pipe.x += PIPE_SPEED
bottom_pipe.x += PIPE_SPEED
# 파이프의 무한순환
if top_pipe.right < 0 or bottom_pipe.right < 0:
top_pipe.x = WIDTH
bottom_pipe.x = WIDTH
# 파이프와의 충돌
if flappy_bird.colliderect(top_pipe) or flappy_bird.colliderect(bottom_pipe):
flappy_bird.image = "birddead"
bird_alive = False
def on_mouse_down():
global drop_speed
if bird_alive == True:
drop_speed = -6.5Last updated
