Beispiel #1
0
def create_alien(ai_settings, screen, alien_number, row_number, aliens):
    alien = Alien(ai_settings, screen)
    alien.x = alien.rect.width + 2 * alien.rect.width * alien_number
    alien.rect.x = alien.x
    alien.y = alien.rect.height + 2 * alien.rect.height * row_number
    alien.rect.y = alien.y
    aliens.add(alien)
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 + 1.5 * alien.rect.height * row_number
    aliens.add(alien)
Beispiel #3
0
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.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
    aliens.add(alien)
Beispiel #4
0
def create_alien(ai_settings, screen, alien_number, alien_row):
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_number * alien_width
    alien.rect.x = alien.x
    alien_height = alien.rect.height
    alien.y = alien_height + 2 * alien_row * alien_height
    alien.rect.y = alien.y
    return alien
Beispiel #5
0
def create_alien(sett, screen, aliens, alien_number, row_no):
    """Create an alien, and place it in row."""
    alien = Alien(sett, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 1.5 * alien_width * alien_number
    alien.rect.x = alien.x
    alien_height = alien.rect.height
    alien.rect.y = alien_height + 1.5 * alien_height * row_no
    aliens.add(alien)
Beispiel #6
0
def create_alien(ai_settings, screen, aliens):
    """创建一个外星人"""
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = randint(alien_width, screen.get_rect().right - alien_width)
    # 如果外星人的x坐标在创建时就和屏幕碰撞将会有bug
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height
    alien.fleet_direction = choice([1, -1])
    aliens.add(alien)
Beispiel #7
0
def create_fleet(ai_settings, screen, aliens, ship):
    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)
    for alien_number in range(number_aliens_x):
        for alien_row in range(number_rows):
            aliens.add(create_alien(ai_settings, screen, alien_number, alien_row))
Beispiel #8
0
def create_fleet(ai_settings: Settings, screen, ship, aliens: Group):
    alien = Alien(ai_settings, screen)
    number_rows = get_number_rows(ai_settings, ship.rect.height,
                                  alien.rect.height)
    number_aliens_x = get_number_aliens_x(ai_settings, alien.rect.width)

    for row_number in range(number_rows):
        for alien_number in range(number_aliens_x):
            create_alien(ai_settings, screen, alien_number, row_number, aliens)
def create_fleet(ai_settings, screen, ship, aliens):
    """Creates a fleet of aliens"""
    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 fleet
    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)
def create_fleet(ai_settings, screen, rocket_ship, aliens):
    """Create a full fleet of aliens."""
    # Create an alien and find the number of aliens in row
    alien = Alien(ai_settings, screen)
    number_aliens_x = get_number_aliens(ai_settings, alien.rect.width)
    number_rows = get_number_rows(ai_settings, rocket_ship.rect.height, alien.rect.height)

    # Create the first row 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)
Beispiel #11
0
def create_fleet(sett, screen, ship, aliens):
    """Create a full fleet/row of aliens."""
    alien = Alien(sett, screen)
    no_aliens = get_no_aliens(sett, alien.rect.width)
    no_rows = get_no_rows(sett, ship.rect.height, alien.rect.height)

    # Create the fleet of aliens.

    for row in range(no_rows):
        for alien_number in range(no_aliens):
            create_alien(sett, screen, aliens, alien_number, row)
Beispiel #12
0
def create_fleet(ai_settings, screen, ship, aliens):
    """创建外星人群"""
    # 创建一个外星人,并计算每行可容纳多少个外星人
    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)

    # 创建外星人群
    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)
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    ship = Ship(ai_settings, screen)
    bullets = Group()
    alien = Alien(ai_settings, screen)
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullet(bullets)
        gf.update_screen(ai_settings, screen, ship, alien, bullets)
Beispiel #14
0
def rungame():
    # Initialize game,settings and create screen object.
    pygame.init()
    sett = Settings()
    screen = pygame.display.set_mode((sett.screen_width, sett.screen_height))
    pygame.display.set_caption("Alien Invasion")
    """"Instance initialization"""
    # Make instance of game stats.
    stats = GameStats(sett)
    # Make instance of scoreboard.
    sb = ScoreBoard(sett, screen, stats)
    # Make the play button.
    b_play = Button(sett, screen, "PLAY")

    # Make instance of ship.
    ship = Ship(sett, screen)
    # Make a group to store bullets and aliens.
    aliens = Group()
    bullets = Group()
    # Make instance of alien.
    alien = Alien(sett, screen)
    gf.create_fleet(sett, screen, ship, aliens)

    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(sett, screen, stats, sb, b_play, ship, aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(sett, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(sett, stats, sb, screen, ship, aliens, bullets)

        # Redraw the screen during each pass through the loop.
        gf.update_screen(sett, screen, stats, sb, ship, aliens, bullets,
                         b_play)