存储项目的大部分函数
This commit is contained in:
parent
50aaffe003
commit
8988705699
|
@ -159,7 +159,7 @@ def check_bullet_collisions(ai_settings, screen, stats, sb, ship, aliens, bossal
|
|||
# 子弹击中BOSS外星人,BOSS外星人失去一定血量
|
||||
for bullet in bullets:
|
||||
if pygame.Rect.colliderect(bullet.rect, bossalien.rect):
|
||||
bossalien.health -= 10
|
||||
bossalien.health -= 100
|
||||
bullets.remove(bullet)
|
||||
|
||||
# 生命值为0时删除该BOSS
|
||||
|
@ -194,8 +194,8 @@ def create_fleet(ai_settings, screen, ship, aliens):
|
|||
|
||||
def get_number_aliens_x(ai_settings, alien_width):
|
||||
"""计算每行可容纳多少个外星人"""
|
||||
available_space_x = ai_settings.screen_width - 4 * alien_width
|
||||
number_aliens_x = int(available_space_x / (2 * alien_width))
|
||||
available_space_x = ai_settings.screen_width - 3 * alien_width
|
||||
number_aliens_x = int(available_space_x / (3 * alien_width))
|
||||
return number_aliens_x
|
||||
|
||||
|
||||
|
@ -203,16 +203,16 @@ def create_alien(ai_settings, screen, aliens, alien_number, row_number):
|
|||
"""创建一个外星人并将其放在当前行"""
|
||||
alien = Alien(ai_settings, screen)
|
||||
alien_width = alien.rect.width
|
||||
alien.x = alien_width + 2 * alien_width * alien_number
|
||||
alien.x = alien_width + 4 * alien_width * alien_number
|
||||
alien.rect.x = alien.x
|
||||
alien.rect.y = alien.rect.height + 4 * alien.rect.height * row_number
|
||||
alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
|
||||
aliens.add(alien)
|
||||
|
||||
|
||||
def get_number_rows(ai_settings, ship_height, alien_height):
|
||||
"""计算屏幕可容纳多少行外星人"""
|
||||
available_space_y = (ai_settings.screen_height - (4 * alien_height) - ship_height)
|
||||
number_rows = int(available_space_y / (3 * alien_height))
|
||||
available_space_y = (ai_settings.screen_height - (5 * alien_height) - ship_height)
|
||||
number_rows = int(available_space_y / (2 * alien_height))
|
||||
return number_rows
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue