第五部分5
This commit is contained in:
parent
4f1ed48754
commit
bd294836b0
Binary file not shown.
Binary file not shown.
|
@ -201,3 +201,38 @@ def update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets):
|
||||||
# Look for aliens hitting the bottom of the screen.
|
# Look for aliens hitting the bottom of the screen.
|
||||||
check_aliens_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets)
|
check_aliens_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets)
|
||||||
|
|
||||||
|
def get_number_aliens_x(ai_settings, alien_width):
|
||||||
|
"""Determine the number of aliens that fit in a row."""
|
||||||
|
available_space_x = ai_settings.screen_width - 2 * alien_width
|
||||||
|
number_aliens_x = int(available_space_x / (2 * alien_width))
|
||||||
|
return number_aliens_x
|
||||||
|
|
||||||
|
def get_number_rows(ai_settings, ship_height, alien_height):
|
||||||
|
"""Determine the number of rows of aliens that fit on the screen."""
|
||||||
|
available_space_y = (ai_settings.screen_height -
|
||||||
|
(3 * alien_height) - ship_height)
|
||||||
|
number_rows = int(available_space_y / (2 * alien_height))
|
||||||
|
return number_rows
|
||||||
|
|
||||||
|
def create_alien(ai_settings, screen, aliens, alien_number, row_number):
|
||||||
|
"""Create an alien, and place it in the row."""
|
||||||
|
alien = Alien(ai_settings, screen)
|
||||||
|
alien_width = alien.rect.width
|
||||||
|
alien.x = alien_width + 2 * alien_width * alien_number
|
||||||
|
alien.rect.x = alien.x
|
||||||
|
alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
|
||||||
|
aliens.add(alien)
|
||||||
|
|
||||||
|
def create_fleet(ai_settings, screen, ship, aliens):
|
||||||
|
"""Create a full fleet of aliens."""
|
||||||
|
# Create an alien, and find number of aliens in a row.
|
||||||
|
alien = Alien(ai_settings, screen)
|
||||||
|
number_aliens_x = get_number_aliens_x(ai_settings, alien.rect.width)
|
||||||
|
number_rows = get_number_rows(ai_settings, ship.rect.height,
|
||||||
|
alien.rect.height)
|
||||||
|
|
||||||
|
# Create the fleet of aliens.
|
||||||
|
for row_number in range(number_rows):
|
||||||
|
for alien_number in range(number_aliens_x):
|
||||||
|
create_alien(ai_settings, screen, aliens, alien_number,
|
||||||
|
row_number)
|
||||||
|
|
Loading…
Reference in New Issue