两个运动图像之间的碰撞

时间:2019-05-02 20:16:04

标签: python pygame

我正在尝试使其在两个图像相互碰撞时退出。我希望在没有课程的情况下做到这一点,因为我仍然对它们的工作方式感到困惑。

下面我同时具有它们和主循环的功能

def Good(type, x,y):
    screen.blit(type,(x,y))

def boulder(x,y):
    screen.blit(rock,(x,y))

def main_loop():
    good_y = 500
    good_x = 336
    change = 0
    boulder_y = 0
    boulder_x = random.randint(64, 736)


    done = False


    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    change = -10
                if event.key == pygame.K_d:
                    change = 10
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_a or event.key == pygame.K_d:
                    change = 0
        good_x += change
        screen.fill(white)
        Good(neutral,good_x,good_y)
        boulder(boulder_x,boulder_y)
        pygame.display.update()
        clock.tick(60)


        if good_x > w - sprite_size or good_x < 0:
            done = True
        boulder_y = boulder_y + boulder_fall
        if boulder_y > h:
            boulder_x = random.randint(64, 736)
            boulder_y = 0

0 个答案:

没有答案