Пример #1
0
 def die(self):
     for i in range(9):
         pg.display.update(
                 gfx.explosion(self.center[0] + randrange(-100, 100, 20), self.center[1] + randrange(-100, 100, 20)))
         snd.load_sound("explode.wav")
     self.image = pg.transform.scale2x(gfx.load_image("explosion_last.png"))
     snd.load_sound("blow_up.wav")
     pg.display.update()
     snd.play_song("saturns_folly.ogg")
     self.kill()
Пример #2
0
    def title_screen(self):
        scroll = 0
        anim = 0
        ship_image = None

        while True:
            title_a = gfx.img_title_a
            title_b = gfx.img_title_b
            title_size = title_a.get_size()
            steps = int(title_size[0] / 2)
            for i in range(steps + 75):
                self.screen.blit(gfx.img_title_background, (0, 0))
                self.screen.blit(gfx.img_title_stars, (0, 100))
                self.screen.blit(title_a, (10 - title_size[0] + i * 2, 300))
                self.screen.blit(title_b, (10 + SCREEN_WIDTH - i * 2, 300))
                pg.display.flip()
            snd.load_sound("blow_up.wav")
            for i in range(100):
                pg.display.update(self.screen.fill(WHITE))
            self.screen.blit(gfx.img_title_background, (0, 0))
            snd.play_song("title_song.ogg")
            break

        while True:

            if scroll <= SCREEN_WIDTH:
                scroll += .5
            else:
                scroll = 0

            self.screen.blit(gfx.img_title_stars, (scroll, 100))
            self.screen.blit(gfx.img_title_stars, (-SCREEN_WIDTH + scroll, 100))
            self.screen.blit(gfx.img_title_whole, (SCREEN_CENTER[0] - gfx.img_title_whole.get_width() / 2 + 20, 300))

            for _ in range(1):
                if anim < 20:
                    ship_image = gfx.title_ship_a
                elif anim > 20:
                    ship_image = gfx.title_ship_b
                self.screen.blit(ship_image, (SCREEN_CENTER[0] - (gfx.title_ship_a.get_width() / 2) + 20, 600))

                if anim < 50:
                    menu = self.font.render("PRESS ENTER", True, WHITE)
                    self.screen.blit(menu, (SCREEN_CENTER[0] - menu.get_width() / 2, SCREEN_CENTER[1]))
                elif anim > 50:
                    menu = self.font.render("PRESS ENTER", True, BLACK)
                    self.screen.blit(menu, (SCREEN_CENTER[0] - menu.get_width() / 2, SCREEN_CENTER[1]))

            anim += 1
            if anim >= 100:
                anim = 0

            pg.display.update()

            e = pg.event.poll()
            if e.type == pg.KEYDOWN:
                if e.key == pg.K_RETURN:
                    snd.load_sound("takeoff.wav")
                    while True:
                        for i in range(255):
                            self.screen.fill((255 - i, 255 - i, 255 - i))
                            helper_functions.scanlines()
                            pg.display.update()
                        break
                    break

        while True:
            text = self.font.render("GET READY", True, WHITE)
            count_list = ["5", "4", "3", "2", "1", "GO!"]
            for i in range(6):
                countdown = self.font.render(count_list[i], True, WHITE)
                self.screen.fill(BLACK)
                self.screen.blit(text, (SCREEN_CENTER[0] - text.get_width() / 2, SCREEN_CENTER[1]))
                self.screen.blit(countdown, (SCREEN_CENTER[0] - countdown.get_width() / 2, SCREEN_CENTER[1] + 30))
                helper_functions.scanlines()
                pg.display.update()
                pg.time.wait(1000)
            break

        snd.play_song("saturns_folly.ogg")
        self.started = True
Пример #3
0
    def update_loop(self):
        # self.gametime = round(time() - self.start_time)
        self.ticker += 1
        if self.ticker == self.FPS:
            self.gametime += 1
            self.ticker = 0

        self.all_sprites.add(self.player_bullets)
        self.all_sprites.add(self.enemy_bullets)
        self.all_sprites.add(self.player)
        self.all_sprites.add(self.enemies)
        self.all_sprites.add(self.powerups)

        if self.player_lives <= 0:
            self._is_running = False

        if self._is_running and self.gametime > 10:
            if not self.boss_defeated and not self.player.dead:
                if len(self.cruiser) < 1 and self.KILL_COUNT >= 99:
                    snd.play_song("deadly_opposition.ogg")
                    big_enemy = EnemyCruiser()
                    self.cruiser.add(big_enemy)
                    self.enemies.add(self.cruiser)

                if len(self.fighters) < self.MAX_ENEMIES:
                    if len(self.cruiser) == 0:
                        self.spawn_timer += 1
                        if self.spawn_timer >= 20:
                            little_enemy = EnemyFighter()
                            self.fighters.add(little_enemy)
                            self.enemies.add(self.fighters)
                            self.spawn_timer = 0

                        if len(self.frigates) < 1:
                            frigate = EnemyFrigate()
                            frigate.rect.y = choice([50, 100, 150, 200, 250, 300])
                            frigate.rect.right = 0
                            self.frigates.add(frigate)
                            self.enemies.add(self.frigates)

            if self.ENEMIES_KILLED > 25:
                self.MAX_ENEMIES += 1
                self.ENEMIES_KILLED = 0

            for fighter in self.fighters:
                if not self.player.dead or self.player.arrive or self.player.respawn or self.player.invulnerable:
                    if not fighter.has_shot:
                        if abs(self.player.rect.y - fighter.rect.bottom <= 300) and abs(
                                                self.player.rect.centerx - fighter.rect.centerx <= 500) and fighter.rect.y <= 900:
                            fighter.shoot(self.player)
                            self.enemy_bullets.add(fighter.allBullets)

            for frigate in self.frigates:
                if frigate.rect.left >= SCREEN_WIDTH:
                    frigate.kill()
                if frigate.rect.centerx == self.player.rect.centerx:
                    frigate.shoot()
                self.enemy_bullets.add(frigate.allBullets)

            for cruiser in self.cruiser:
                print(cruiser.HEALTH)
                if cruiser.HEALTH < 1:
                    print("DEAD")
                    self.boss_defeated = True
                    cruiser.die()
                if self.player.dead:
                    cruiser.allBullets.empty()
                # if cruiser.rect.bottom <= self.player.rect.bottom:
                #     new_bullet = Bullet(cruiser.rect.centerx, cruiser.rect.y, gfx.img_enemy_shot_a)
                #     if self.player.rect.centerx < cruiser.rect.centerx:
                #         new_bullet.dx = -10
                #         cruiser.allBullets.add(new_bullet)
                #     elif self.player.rect.centerx > cruiser.rect.centerx:
                #         new_bullet.dx = 10
                #         cruiser.allBullets.add(new_bullet)
                self.enemy_bullets.add(cruiser.allBullets)

            if not self.player.invulnerable:
                for enemy in self.enemies:
                    if pg.sprite.collide_mask(self.player, enemy):
                        enemy.HEALTH -= 10
                        self.player.die()
                        self.player_lives -= 1

                for bullet in self.enemy_bullets:
                    if not self.player.dead and self.player.rect.colliderect(bullet.rect):
                        self.player.die()
                        bullet.kill()
                        self.player_lives -= 1

            for bullet in self.player_bullets:
                for enemy in self.enemies:
                    if enemy.HEALTH > 0 and enemy.rect.y >= 10 and pg.sprite.collide_mask(bullet, enemy):
                        bullet.on_hit()
                        snd.load_sound("hit.wav")
                        enemy.is_hit = True
                        enemy.HEALTH -= 1
                        if self.player.power_level <= 2:
                            bullet.kill()
                        if enemy.HEALTH <= 0:
                            self.ENEMIES_KILLED += 1
                            self.KILL_COUNT += 1
                            pwr_up = PowerUp()
                            pwr_up.rect = enemy.rect
                            if randint(1, 20) == self.drop_chance:
                                self.powerups.add(pwr_up)

            for beam in EnemyCruiser.allBullets:
                for fighter in self.fighters:
                    if pg.sprite.collide_mask(beam, fighter):
                        fighter.die()
                for frigate in self.frigates:
                    if pg.sprite.collide_mask(beam, frigate):
                        frigate.die()

            for powerup in self.powerups:
                if pg.sprite.collide_mask(powerup, self.player):
                    powerup.on_pickup()
                    self.player.power_level += 1

            for sprite in self.all_sprites:
                if 0 > sprite.rect.x > SCREEN_WIDTH:
                    sprite.kill()
                    self.all_sprites.remove(sprite)
                if 0 > sprite.rect.y > SCREEN_HEIGHT:
                    sprite.kill()
                    self.all_sprites.remove(sprite)

        # Mimic the apperance of hyper drive
        if self.player.arrive:
            self.star_speed = 10
        else:
            self.counter += 1
            if self.star_speed > 2 and self.counter >= 10:
                self.star_speed -= 1
                self.counter = 0
            else:
                pass

        # Player ship leaves after boss defeated
        if self.boss_defeated:
            self.enemy_bullets.empty()
            self.star_speed = 5
            self.player.dx = 0
            self.player.move_up()
            if self.player.rect.bottom <= 0:
                self._is_running = False

        self.all_sprites.update()
        self.clock.tick(self.FPS)