如何使这个对象与屏幕底部碰撞? (pygame的)

时间:2017-07-23 03:27:40

标签: pygame collision-detection

如何让此物体与屏幕底部碰撞?

def update(self):
    """Atualiza a posição do foguete de acordo com a flag"""
    # Atualiza o valor  centro da espaçonave, e não o retângolo

    if self.moving_right and self.rect.right < self.screen_rect.right:
        self.centerx += self.ai_settings.foguete_speed_factor

    if self.moving_left and self.rect.left > 0:
        self.centerx -= self.ai_settings.foguete_speed_factor

    if self.moving_top and self.rect.top > 0:
        self.centery -= self.ai_settings.foguete_speed_factor

    if self.moving_bottom:
        self.centery += self.ai_settings.foguete_speed_factor

enter image description

1 个答案:

答案 0 :(得分:1)

如果你想在火箭没有碰到屏幕底部时继续向下移动,那么:

if self.moving_bottom and self.rect.bottom < self.screen_rect.bottom:
    self.centery += self.ai_settings.foguete_speed_factor