def __init__(self, x, y, color):
        super().__init__()

        self.frames = [[0, 0], [128, 0], [0, 128], [128, 128], [0, 256],
                       [128, 256]]
        self.index = 0
        self.tick_counter = 0
        self.animation_speed = 1

        self.h = 128
        self.w = 128

        self.color = color

        self.sprite_sheet = SpriteSheet("game/visualizer/assets/attack.png")

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        pa = pygame.PixelArray(self.image)
        pa.replace(pygame.Color(0, 0, 0, 255), self.color)
        del pa

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
    def __init__(self,
                 sprite_sheet_path,
                 frames,
                 x,
                 y,
                 h,
                 w,
                 animation_speed,
                 scale=1):
        super().__init__()

        self.frames = frames
        self.index = 0
        self.tick_counter = 0
        self.animation_speed = animation_speed
        self.scale = scale

        self.h = h
        self.w = w

        self.sprite_sheet = SpriteSheet(sprite_sheet_path)

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.image = pygame.transform.scale(
            self.image, (self.h * self.scale, self.w * self.scale))

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
class BackgroundSprite(pygame.sprite.Sprite):
    def __init__(self, sprite_sheet_path, frames, x, y, h, w, animation_speed):
        super().__init__()

        self.frames = frames
        self.index = 0
        self.tick_counter = 0
        self.animation_speed = animation_speed

        self.h = h
        self.w = w

        self.sprite_sheet = SpriteSheet(sprite_sheet_path)

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self):
        self.tick_counter += 1
        if self.tick_counter % self.animation_speed is 0:
            if self.index < len(self.frames) - 1:
                self.index += 1
            else:
                self.index = 0
        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)
示例#4
0
    def load_sprite(self):
        sprite_sheet = SpriteSheet("game/visualizer/assets/simple_ship.png")

        self.image = sprite_sheet.get_image(self.sprite_sheet_data[0],
                                            self.sprite_sheet_data[1],
                                            self.sprite_sheet_data[2],
                                            self.sprite_sheet_data[3])

        self.image_cache = self.image

        # Colorizing ship
        self.color = pygame.Color(self.raw_color.r, self.raw_color.g,
                                  self.raw_color.b, 255)

        d = 60
        self.color_2 = pygame.Color(
            self.color.r if self.color.r - d < 0 else self.color.r - d,
            self.color.g if self.color.g - d < 0 else self.color.g - d,
            self.color.b if self.color.b - d < 0 else self.color.b - d, 255)

        d = 100
        self.color_3 = pygame.Color(
            self.color.r if self.color.r - d < 0 else self.color.r - d,
            self.color.g if self.color.g - d < 0 else self.color.g - d,
            self.color.b if self.color.b - d < 0 else self.color.b - d, 255)

        pa = pygame.PixelArray(self.image)
        pa.replace(pygame.Color("#ffffff"), self.color)
        pa.replace(pygame.Color("#a5a5a5"), self.color_2)
        pa.replace(pygame.Color("#3c3c3c"), self.color_3)
        del pa
class SpecialAbilityAnimation(pygame.sprite.Sprite):
    def __init__(self,
                 sprite_sheet_path,
                 frames,
                 x,
                 y,
                 h,
                 w,
                 animation_speed,
                 scale=1,
                 repeat=1):
        super().__init__()

        self.frames = frames
        self.index = 0
        self.tick_counter = 0
        self.animation_speed = animation_speed

        self.h = h
        self.w = w

        self.scale = scale

        self.repeat = repeat

        self.sprite_sheet = SpriteSheet(sprite_sheet_path)

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.image = pygame.transform.scale(
            self.image, (self.h * self.scale, self.w * self.scale))

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self, obj):

        self.tick_counter += 1
        if self.tick_counter % self.animation_speed is 0:
            if self.index < len(self.frames) - 1:
                self.index += 1
            else:
                self.index = 0
                self.repeat -= 1

        if self.repeat <= 0:
            obj.remove(self)

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.image = pygame.transform.scale(
            self.image, (self.h * self.scale, self.w * self.scale))
    def __init__(self, x, y):
        super().__init__()

        sprite_sheet = SpriteSheet("game/visualizer/assets/icon_back.png")

        self.image = sprite_sheet.get_image(0, 0, 40, 40)

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
    def __init__(self, sprite_sheet_data, x, y):
        super().__init__()

        sprite_sheet = SpriteSheet(
            "game/visualizer/assets/unit_class_icons.png")

        self.image = sprite_sheet.get_image(sprite_sheet_data[0],
                                            sprite_sheet_data[1],
                                            sprite_sheet_data[2],
                                            sprite_sheet_data[3])

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
class AttackAnimation(pygame.sprite.Sprite):
    def __init__(self, x, y, color):
        super().__init__()

        self.frames = [[0, 0], [128, 0], [0, 128], [128, 128], [0, 256],
                       [128, 256]]
        self.index = 0
        self.tick_counter = 0
        self.animation_speed = 1

        self.h = 128
        self.w = 128

        self.color = color

        self.sprite_sheet = SpriteSheet("game/visualizer/assets/attack.png")

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        pa = pygame.PixelArray(self.image)
        pa.replace(pygame.Color(0, 0, 0, 255), self.color)
        del pa

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self, group):
        self.tick_counter += 1
        if self.tick_counter % self.animation_speed is 0:
            if self.index < len(self.frames) - 1:
                self.index += 1
            else:
                del self.image
                group.remove(self)

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)
        pa = pygame.PixelArray(self.image)
        pa.replace(pygame.Color(255, 255, 255, 255), self.color)
        d = 60
        r = self.color.r if self.color.r - d < 0 else self.color.r - d
        g = self.color.g if self.color.g - d < 0 else self.color.g - d
        b = self.color.b if self.color.b - d < 0 else self.color.b - d
        pa.replace(pygame.Color("#a5a5a5"), pygame.Color(r, g, b, 255))
        del pa
示例#9
0
    def __init__(self, sprite_sheet_data, x, y, station_id, color):
        super().__init__()

        sprite_sheet = SpriteSheet("game/visualizer/assets/simple_station.png")

        self.image = sprite_sheet.get_image(sprite_sheet_data[0],
                                            sprite_sheet_data[1],
                                            sprite_sheet_data[2],
                                            sprite_sheet_data[3])

        self.image_cache = self.image

        # Colorizing station
        self.color = pygame.Color(
            color.r,
            color.g,
            color.b,
            255
        )

        d = 60
        self.color_2 = pygame.Color(
            self.color.r if self.color.r-d < 0 else self.color.r-d,
            self.color.g if self.color.g-d < 0 else self.color.g-d,
            self.color.b if self.color.b-d < 0 else self.color.b-d,
            255
        )

        d = 100
        self.color_3 = pygame.Color(
            self.color.r if self.color.r-d < 0 else self.color.r-d,
            self.color.g if self.color.g-d < 0 else self.color.g-d,
            self.color.b if self.color.b-d < 0 else self.color.b-d,
            255
        )

        pa = pygame.PixelArray(self.image)
        pa.replace(pygame.Color("#ffffff"), self.color)
        pa.replace(pygame.Color("#a5a5a5"), self.color_2)
        pa.replace(pygame.Color("#3c3c3c"), self.color_3)
        del pa


        self.rect = self.image.get_rect()
        self.rect.center = world_to_display(x,y)
    def __init__(self, x, y, color):
        super().__init__()
        self.frames = [[0, 0], [128, 0], [256, 0], [384, 0], [0, 128],
                       [128, 128], [256, 128], [384, 128], [0, 256],
                       [128, 256], [256, 256], [384, 256], [0, 384]]

        self.index = 0
        self.tick_counter = 0
        self.animation_speed = 1

        self.h = 128
        self.w = 128

        self.sprite_sheet = SpriteSheet(
            "game/visualizer/assets/explosion_animation.png")

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.color = pygame.Color(color.r, color.g, color.b, 255)

        d = 60
        self.color_2 = pygame.Color(
            self.color.r if self.color.r - d < 0 else self.color.r - d,
            self.color.g if self.color.g - d < 0 else self.color.g - d,
            self.color.b if self.color.b - d < 0 else self.color.b - d, 255)

        d = 100
        self.color_3 = pygame.Color(
            self.color.r if self.color.r - d < 0 else self.color.r - d,
            self.color.g if self.color.g - d < 0 else self.color.g - d,
            self.color.b if self.color.b - d < 0 else self.color.b - d, 255)

        pa = pygame.PixelArray(self.image)
        pa.replace(pygame.Color("#ffffff"), self.color)
        pa.replace(pygame.Color("#a5a5a5"), self.color_2)
        pa.replace(pygame.Color("#3c3c3c"), self.color_3)
        del pa

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
    def __init__(self, sprite_sheet_data, x, y):
        super().__init__()

        sprite_sheet = SpriteSheet(
            "game/visualizer/assets/damage_type_icons.png")

        self.h = 32
        self.w = 32

        self.image = sprite_sheet.get_image(sprite_sheet_data[0],
                                            sprite_sheet_data[1],
                                            sprite_sheet_data[2],
                                            sprite_sheet_data[3])

        self.image = pygame.transform.scale(self.image,
                                            (self.h * 2, self.w * 2))

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
class UnitSprite(pygame.sprite.Sprite):
    def __init__(self, sprite_sheet_path, frames, x, y, h, w, animation_speed):
        super().__init__()

        self.frames = frames
        self.index = 0
        self.tick_counter = 0
        self.animation_speed = animation_speed

        self.h = h
        self.w = w

        self.sprite_sheet = SpriteSheet(sprite_sheet_path)

        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.image = pygame.transform.scale(self.image,
                                            (self.h * 2, self.w * 2))

        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self):
        self.tick_counter += 1
        if self.tick_counter % self.animation_speed is 0:
            if self.index < len(self.frames) - 1:
                self.index += 1
            else:
                self.index = 0
        self.image = self.sprite_sheet.get_image(self.frames[self.index][0],
                                                 self.frames[self.index][1],
                                                 self.h, self.w)

        self.image = pygame.transform.scale(
            self.image, (math.floor(self.h * 1.5), math.floor(self.w * 1.5)))