def __init__(self, name, width, height, count):
        super(SpriteSheet, self).__init__()

        self.name = name

        self.frame = 0

        self.motion_types = MotionType().get_all()
        self.motion_type = 0

        self.facing = 0

        self.sprite = None
        self.sprite_surface = None

        self.sprite_size = width, height

        self.sprites_path = {}

        self.images = {}
        self.surfaces = {}
        self.surfaces_size = {}
        self.surfaces_with = []
        self.surfaces_height = 0

        for k, v in self.motion_types.items():
            LOG.debug(f"filename {self.name}_{k}.png")
            path = RESOURCES.get_path(f"{self.name}_{k}.png")

            mt = self.motion_types[k]
            LOG.debug(f"motion_type: {mt}")
            # for k, v in self.sprites_path.items():
            self.images[mt] = load_image(path)
            self.surfaces_size[mt] = self.images[mt].w, self.images[mt].h
            self.surfaces_with = self.images[mt].w
            self.surfaces_height = self.images[mt].h

            LOG.debug(f"WIDHT {self.surfaces_with}")
            LOG.debug(f"HEIGHT {self.surfaces_height}")

            new_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
                                               self.surfaces_with,
                                               self.surfaces_height, 32,
                                               0x000000FF, 0x0000FF00,
                                               0x00FF0000, 0xFF000000)

            i = 0
            for filename, surface in self.images.items():
                vertical_offset = i * self.images[filename].h
                rect = SDL_Rect(0, vertical_offset, self.images[filename].w,
                                self.images[filename].h)
                SDL_BlitSurface(surface, None, new_surface, rect)
                i += 1
            self.surfaces[mt] = new_surface

        LOG.debug(f"SURFACE {self.surfaces}")
Beispiel #2
0
    def __init__(self, name):
        super(SpriteSheet, self).__init__()

        self.name = name

        self.frame = 0

        self.motion_types = MotionType().get_all()
        self.motion_type = 0

        self.facing = 0

        self.sprite = None
        self.sprite_surface = None

        self.sprite_size = 128, 128

        self.sprites_path = {}

        for k, v in self.motion_types.items():
            self.sprites_path[v] = RESOURCES.get_path("{0}_{1}.png".format(
                self.name, k))

        self.surfaces = {}
        self.surfaces_size = {}
        self.surfaces_with = []
        self.surfaces_height = 0

        for k, v in self.sprites_path.items():
            self.surfaces[k] = load_image(v)
            self.surfaces_size[k] = self.surfaces[k].w, self.surfaces[k].h
            self.surfaces_with.append(self.surfaces[k].w)
            self.surfaces_height += self.surfaces[k].h
            self.surface_height = self.surfaces[k].h

        self.surfaces_with = max(self.surfaces_with)

        self.surface = SDL_CreateRGBSurface(SDL_SWSURFACE, self.surfaces_with,
                                            self.surfaces_height, 32,
                                            0x000000FF, 0x0000FF00, 0x00FF0000,
                                            0xFF000000)
        i = 0
        for filename, surface in self.surfaces.items():
            vertical_offset = i * self.surfaces[filename].h
            rect = SDL_Rect(0, vertical_offset, self.surfaces[filename].w,
                            self.surfaces[filename].h)
            SDL_BlitSurface(surface, None, self.surface, rect)
            i += 1
Beispiel #3
0
    def __init__(self, world, sprite, posx=0, posy=0):
        super(Player, self).__init__()

        self.sprite = sprite
        self.sprite.position = posx, posy

        self.frames = Frames()
        self.motiontype = MotionType()
        self.facing = Facing()
        self.velocity = Velocity()

        self.playerdata = PlayerData()
Beispiel #4
0
    def __init__(self, world, sprite, posx=0, posy=0):
        super(Horse, self).__init__()

        self.sprite = sprite.get_sprite()
        self.sprite_data = sprite
        self.sprite.position = posx, posy

        self.frames = Frames()
        self.motiontype = MotionType()
        self.facing = Facing()
        self.velocity = Velocity()

        self.horse_data = HorseData()
Beispiel #5
0
class SpriteSheet:
    """ Sprite sheet """
    def __init__(self, name):
        super(SpriteSheet, self).__init__()

        self.name = name

        self.frame = 0

        self.motion_types = MotionType().get_all()
        self.motion_type = 0

        self.facing = 0

        self.sprite = None
        self.sprite_surface = None

        self.sprite_size = 128, 128

        self.sprites_path = {}

        for k, v in self.motion_types.items():
            self.sprites_path[v] = RESOURCES.get_path("{0}_{1}.png".format(
                self.name, k))

        self.surfaces = {}
        self.surfaces_size = {}
        self.surfaces_with = []
        self.surfaces_height = 0

        for k, v in self.sprites_path.items():
            self.surfaces[k] = load_image(v)
            self.surfaces_size[k] = self.surfaces[k].w, self.surfaces[k].h
            self.surfaces_with.append(self.surfaces[k].w)
            self.surfaces_height += self.surfaces[k].h
            self.surface_height = self.surfaces[k].h

        self.surfaces_with = max(self.surfaces_with)

        self.surface = SDL_CreateRGBSurface(SDL_SWSURFACE, self.surfaces_with,
                                            self.surfaces_height, 32,
                                            0x000000FF, 0x0000FF00, 0x00FF0000,
                                            0xFF000000)
        i = 0
        for filename, surface in self.surfaces.items():
            vertical_offset = i * self.surfaces[filename].h
            rect = SDL_Rect(0, vertical_offset, self.surfaces[filename].w,
                            self.surfaces[filename].h)
            SDL_BlitSurface(surface, None, self.surface, rect)
            i += 1

    def get_surface(self, frame, motion_type, facing):

        self.frame = frame
        self.motion_type = motion_type
        self.facing = facing

        crop = self.frame * self.sprite_size[0], \
            self.facing * self.sprite_size[1] + self.surface_height * self.motion_type, \
            self.sprite_size[0], self.sprite_size[1]

        self.sprite_surface = subsurface(self.surface.contents, crop)

        return self.sprite_surface

    def get_sprite(self):
        surface = self.get_surface(0, 0, 0)
        return SoftwareSprite(surface, True)

    def get_sprite_sheet_width(self, motion_type):
        return self.surfaces[motion_type].w