提问者:小点点

如何在玩家触摸婴儿时添加碰撞


我有一个游戏,我希望当玩家触摸婴儿时,游戏能增加一分。我知道如何加分数,但我不知道如何让系统理解它们之间的冲突。

这是我的代码的主要部分:

while Level1:
    thing_rect = pygame.Rect(random.randrange(display_width), -60, 40, 40)
    thing_speed = 2
    while lives == 3:
        for event in pygame.event.get():
        if event.type == pygame.QUIT:
            return
        # adds the images and movement        
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                x_Pl = x_Pl - 40
            elif event.key == pygame.K_RIGHT:
                x_Pl = x_Pl + 40
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                x_Pl = x_Pl + 0
    gameDisplay.blit(Level1_Back, (0,0) )
    smallText_2 = pygame.font.Font("LSANS.ttf", 20)
    textSurf, textRect = text_objects("Use the arrow keys to move", smallText_2, black)
    textRect.center = ( (730+(180/2)), (200+(50/2)) )
    gameDisplay.blit(textSurf, textRect)
    gameDisplay.blit(lives_3, (10, 10) )
    gameDisplay.blit(Character_1, (x_Pl, 275))
    thing_rect.y += thing_speed
    if thing_rect.y > display_height:
        thing_rect.y = 0 - thing_rect.height
        thing_rect.x = random.randrange(display_width)

    gameDisplay.blit(Baby_1, thing_rect)
    pygame.display.update()

感谢您的所有帮助。(如果您需要更多代码,请告诉我)


共1个答案

匿名用户

您需要一个类似如下的if语句:if-thing_rectX和thing_rectY