Exemple #1
0
    def update(self):
        if self.dir:
            self.x += self.speed
            self.rect.centerx += self.speed
        else:
            self.x -= self.speed
            self.rect.centerx -= self.speed
        if self.rect.colliderect(self.oppo.rect):
            if self.oppo.animation == ATTACK_ONE and self.oppo.dir != self.dir:
                self.dir = not self.dir
                if self.player == 1:
                    self.image = self.image = pygame.image.load(
                        convertpath.path(
                            ['Martial Hero 2', 'Sprites',
                             'bullet.png'])).convert()
                    self.player = 2

                else:
                    self.image = self.image = pygame.image.load(
                        convertpath.path(
                            ['Martial Hero', 'Sprites',
                             'bullet.png'])).convert()
                    self.player = 1
                self.image.set_colorkey(self.image.get_at((0, 0)))

                self.oppo, self.parent = self.parent, self.oppo

            else:
                self.oppo.take_damage(Blue.damage_2, self.x)
                Bullet.bullets.remove(self)
                del self
        elif self.rect.right < 0 or self.rect.left > SIZE[0]:
            del self
Exemple #2
0
 def __init__(self, filename, v=0.5, loop=0):
     self.volume = v
     self.right_channel = 0.5
     path = convertpath.path(['sounds', filename])
     self.mix = pygame.mixer.Sound(path)
     self.channel = pygame.mixer.find_channel()
     self.channel.play(self.mix, loops=loop)
     self.channel.set_volume(self.volume)
Exemple #3
0
 def __init__(self, surface, h):
     self.y = -50
     self.h = h
     self.surface = surface
     self.image = pygame.image.load(
         convertpath.path(['sprites', 'meteor.png'])).convert()
     self.image.set_colorkey(self.image.get_at((0, 0)))
     self.image = pygame.transform.scale(self.image, (100, 100))
     self.rect = self.image.get_rect()
     self.rect.center = self.surface.get_rect().center
     self.rect.bottom = self.y
Exemple #4
0
def blit_chess(surface, path, anchor, pos, size=None):
    image = pygame.image.load(convertpath.path(path)).convert()
    if size:
        image = pygame.transform.scale(image, size)

    rect = image.get_rect()
    if anchor == "center":
        rect.center = pos
    elif anchor == "topleft":
        rect.topleft = pos
    surface.blit(image, rect)
Exemple #5
0
def blit_image(surface, path, anchor, pos, size=None):
    image = pygame.image.load(convertpath.path(path)).convert()
    if size:
        image = pygame.transform.scale(image, size)
    image.set_colorkey(image.get_at((0, 0)))
    #     image.set_colorkey(BLACK)
    rect = image.get_rect()
    if anchor == "center":
        rect.center = pos
    elif anchor == "topleft":
        rect.topleft = pos
    surface.blit(image, rect)
Exemple #6
0
 def __init__(self, player, parent, oppo):
     pygame.sprite.Sprite.__init__(self)
     Bullet.bullets.append(self)
     self.dir = parent.dir
     self.parent = parent
     self.oppo = oppo
     self.player = player
     if player == 2:
         self.image = pygame.image.load(
             convertpath.path(['Martial Hero 2', 'Sprites',
                               'bullet.png'])).convert()
     else:
         self.image = pygame.image.load(
             convertpath.path(['Martial Hero', 'Sprites',
                               'bullet.png'])).convert()
     self.image.set_colorkey(self.image.get_at((0, 0)))
     if self.dir:
         self.x, self.y = parent.rect.midright
         self.rect = self.image.get_rect()
         self.rect.midleft = (self.x - 100, self.y)
     else:
         self.x, self.y = parent.rect.midleft
         self.rect = self.image.get_rect()
         self.rect.midright = (self.x + 100, self.y)
Exemple #7
0
    def __init__(self, sprite_path, x, y, parent):
        pygame.sprite.Sprite.__init__(self)
        self.x = x
        self.y = y
        self.cd1 = 20
        self.cd2 = 50
        self.t1 = self.cd1
        self.t2 = self.cd2
        self.speed = 10
        self.path = sprite_path
        self.parent = parent
        self.rect = None
        self.animation = 0
        self.dir = True
        self.timer = 0
        self.loop = False
        self.knockback = 0
        self.jump_power = self.max_jump
        self.images = []
        self.already = False
        for i in [
                'Idle', 'Attack1', 'Attack2', 'Jump', 'Fall', 'Run',
                'Take hit', 'Death'
        ]:
            self.images.append(
                pygame.image.load(convertpath.path(sprite_path +
                                                   [f'{i}.png'])).convert())

        self.frames = 0
        #         for i in range(len(self.images)):
        #             self.images[i].set_colorkey(self.images[i].get_at((0,0)))
        # self.animations = [[pygame.Rect(80, 70, 36, 59)],
        #                             [pygame.Rect(472, 69, 41, 53), pygame.Rect(673, 69, 41, 53), pygame.Rect(882, 53, 109, 69), pygame.Rect(107, 69, 1082, 53)]
        #         ]
        self.animations = [
            [pygame.Rect(80, 70, 36, 59)],
            [
                pygame.Rect(76, 63, 30, 65),
                pygame.Rect(271, 63, 35, 65),
                pygame.Rect(493, 68, 90, 60),
                pygame.Rect(693, 74, 34, 54)
            ],
            [
                pygame.Rect(82, 77, 45, 51),
                pygame.Rect(279, 72, 49, 56),
                pygame.Rect(490, 43, 96, 83),
                pygame.Rect(693, 86, 72, 42)
            ], [pygame.Rect(86, 72, 36, 56),
                pygame.Rect(286, 73, 36, 54)],
            [pygame.Rect(83, 75, 36, 53),
             pygame.Rect(283, 74, 37, 54)],
            [
                pygame.Rect(72, 81, 44, 47),
                pygame.Rect(272, 81, 44, 47),
                pygame.Rect(472, 81, 44, 47),
                pygame.Rect(672, 81, 44, 47),
                pygame.Rect(872, 81, 44, 47),
                pygame.Rect(1072, 81, 44, 47),
                pygame.Rect(1272, 81, 44, 47),
                pygame.Rect(1472, 81, 44, 47)
            ],
            [
                pygame.Rect(80, 71, 36, 55),
                pygame.Rect(280, 72, 30, 56),
                pygame.Rect(481, 72, 33, 56)
            ],
            [
                pygame.Rect(82, 72, 32, 56),
                pygame.Rect(284, 76, 33, 51),
                pygame.Rect(489, 86, 38, 41),
                pygame.Rect(686, 82, 33, 46),
                pygame.Rect(887, 91, 54, 36),
                pygame.Rect(1088, 114, 74, 13),
                pygame.Rect(1287, 120, 74, 8)
            ]
        ]
        self.animate(IDLE)