コード例 #1
0
    def _fire_alien(self):
        # for alien in self.aliens.sprites():
        alien = random.choice(self.aliens.sprites())

        new_alien_bullet = AlienBullet(self)
        self.alien_bullets.add(new_alien_bullet)

        new_alien_bullet.rect.midbottom = alien.rect.center
        new_alien_bullet.y = float(alien.rect.y)
        self.settings.last_alien_shot = time.clock()
コード例 #2
0
def create_alien_bullet(ai_settings, screen, alien_bullets):
	"""
	Create alien bullets which start position's based on the random 
	position of the fleet of aliens 
	"""
	while (len(alien_bullets) < ai_settings.alien_bullets_allowed):		
		alien_bullet = AlienBullet(ai_settings, screen)
		chosen_alien = choice(alien_list)
		alien_bullet.rect.x = chosen_alien.rect.x
		alien_bullet.y = float(chosen_alien.rect.y)
		alien_bullet.rect.y = alien_bullet.y
		alien_bullets.add(alien_bullet) 
コード例 #3
0
def create_alien_bullet(ai_settings, screen, aliens, ship, alien_bullets):
    for alien in aliens:
        if round(time.time(), 1) - alien.las_fire_time >= ai_settings.alien_bullet_time and \
                alien.rect.bottom < ai_settings.screen_height / 2:
            alien_bullet = AlienBullet(ai_settings, screen, alien, ship)
            alien_bullets.add(alien_bullet)
            alien.update_last_fire_time()
コード例 #4
0
ファイル: alien.py プロジェクト: yungwill/SpaceInvadersClone
    def update(self):
        """Move the aliens, animates every 50 loops, and sets up aliens shooting lasers"""
        if self.index == 3:
            self.x += self.ai_settings.ufo_speed_factor
        else:
            self.x += (self.ai_settings.alien_speed_factor *
                       self.ai_settings.fleet_direction)
        self.rect.x = self.x

        if self.delay == 50 and self.index != 3:
            if not self.animate:
                self.image = pygame.image.load(self.img2[self.index])
                self.animate = True
            elif self.animate:
                self.image = pygame.image.load(self.img[self.index])
                self.animate = False
            self.delay = 0
        else:
            self.delay += 1

        # Shoots lasers at random intervals
        if self.delay2 == self.timer:
            if len(self.alien_bullets
                   ) < self.ai_settings.alien_bullets_allowed:
                new_bullet = AlienBullet(self.ai_settings, self.screen,
                                         self.rect.x, self.rect.y)
                self.alien_bullets.add(new_bullet)
            self.delay2 = 0
            self.timer = random.randint(300, 701)
        else:
            self.delay2 += 1
コード例 #5
0
ファイル: game_functions.py プロジェクト: Shevvv/ships_python
def aliens_shooting(ai_settings, screen, aliens, alien_bullets):
    """Make bottommost aliens randomly shoot their own bullets."""
    for alien in aliens:
        if alien.bottommost and (
                randint (0, 10000) in (
                    range(0, int(ai_settings.alien_bullet_chance)))):
            alien_bullet = AlienBullet(ai_settings, screen, alien)
            alien_bullets.add(alien_bullet)
    alien_bullets.update()
コード例 #6
0
ファイル: bullets.py プロジェクト: Maxw21/Alien_Invader
 def alien_shoot(self, alien):
     """Create a bullet from an alien."""
     self.sounds.alien_bullet_sound.play()
     new_bullet = AlienBullet(screen=self.screen,
                              sprite_sheet=self.sprite_sheet,
                              x=alien.rect.x,
                              y=alien.rect.y,
                              version=random.randint(0, 1))
     self.alien_bullets.add(new_bullet)
コード例 #7
0
def fire_random_alien_bullet(ai_settings, screen, aliens, alien_bullets):
    """Fire a alien bullet from a random alien in the fleet"""
    firing_alien = random.choice(aliens.sprites())
    if len(alien_bullets) < ai_settings.alien_bullet_allowed and \
            (ai_settings.alien_bullet_stamp is None or
             (abs(pygame.time.get_ticks() - ai_settings.alien_bullet_stamp) > ai_settings.alien_bullet_time)):
        new_alien_bullet = AlienBullet(ai_settings, screen, firing_alien)
        firing_alien.fire_weapon()
        alien_bullets.add(new_alien_bullet)
コード例 #8
0
def fire_alien_bullet(sw_settings, screen, aliens, aliens_bullets):
    alien_y_values = [alien.rect.y for alien in aliens.sprites()]
    max_alien_y = max(alien_y_values)
    bottom_aliens = []
    for alien in aliens.sprites():
        if alien.rect.y == max_alien_y:
            bottom_aliens.append(alien)
    for alien in bottom_aliens:
        new_alien_bullet = AlienBullet(sw_settings, screen, alien)
        aliens_bullets.add(new_alien_bullet)
コード例 #9
0
def fire_random_alien_bullet(ai_settings, screen, aliens, alien_bullets):
    """Random bullets fire from aliens randomly"""
    # Alien fire randomly
    firing_alien = random.choice(aliens.sprites())
    if len(alien_bullets) < ai_settings.alien_bullet_allowed and (ai_settings.alien_bullet_stamp is None or (abs(pygame.time.get_ticks() - ai_settings.alien_bullet_stamp) > ai_settings.alien_bullet_time)):
        new_alien_bullet = AlienBullet(ai_settings, screen, firing_alien)
        # Fire from alien
        firing_alien.shoot_fire()
        # Create new bullet
        alien_bullets.add(new_alien_bullet)
コード例 #10
0
def alien_shooting(ai_settings, screen, ship, alien_bullets, aliens):
    alien_bullets.update()
    # Get rid of bullets that have disappeared.
    for alien in aliens.sprites():
        i = alien.rect.y

        # if len(alien_bullets) < ai_settings.bullets_allowed:
        bullet_sound = pygame.mixer.Sound("sounds/fire_sound.ogg")
        pygame.mixer.Sound.play(bullet_sound)
        new_bullet = AlienBullet(ai_settings, screen, ship, i)
        alien_bullets.add(new_bullet)
コード例 #11
0
def fire_alien_bullet(ai_settings, screen, aliens, alien_bullets):
    """Fire an alien bullet from a random alien every 5 seconds"""
    try:
        #Choose a random alien
        alien_sprites_list = aliens.sprites()
        rand_alien_index = randint(0, len(alien_sprites_list))
        chosen_alien = alien_sprites_list[rand_alien_index]

        #Have the chosen alien fire an alien bullet
        new_alien_bullet = AlienBullet(ai_settings, screen, chosen_alien)
        alien_bullets.add(new_alien_bullet)
    except IndexError:
        pass
コード例 #12
0
def fire_alien_bullet(si_settings, aliens, alien_bullets, screen):
    """"Fire a bullet from a random alien once every couple of hundred frames"""
    # set firing time
    random_fire = random.randint(-si_settings.alien_firing_spread,
                                 si_settings.alien_firing_spread)
    time_to_next_bullet = si_settings.alien_firing_rate + random_fire

    if len(alien_bullets) < si_settings.alien_bullets_allowed and len(
            aliens) > 0:
        alien = select_firing_alien(aliens)
        new_alien_bullet = AlienBullet(si_settings, screen, alien)
        alien_bullets.add(new_alien_bullet)

    return time_to_next_bullet
コード例 #13
0
def update_shooting_aliens(ai_settings, stats, scoreboard, screen, ship,
                           aliens, moving_aliens, shooting_aliens,
                           alien_bullets):
    """Update the position of all aliens in the fleet"""
    for shooting_alien in shooting_aliens:
        shooting_alien.update()
        if shooting_alien.fire_bullet() == 0:
            new_bullet = AlienBullet(ai_settings, screen, shooting_alien)
            alien_bullets.add(new_bullet)

    screen_rect = screen.get_rect()
    for shooting_alien in shooting_aliens:
        if shooting_alien.rect.right >= screen_rect.right:
            #as if the ship got hit
            shooting_aliens.remove(shooting_alien)
    if len(shooting_aliens) == 0:
        #as if the ship got hit
        create_shooting_fleet(ai_settings, screen, shooting_aliens)
コード例 #14
0
def update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets,
                  alien_bullets):
    check_fleet_edges(ai_settings, aliens)

    if pygame.sprite.spritecollideany(ship, aliens):
        ship_hit(stats, sb, ship, aliens, bullets, alien_bullets)

    check_aliens_bottom(screen, stats, sb, ship, aliens, bullets,
                        alien_bullets)

    num = random.randint(1, 42)
    count = 1
    num2 = random.randint(1, 100)
    for alien in aliens.sprites():
        if count == num:
            if num2 == 1:
                new_bullet = AlienBullet(ai_settings, screen, alien)
                alien_bullets.add(new_bullet)
        count += 1
コード例 #15
0
def create_alien_bullets(aliens, screen, stats, ai_settings, alien_bullets, ship):
	for alien in aliens:
		alien_bullet = AlienBullet(screen, alien, ai_settings, ship)
		alien_bullets.add(alien_bullet)
コード例 #16
0
 def _fire_alien_bullet(self):
     """Create new alien bullet and add it to the alien bullet's group"""
     if len(self.alien_bullets) < self.settings.alien_bullets_allowed:
         new_bullet = AlienBullet(self)
         self.alien_bullets.add(new_bullet)
         self.alien_fire_sound.play()
コード例 #17
0
ファイル: alien.py プロジェクト: admiralZz/Space-Invasion
 def shot(self, bullets):
     bullet = AlienBullet(self.screen, self.settings, self)
     bullets.add(bullet)
コード例 #18
0
ファイル: main.py プロジェクト: kovadam19/AlienInvasion
 def _fire_queen_bullet(self):
     """Creates a new bullet for the queen and adds it to the bullet group"""
     new_bullet = AlienBullet(self)
     self.alien_bullets.add(new_bullet)
コード例 #19
0
ファイル: alien.py プロジェクト: mlopez814/AlienInvasion-Pt.2
 def fire_bullet(self):
     new_bullet = AlienBullet(self.ai_setting, self.screen, self.rect)
     new_bullet.rect.centerx = self.rect.centerx
     new_bullet.rect.top = self.rect.bottom
     new_bullet.rect.y = self.rect.y
     self.alien_bullets.add(new_bullet)
コード例 #20
0
def shoot_boss_bullets(settings, screen, aliens, boss_bullets, boss):
    if boss.shoot():
        bullet = AlienBullet(settings, screen, boss)
        boss_bullets.add(bullet)
コード例 #21
0
def shoot_alien_bullets(settings, screen, aliens, alien_bullets, alien):
    for alien in aliens.sprites():
        if random.randrange(101) == 100:
            if len(alien_bullets) < settings.alien_bullets_allowed:
                bullet = AlienBullet(settings, screen, alien)
                alien_bullets.add(bullet)
コード例 #22
0
ファイル: game_functions.py プロジェクト: An-LeMi/Alien-fire
def alien_fire_bullet(ai_settings, screen, alien, alien_bullets):
    """Create an alien bullet"""
    new_alien_bullet = AlienBullet(ai_settings, screen, alien)
    alien_bullets.add(new_alien_bullet)
コード例 #23
0
def fire_aliens_bullet(ai_settings, screen, aliens, aliens_bullets):
    """如果没有达到限制,就发射一颗子弹"""
    if len(aliens_bullets) < ai_settings.bullets_allowed:
        new_bullet = AlienBullet(ai_settings, screen,
                                 random.choice(aliens.sprites()))
        aliens_bullets.add(new_bullet)