Beispiel #1
0
class Resources:
    """
    Administra los paths de los recursos que serán necesarios para un videojuego.
    """
    def __init__(self):
        self.__loader = Loader()


    def __str__(self):
        return f'Resources: {self.__loader.path}'


    def append_path(self, path:str, directory = ''):
        """
        Agrega un nuevo path a los recursos registrados.

        Args:
            path (str): Path donde se ecunetran los recursos, este campo puede ser la ruta absoluta a los recursos.
            directory (str, optional): Es el nombre del directorio que contiene a los recursos. Defaults to ''.
        """
        if path and path.strip() != '':
            self.__loader.path.append(f'{path}/{directory}' if directory and directory.strip() != '' else path)
            self.__loader.reindex()


    def append_sprites_path(self, path = '', directory = ''):
        """
        Agrega un nuevo path que debe contener sprites para un videojuego. El path default estará dado por el 
        directorio home del proyecto.

        Args:
            path (str, optional): Path donde se encuentran los sprites. Defaults to ''.
            directory (str, optional): directorio donde se encuentran los sprites. Defaults to ''.
        """
        self.append_path(path if path and path.strip() != '' else levbopaths.SPRITES_RESOURCE, directory)


    def get_image(self, file_name):
        """
        [summary]

        Args:
            file_name ([type]): [description]
        """
        return self.__loader.image(file_name)
Beispiel #2
0
from __future__ import division
from random import randint, choice
from itertools import chain, repeat
from logging import getLogger

from pyglet import gl
from pyglet import clock
from pyglet.event import EventDispatcher
from pyglet.resource import Loader
from pyglet.image import ImageGrid, TextureGrid, Animation
from pyglet.sprite import Sprite
from pyglet.graphics import Batch, TextureGroup

LOGGER = getLogger("defence.tilemap")
TILE_LOADER = Loader(["graphics/tiles"])

class TileLayerGroup(TextureGroup):
	def __init__(self, texture, translation=(0, 0), rotation=0):
		super(TileLayerGroup, self).__init__(texture)
		self.translation = translation
		self.rotation = rotation
	
	def set_state(self):
		super(TileLayerGroup, self).set_state()
		
		gl.glPushAttrib(gl.GL_COLOR_BUFFER_BIT)
		gl.glEnable(gl.GL_BLEND)
		gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
		
		x, y = self.translation
		
Beispiel #3
0
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
Beispiel #4
0
 def file(self, name, mode='rb'):
     return Loader.file(self, self.filename(name), mode)
Beispiel #5
0
 def __init__(self):
     self.__loader = Loader()
Beispiel #6
0
# -- 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
Beispiel #7
0
# 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
Beispiel #8
0
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)
Beispiel #9
0
    "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):
Beispiel #10
0
 def file(self, name, mode='rb'):
     return Loader.file(self, self.filename(name), mode)