import pyglet from pyglet.resource import Loader import zipfile from client.ui.resloader import anim, bgm, get_atlas, img, imgdata_grid, img_grid, Resource, sound, subdir, texture, imgdata, lazytexture from client.ui.resloader import _ResourceDesc import os respath = os.path.join(os.path.dirname(__file__), 'res') # special case for font ldr = Loader(respath) fontzip = zipfile.ZipFile(ldr.file('font.zip')) font = { fn: fontzip.open(fn).read() for fn in fontzip.namelist() } fontzip.close() del fontzip, ldr class white(_ResourceDesc): __slots__ = ('name', ) def load(self, loader): atlas = get_atlas() white = atlas.add(pyglet.image.ImageData(4, 4, 'RGBA', '\xFF'*64)) c = white.tex_coords f = c[0:3]; t = c[6:9] white.tex_coords = ((f[0] + t[0]) / 2, (f[1] + t[1]) / 2, 0) * 4 return white
def __init__(self): self.__loader = Loader()
# -- stdlib -- from cStringIO import StringIO import hashlib import os # -- third party -- from PIL import Image from pyglet.resource import Loader import pyglet # -- own -- from settings import BASEDIR from utils import aes_decrypt # -- code -- loader = Loader(os.path.join(BASEDIR, 'resource')) inventory = [] loaders = {} resources = {} atlases = {} atlases['__default__'] = pyglet.image.atlas.TextureBin(1024, 1024) def get_atlas(atlas_name='__default__', atlas_size=(1024, 1024)): atlas = atlases.get(atlas_name) if not atlas: atlas = pyglet.image.atlas.TextureAtlas(*atlas_size) atlases[atlas_name] = atlas return atlas
# Molecule - a chemical reaction puzzle game # Copyright (C) 2013 Simon Norberg <*****@*****.**> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os from pyglet.resource import Loader loader = Loader("img", script_home=os.getcwd()) def load_image(name): img = loader.image(name) return img
class Resources: """Administra los recursos necesarios para el juego. Puede haber más de una ruta que contenga recursos. """ __loader = Loader() __RESOURCES_DIRECTORY = 'resources' __SPRITES_DIRECTORY = 'sprites' __HEAD_SPRITE = 'head.png' __SEGMENT_SPRITE = 'segment.png' __HEART_SPRITE = 'heart.gif' @staticmethod def load_sprites_path(): """Cargar la carpeta de sprites que se encuentra dentro del directorio principal. """ Resources.add_path( f'{Environment.paths.home}/{Resources.__RESOURCES_DIRECTORY}/'\ f'{Resources.__SPRITES_DIRECTORY}' ) @staticmethod def add_path(path: str): """Carga un directorio que debe contener recursos para el juego. Estos directorios deben existir y puede encontrarse en cualquier ubicación que tenga los permisos necesarios para ser leidos por el programa. Args: path (str): Ruta del directorio a cargar. """ if pathvalid.exists(path) and path not in Resources.__loader.path: Resources.__loader.path.append(path) Resources.__loader.reindex() @staticmethod def remove_path(path: str): """Descarta un directorio de recursos. Args: path (str): Ruta deldirectorio que se va a descartar. """ Resources.__loader.path.remove(path) Resources.__loader.reindex() @staticmethod def get_head_image(): """Carga la imagen que representa la cabeza del personaje principal. Returns: Texture: La cabeza de Quetzalcoatl. """ return Resources.__loader.image(Resources.__HEAD_SPRITE) @staticmethod def get_segment_image(): """Segmentos de los que se conforma el cuerpo del personaje principla. Returns: Texture: Segmento del cuerpo de Quetzalcoatl. """ return Resources.__loader.image(Resources.__SEGMENT_SPRITE) @staticmethod def get_heart_animation(): """Sprite animado que representa la comida de Qutzalcoatl: corazones. """ return Resources.__loader.animation(Resources.__HEART_SPRITE)
"fire_2.png", "fire_1.png", "fire_0.png", "fire_none.png", ] fire_image = [ "fire_3.png", "fire_4.png", "fire_6.png", "fire_7.png", "fire_8.png", ] effects = [] loader = Loader() loader.path = resources_paths loader.reindex() def create_effect(image_frames, duration=1.0, loop=False): frames = [] for img in image_frames: image = loader.image(img) frames.append(AnimationFrame(image, duration)) if loop is False: frames[len(image_frames) - 1].duration = None return Animation(frames=frames) def create_effect_animation(self, image_name, columns, rows):