Пример #1
0
    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}")
Пример #2
0
    def __init__(self, lines, font_size):

        self.free = True

        border_sprite_sheet_path = RESOURCES.get_path("dialog_border.png")
        self.border_sprite_sheet = load_image(border_sprite_sheet_path)

        self.surface = self.create_surface(lines, font_size)

        super(DialogDecorations, self).__init__(self.surface.contents, self.free)
Пример #3
0
    def test_load_image(self):
        # TODO: add image comparision to check, if it actually does the
        # right thing (SDL2 BMP loaded image?)
        # Add argument tests
        try:
            import PIL
            _HASPIL = True
        except ImportError:
            _HASPIL = False

        fname = "surfacetest.%s"
        for fmt in formats:
            filename = RESOURCES.get_path(fname % fmt)
            sf = sdl2ext.load_image(filename)
            self.assertIsInstance(sf, surface.SDL_Surface)

            # Force only PIL
            if _HASPIL and fmt not in ("webp", "xcf", "lbm"):
                sf = sdl2ext.load_image(filename, enforce="PIL")
                self.assertIsInstance(sf, surface.SDL_Surface)

            # Force only sdlimage
            sf = sdl2ext.load_image(filename, enforce="SDL")
            self.assertIsInstance(sf, surface.SDL_Surface)
Пример #4
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
Пример #5
0
    def __init__(self, map_name):

        self.tile_sets = {}

        tm = TiledMap(map_name)
        self.size = tm.width * tm.tilewidth, tm.height * tm.tileheight
        self.tmx_data = tm
        self.position = [0, 0]

        tile_set_name = ""

        for tile in self.tmx_data.images:
            if tile is not None:
                tile_set = tile[0]
                tile_set_name = tile_set
                if tile_set not in self.tile_sets:
                    self.tile_sets[tile_set] = load_image(tile_set)

        self.tile_set = self.tile_sets[tile_set_name]

        """
        self.blocking_elements = []

        print("Objects in map:")
        for obj in self.tmx_data.objects:
            print(obj)
            print("BLOCK\t{0}".format(obj.points))
            for k, v in obj.properties.items():
                print("PROPS\t{0}\t{1}".format(k, v))
                if (k == "block") and (v == "true"):
                    print("FOUND BLOCK")
                    self.blocking_elements.append(obj)

        print("GID (tile) properties:")
        for k, v in self.tmx_data.tile_properties.items():
            print("{0}\t{1}".format(k, v))
        """

        self.bg_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
                                               self.size[0],
                                               self.size[1],
                                               32,
                                               0x000000FF,
                                               0x0000FF00,
                                               0x00FF0000,
                                               0xFF000000)
Пример #6
0
    def __init__(self, map_name):

        self.tile_sets = {}

        tm = TiledMap(map_name)
        self.size = tm.width * tm.tilewidth, tm.height * tm.tileheight
        self.tmx_data = tm
        self.position = [0, 0]

        for tile_set in self.tmx_data.tilesets:
            name = tile_set.name
            tile_set_path = MAPS.get_path("{0}.png".format(name))
            self.tile_sets[tile_set_path] = load_image(tile_set_path)
        """
        self.blocking_elements = []

        print("Objects in map:")
        for obj in self.tmx_data.objects:
            print(obj)
            print("BLOCK\t{0}".format(obj.points))
            for k, v in obj.properties.items():
                print("PROPS\t{0}\t{1}".format(k, v))
                if (k == "block") and (v == "true"):
                    print("FOUND BLOCK")
                    self.blocking_elements.append(obj)

        print("GID (tile) properties:")
        for k, v in self.tmx_data.tile_properties.items():
            print("{0}\t{1}".format(k, v))
        """

        layers = "background", "behind", "front"
        self.surfaces = {}

        for layer in layers:
            self.surfaces[layer] = SDL_CreateRGBSurface(
                SDL_SWSURFACE, self.size[0], self.size[1], 32, 0x000000FF,
                0x0000FF00, 0x00FF0000, 0xFF000000)
Пример #7
0
def texture_from_image(renderer, image_name):
    """Create an SDL2 Texture from an image file"""
    soft_surface = ext.load_image(image_name)
    texture = SDL_CreateTextureFromSurface(renderer.renderer, soft_surface)
    SDL_FreeSurface(soft_surface)
    return texture
Пример #8
0
def texture_from_image(renderer, image_name):
    """Create an SDL2 Texture from an image file"""
    soft_surface = ext.load_image(image_name)
    texture = SDL_CreateTextureFromSurface(renderer.renderer, soft_surface)
    SDL_FreeSurface(soft_surface)
    return texture
Пример #9
0
    if "images" not in json_data:
        json_data["images"] = {}

# Walk through the directtories and find all the files
    print("Searching for files.")
    print()
    for directory in namespace.directories:
        for root, dirs, files in os.walk(directory):
            for filename in files:
                split_name = os.path.splitext(filename)
                name = split_name[0]
                extension = split_name[-1][1:]
                file_path = os.path.join(root, filename)

                if extension in IMAGE_EXTENSIONS:
                    temp_surface = sdlext.load_image(file_path)
                    width = temp_surface.w
                    height = temp_surface.h
                    sdl2.SDL_FreeSurface(temp_surface)

                    if name in json_data["images"]:
                        if "path" not in json_data["images"][name]:
                            warnings.append(
                                "WARNING: Image \"" + name +
                                "\" has entry in index, but no \"path\" value. Fixed!"
                            )
                            json_data["images"][name]["path"] = file_path

                        elif json_data["images"][name]["path"] != file_path:
                            warnings.append(
                                "WARNING: Images \"" + name +