Beispiel #1
0
    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
Beispiel #2
0
 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)
Beispiel #3
0
 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')
Beispiel #4
0
    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()
Beispiel #5
0
 def off(self):
     self.state = False
     self.rect.size = [self.width, 1]
     self.image = self.off_image
     self.recharge = self.recharge_time
     global MIXER
     MIXER.stop(self.soundchannel)
Beispiel #6
0
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)
Beispiel #7
0
 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()
Beispiel #8
0
 def destruct(self):
     global MIXER
     global explosion_channel
     MIXER.stop(self.soundchannel)
     MIXER.stop(self.lazer.soundchannel)
     MIXER.free_channel(self.soundchannel)
     MIXER.play(explosion_channel, 'explosion')
     exploading_ships.append([self.rect.left, self.rect.top, 0])
     self.lazer.kill()
     self.kill()
Beispiel #9
0
    def __init__(self):
        x = randint(0, main_win_width - 20)
        self.rect = pygame.Rect(x, 0, 20, 20)
        self.image = pygame.Surface(self.rect.size)
        self.image.fill((220, 40, 40))
        pygame.draw.rect(self.image, (255, 255, 255), (8, 0, 4, 20))
        pygame.draw.rect(self.image, (255, 255, 255), (0, 8, 20, 4))
        pygame.sprite.Sprite.__init__(self)

        global MIXER
        self.soundchannel = MIXER.get_channel()
Beispiel #10
0
    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()
Beispiel #11
0
    def __init__(self):
        x = randint(0, main_win_width - 20)
        self.rect = pygame.Rect(x, 0, 20, 20)
        self.image = pygame.Surface(self.rect.size)
        pygame.draw.circle(self.image, (160, 160, 180), (10, 10), 10)

        self.gathered = False
        self.timer = 0

        self.recharge_time = 100
        pygame.sprite.Sprite.__init__(self)

        global MIXER
        self.soundchannel = MIXER.get_channel()
Beispiel #12
0
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)
Beispiel #13
0
    def __init__(self,
                 rect,
                 image,
                 speed,
                 lifebar_rect,
                 life_capacity,
                 life_color=(0, 255, 0)):
        self.life_capacity = life_capacity
        self.life = life_capacity
        self.lifebar_rect = lifebar_rect
        self.lifecolor = life_color

        self.speed = speed
        self.score = 0

        global MIXER
        self.soundchannel = MIXER.get_channel()
        Solid.__init__(self, image, rect)
Beispiel #14
0
 def destruct(self):
     global MIXER
     MIXER.free_channel(self.soundchannel)
     self.kill()
Beispiel #15
0
    pygame.image.load(os.path.join('explosion', 'frame_' + str(i) + '.png'))
    for i in range(12)
]
explosion_frames = [
    pygame.transform.scale(image,
                           (image.get_width() // 3, image.get_width() // 3))
    for image in big_explosion_frames
]

scaling_factor = 2

from soundhandler import MIXER

from directives import enemy_lazership_directive_0, enemy_blasterfighter_directive_3, enemy_blasterfighter_directive_2, enemy_blasterfighter_directive_1, enemy_blasterfighter_directive_0, serp_directive_0

explosion_channel = MIXER.get_channel()

background = pygame.image.load('images/b2.png')


def docollide(recta, imagea, rectb, imageb):
    i_x_s, i_x_e = max(recta.left, rectb.left), min(recta.right, rectb.right)
    i_y_s, i_y_e = max(rectb.top, recta.top), min(recta.bottom, rectb.bottom)

    arra = pygame.PixelArray(imagea)
    arrb = pygame.PixelArray(imageb)
    for i in range(i_x_s, i_x_e):
        for j in range(i_y_s, i_y_e):
            #if arra[i-recta.left][j-recta.top] != 0 and arrb[i-rectb.left][j-rectb.top] != 0:
            if arra[i - recta.left][j - recta.top] != 0 and arrb[
                    i - rectb.left][j - rectb.top] != 0: