@websec007
2020-06-22T13:54:06.000000Z
字数 707
阅读 927
2020.Python从入门到实践
边缘检测:if alien.rect.bottom >= screen_rect.bottom
像飞船被撞击一样处理:ship_hit()
def check_aliens_bottom(game_settings, stats, screen, ship, aliens, bullets):
"""检查是否有外星人到达了屏幕底端"""
screen_rect = screen.get_rect()
for alien in aliens.sprites():
if alien.rect.bottom >= screen_rect.bottom:
# 像飞船被撞到一样进行处理
ship_hit(stats, aliens, bullets, screen, game_settings, ship)
break
++++++++++++++++++++update_aliens()++++++++++++++++++++++
def update_aliens(ai_settings, stats, screen, ship, aliens, bullets):
--snip--
# 检查是否有外星人到达屏幕底端
check_aliens_bottom(ai_settings, stats, screen, ship, aliens, bullets)
此处省略...