コード例 #1
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
 def __init__(self, x=0, y=0, dx=10, dy=10):
     frames = [
         pygame.image.load('images/serp/' + i)
         for i in os.listdir('images/serp/')
     ]
     global scaling_factor
     frames = [
         pygame.transform.scale(i, (int(i.get_width() / scaling_factor),
                                    int(i.get_height() / scaling_factor)))
         for i in frames
     ]
     image = frames[0]
     self.frames = frames
     width, height = image.get_width(), image.get_height()
     rect = pygame.Rect(x, y, width, height)
     life_capacity = 20
     speed = 0
     lifebar_rect = make_lifebar_rect(width, x, y, life_capacity)
     self.state = 0
     self.bullets = pygame.sprite.Group()
     Spacecraft.__init__(self, rect, image, speed, lifebar_rect,
                         life_capacity, (255, 0, 0))
     Enemy.__init__(self, serp_directive_0, {'damage': 0})
     self.dx = dx
     self.dy = dy
     global MIXER
     MIXER.play(self.soundchannel, 'serp', way=-1)
     Hitter.__init__(self)
コード例 #2
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
    def update(self, character):
        global MIXER
        self.rect.y += 5
        collision = pygame.sprite.spritecollide(
            self, pygame.sprite.GroupSingle(character), 1)

        if collision != []:
            character.shields = True
            self.gathered = True

            MIXER.play(self.soundchannel, 'healing')
            self.respawn()

        if self.rect.y == main_win_width:
            self.respawn()

        if self.gathered:
            if self.timer >= self.recharge_time:
                character.shields = False
                self.timer = 0
                self.gathered = False

                MIXER.play(self.soundchannel, 'shields_down')

            self.timer += 1
コード例 #3
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
    def analyze(self, target):
        # Damage Analysis begins
        dead_bullets = self.analyze_damage(target)
        # Checking own vitals
        if self.life == 0:
            target.score += 1
            self.destruct()
        # Damage Analysis complete
        # Analyzing damage suffered by target...
        if not target.shields:
            collisions = pygame.sprite.spritecollide(target, self.bullets, 0)
            if collisions:
                n = 0
                for bullet in self.bullets:
                    if docollide(target.rect, target.image, bullet.rect,
                                 bullet.image):
                        dead_bullets.append(bullet)
                        n += 1
                target.life = max(target.life - n * self.damage, 0)
                self.score += n
                if target.life < 0:
                    target.life = 0

                    global MIXER
                    MIXER.play(self.soundchannel, 'kill')
        for bullet in dead_bullets:
            bullet.kill()
コード例 #4
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
 def on(self):
     self.state = True
     self.rect.size = [self.width, main_win_height]
     self.image = self.on_image
     self.recharge = self.recharge_time
     global MIXER
     MIXER.play(self.soundchannel, 'lazer')
コード例 #5
0
ファイル: directives.py プロジェクト: yxurrbzallkd/o
def enemy_blasterfighter_directive_3(ship, target):
    if ship.state < 20:
        ship.move(-8, 7)
    elif ship.state < 40:
        ship.move(-8, -7)
    elif ship.state < 60:
        ship.move(8, 7)
    elif ship.state < 80:
        ship.move(8, -7)
    else:
        ship.state = 0
    ship.state += 1

    if ship.guns_recharge == 0:
        ship.shoot()
        ship.guns_recharge = ship.recharge_time

        global MIXER
        MIXER.play(ship.soundchannel, 'enemy_blast')
    else:
        ship.guns_recharge -= 1

    for bullet in ship.bullets:
        bullet.update()
    pygame.sprite.groupcollide(target.bullets, ship.bullets, 1, 1)
コード例 #6
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
 def destruct(self):
     global MIXER
     global explosion_channel
     MIXER.play(explosion_channel, 'explosion')
     exploading_ships.append([self.rect.left, self.rect.top, 0])
     MIXER.stop(self.soundchannel)
     MIXER.free_channel(self.soundchannel)
     self.kill()
コード例 #7
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
 def update(self, character):
     self.rect.y += 5
     collision = pygame.sprite.spritecollide(
         self, pygame.sprite.GroupSingle(character), 1)
     if collision != []:
         character.life = character.life_capacity
         global MIXER
         MIXER.play(self.soundchannel, 'healing')
         self.respawn()
     if self.rect.y == main_win_width:
         self.respawn()
コード例 #8
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
    def update(self):
        x = 0
        y = 0
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT] or keys[pygame.K_a]:
            x -= 1
        if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
            x += 1
        if keys[pygame.K_UP] or keys[pygame.K_w]:
            y -= 1
        if keys[pygame.K_DOWN] or keys[pygame.K_s]:
            y += 1
        if keys[pygame.K_ESCAPE]:
            pygame.quit()
        if keys[pygame.K_SPACE]:
            character.shoot()
            global MIXER
            MIXER.play(self.soundchannel, 'my_shot')

        self.move(x * self.speed, y * self.speed)
        self.bullets.update()
コード例 #9
0
ファイル: animated.py プロジェクト: yxurrbzallkd/o
def end_game(character,
             enemies,
             exploading_ships,
             stars,
             window=window,
             explosion_frames=explosion_frames):
    x_init = character.rect.left + character.image.get_width() // 2
    y_init = character.rect.top + character.image.get_height() // 2
    character.kill()

    global MIXER
    MIXER.play(MIXER.get_channel(), 'explosion')
    for image in big_explosion_frames:
        window.fill(background_color)
        draw_stars(stars, window)
        for enemy in enemies:
            enemy.update(character)
            enemy.draw(window)
        x = x_init - image.get_width() // 2
        y = y_init - image.get_height() // 2

        window.blit(image, (x, y))
        expload(exploading_ships)

        window.blit(score_word_surf, (10, 10))
        window.blit(
            score_text.render(str(character.score), True, (255, 255, 255)),
            (score_width + 10, 10))

        pygame.display.flip()
        pygame.time.delay(100)
    MIXER.play(explosion_channel, 'game_over')
    pygame.mixer.stop()
    window.fill(background_color)

    pygame.time.delay(1500)