Example #1
0
    def init(self, **kwargs):
        self.in_combat_with = []
        self.image = load_image(self.image_file)
        self.sprite = Sprite(self.image, self.x, self.y)
        self.hp_image = load_image('app/assets/healthbar.png')
        self.hp_sprite = Sprite(self.hp_image, self.x + 1,
                                self.y + self.height + 5)
        self.set_sprite_render(self.group)
        self.stats = Stats(modifiers=self.stat_modifiers)

        entity_container = getattr(self.chunk, self.chunk_container)
        if self.chunk and self not in entity_container:
            entity_container.append(self)

        self.post_init(**kwargs)
Example #2
0
    def init(self, **kwargs):
        self.image = load_image(self.image_file)
        self.sprite = Sprite(self.image, self.x, self.y,
                             batch=self.batch, group=self.group)
        self.chunk.objects.append(self)

        clock.schedule_once(self.delete, self.timer)
Example #3
0
def load_sprites(filename, row, col, grid_mapping):
    grid = TextureGrid(ImageGrid(load_image(filename), row, col))
    sprites = {}
    index = 0

    for item in grid_mapping:
        if isinstance(item, Img):
            grid_index = get_grid_index(index, row, col)
            sprites[item.name] = grid[grid_index]
            index += 1
        elif isinstance(item, Anim):
            sprites[item.name] = Animation.from_image_sequence(
                [
                    grid[get_grid_index(index + offset, row, col)]
                    for offset in range(item.nb_frame)
                ],
                item.period,
                item.loop,
            )
            index += item.nb_frame
        elif isinstance(item, Skip):
            index += item.skip_nb
        else:
            raise WrongGridMappingError(item)

    return sprites
 def get_resource(self, path):
     if path.find('/') != -1:
         file_type = path.split('/')[0]
         if file_type == 'texts':
             if os.path.isfile(
                     os.path.join(self.base_dir,
                                  path + '-%s.txt' % self.language)):
                 return open(
                     os.path.join(self.base_dir,
                                  path + '-%s.txt' % self.language),
                     'r+').read()
             else:
                 return open(
                     os.path.join(self.base_dir, path + '-en_us.txt'),
                     'r+').read()
         elif file_type == 'textures':
             return load_image('image.png',
                               file=open(
                                   os.path.join(self.base_dir,
                                                path + '.png'), 'rb'))
         else:
             return json.load(
                 open(os.path.join(self.base_dir, path + '.json'),
                      'r+',
                      encoding='utf-8'))
     else:
         raise FileNotFoundError("No such resource: '%s'" % path)
Example #5
0
    def load(x, y, create=False):
        loaded_chunk = session.query(models.Chunk).filter_by(x=x, y=y).first()

        if loaded_chunk is None:
            if create:
                chunk = Chunk(x, y)
                chunk.build_blocks()
                chunk.save()
            else:
                return None
        else:
            chunk = Chunk.load_from_db_obj(loaded_chunk)

        if not os.path.isfile(chunk.img_file):
            chunk.build_img()

        bg_img = load_image(chunk.img_file)
        chunk.sprite = Sprite(bg_img,
                              0,
                              0,
                              batch=chunk.draw_batch,
                              group=chunk.background)

        chunk.set_walls()
        chunk.add_npcs(5)

        return chunk
Example #6
0
 def __init__(self, filepath, width, height):
     self._img_src = filepath
     self._height = height
     self._width = width
     self._grid = TextureGrid(ImageGrid(load_image(self._img_src), self._height, self._width))
     if self._grid[0].width != self._grid[0].height:
         raise Exception("Tiles must be quadratic!")
     self._tile_size = self._grid[0].width
 def get_pack_info(self):
     info = json.load(
         open(os.path.join(self.base_dir, 'pack.json'),
              'r+',
              encoding='utf-8'))
     image = load_image('pack.png',
                        file=open(os.path.join(self.base_dir, 'pack.png'),
                                  'rb'))
     return (info, image)
Example #8
0
 def get_resource(self, path):
     if path.find('/') != -1:
         file_type = path.split('/')[0]
         if file_type == 'texts':
             if (path + '-%s.txt' % self.language) in self._namelist:
                 return self.zipfile.open(path + '-%s.txt' % self.language).read()
             else:
                 return self.zipfile.open(path + '-en_us.txt' % self.language).read()
         elif file_type == 'textures':
             return load_image('image.png', file=self.zipfile.open(path + '.png'))
         else:
             return json.load(self.zipfile.open(path + '.json'))
     else:
         raise FileNotFoundError("No such resource: '%s'" % path)
Example #9
0
def load_texture(path,
                 min_filter=GL_LINEAR,
                 max_filter=GL_LINEAR,
                 wrap_s=GL_CLAMP_TO_EDGE,
                 wrap_t=GL_CLAMP_TO_EDGE):
    texture = load_image(path).get_texture()  # DIMENSIONS MUST BE POWER OF 2.
    glBindTexture(GL_TEXTURE_2D, texture.id)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, max_filter)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t)
    glBindTexture(GL_TEXTURE_2D, 0)
    return texture
Example #10
0
File: cube00.py Project: Knio/miru
from miru.core import Object
from miru.context import context
from miru.ext.geom import Cube, get_vlist
from miru.ui import Window
from miru.graphics import TextureBindGroup
from miru.camera import LightGroup, DirectionalLight
from miru.input import SimpleMouseControl

window = Window(800, 450)
context.window = window
context.osd.add_object(clock.ClockDisplay())
context.control = SimpleMouseControl()
context.camera.lights = LightGroup([
   DirectionalLight([1.0, 0.0, 1.0])])
tex = load_image('docs/demo/test.png').get_texture()

batch = Batch()
texture_group = TextureBindGroup(tex)
cube_geom = Cube()
get_vlist(cube_geom, batch, texture_group)

cube = Object(batch)
cube.angle.z = 15
context.add_object(cube)

v = 35
def update(dt):
    dy = dt * v
    cube.angle.x += dy
      - pyglet.app.run -> run
'''

import pyglet
# This import is more specific.  We can now refer to 
# `pyglet.window.Window` as just `Window`.
from pyglet.window import Window
# With the `as` keyword, we can rename an import to make it more 
# clear.  If it were just `load`, it wouldn't be clear to a person 
# reading it that it is an image we are loading.
from pyglet.image import load as load_image


window = Window()

paddle_image = load_image('paddle.png')
# By default, the anchor is in the bottom left of the image (0, 0). 
# Setting `anchor_x` to half of the images width will make the 
# cursor control the image from the center.
paddle_image.anchor_x = paddle_image.width / 2

# We can set the starting position of the sprite to (0, 10).  
# Normally, it defaults to (0, 0)
paddle_sprite = pyglet.sprite.Sprite(paddle_image, 0, 10)

@window.event
def on_draw():
    window.clear()
    paddle_sprite.draw()

@window.event
Example #12
0
File: combo01.py Project: Knio/miru
context.camera.pos= (0,1.25,4)
pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)

sky_img = pyglet.image.load(os.path.join(resource_base_path, sky_1))
sky_tex = sky_img.get_texture(rectangle=True, force_rectangle=True)
sky_batch = pyglet.graphics.Batch()
sky_shape = geom.Square(width=192, height=108, depth=0, tex=sky_tex)
sky_group = miru.graphics.TextureBindGroup(sky_tex, sky_tex.target, parent=None, gencoords=False)
sky_vlist = geom.get_vlist(sky_shape, sky_batch, sky_group)
sky_obj = miru.core.Object(sky_batch)
sky_obj.angle.x = 90
sky_obj.pos.y = 7
context.add_object(sky_obj)

skin_tex = load_image(os.path.join(resource_base_path, img_1)).get_texture()#rectangle=True, force_rectangle=True)
geom_batch = Batch()
tex_group = miru.graphics.TextureBindGroup(skin_tex, skin_tex.target, parent=None, gencoords=False)
geom_mesh = geom.Cube()
geom_mesh.texcoord_data = [
    0.245, 0.505, 0.245, 0.745, 0.005, 0.746, 0.005, 0.505, # left 
    0.495, 0.755, 0.495, 0.995, 0.255, 0.995, 0.255, 0.755, # back 
    0.745, 0.505, 0.745, 0.745, 0.505, 0.745, 0.505, 0.505, # right
    0.255, 0.745, 0.255, 0.505, 0.495, 0.505, 0.495, 0.745, # top
    0.255, 0.245, 0.255, 0.005, 0.495, 0.005, 0.495, 0.245, # bottom
    0.255, 0.495, 0.255, 0.255, 0.495, 0.255, 0.495, 0.495 ] # front

#cube_geom.texcoord_data = [
    #0.333, 0.500, 0.333, 0.750, 0.000, 0.750, 0.000, 0.500, #left
    #0.667, 0.750, 0.667, 1.000, 0.333, 1.000, 0.333, 0.750, #back
    #1.000, 0.500, 1.000, 0.750, 0.667, 0.750, 0.667, 0.500, #right
Example #13
0
File: cube02.py Project: Knio/miru
from miru.core import Object
from miru.input import SimpleMouseControl
from miru.ui import Window
from miru.context import context
from miru.ext.geom import Cube, get_vlist
from miru.graphics import TextureBindGroup
from miru.camera import LightGroup, DirectionalLight

window = Window(800,450)
context.window = window
context.osd.add_object(clock.ClockDisplay())
context.control = SimpleMouseControl()
context.camera.lights = LightGroup([
   DirectionalLight(pos=[1.0,1.0,0.5])])
tex = load_image('docs/demo/cross.png').get_texture()

batch = Batch()
texture_group = TextureBindGroup(tex)

cube_geom = Cube()
cube_geom.texcoord_data = [
    0.245, 0.505, 0.245, 0.745, 0.005, 0.746, 0.005, 0.505, # left 
    0.495, 0.755, 0.495, 0.995, 0.255, 0.995, 0.255, 0.755, # back 
    0.745, 0.505, 0.745, 0.745, 0.505, 0.745, 0.505, 0.505, # right
    0.255, 0.745, 0.255, 0.505, 0.495, 0.505, 0.495, 0.745, # top
    0.255, 0.245, 0.255, 0.005, 0.495, 0.005, 0.495, 0.245, # bottom
    0.255, 0.495, 0.255, 0.255, 0.495, 0.255, 0.495, 0.495 ] # front
vlist = get_vlist(cube_geom, batch, texture_group)
slider = deque(vlist.tex_coords)
Example #14
0
 def get_pack_info(self):
     info = json.load(self.zipfile.open('pack.json'))
     image = load_image('pack.png', file=self.zipfile.open('pack.png'))
     return (info, image)
Example #15
0
         [0, 1, 2, 3]]
Vertices = [
    -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1,
    -1, 1, -1
]
FacesScale = [[FaceSize, 1, FaceSize], [1, FaceSize, FaceSize],
              [FaceSize, FaceSize, 1], [1, FaceSize, FaceSize],
              [FaceSize, FaceSize, 1], [FaceSize, 1, FaceSize]]

# Color and texture configuration
Colors = [[30, 30, 30], [255, 255, 255], [0, 100, 50], [150, 0, 0],
          [0, 50, 155], [230, 100, 0], [255, 255, 0]]
Background = [0.3, 0.3, 0.3, 1]

TextureUV = [[0, 0], [0, 1.0], [1.0, 1.0], [1.0, 0]]
TextureMask = load_image('resources/mask.png').get_texture()
RoundedCube = load_wavefront('resources/rounded_cube.obj')

# Axis, front face and rotation direction for animation
Animation = {
    'L': {
        'axis': 0,
        'face': -1,
        'dir': -1
    },
    'M': {
        'axis': 0,
        'face': 0,
        'dir': -1
    },
    'R': {
'''

from pyglet.window import Window
from pyglet.image import load as load_image
from pyglet.sprite import Sprite
from pyglet.clock import schedule_interval
from pyglet.app import run

from physics.collision import get_exit_direction
from physics.vector import Vector
from physics.rect import Rect


window = Window()

paddle_image = load_image('paddle.png')
paddle_sprite = Sprite(paddle_image, 0, 10)

ball_image = load_image('ball.png')
ball_sprite = Sprite(ball_image, 10, 300)
ball_velocity = Vector.new(50, -50)

left_wall = Rect.new(0, 0, 0, window.height)
top_wall = Rect.new(0, window.height, window.width, 0)
right_wall = Rect.new(window.width, 0, 0, window.height)

walls = [left_wall, top_wall, right_wall, paddle_sprite]

@window.event
def on_draw():
    window.clear()
Example #17
0
    def __init__(self):
        self.map = None
        self.layout = None
        self.end_staircase = None
        self.stage = 1
        self.game_window = None
        self.pc = None
        self.next_stage = False
        self.move_timeout = True
        self.timeout_limit = 1  # sekundy
        self.enemies = set()
        self.consumables = set()
        self.equippables = set()
        self.sprites = Batch()
        self.items = Batch()
        self.stages = 5
        self.cell_size = 5
        self.width = 45  # w tile-ach, wielokrotność 3*sell_size
        self.height = 30  # wielokrotność cell_size
        self.status_bar = None
        self.difficulty = 0
        self.groups = [OrderedGroup(0), OrderedGroup(1)]

        self.tileset = TextureGrid(ImageGrid(load_image('img/tiles.png'), 5,
                                             5))

        self.tile_textures = {
            'floor': self.tileset.get(4, 0).get_image_data(),
            'wall': self.tileset.get(4, 1).get_image_data(),
            'bars': self.tileset.get(4, 2).get_image_data(),
            'rubble': self.tileset.get(4, 3).get_image_data(),
            'stairs': self.tileset.get(4, 4).get_image_data(),
        }

        self.sprite_textures = {
            'bandit_dig': self.tileset.get(0, 0),
            'bandit_disg': self.tileset.get(0, 1),
            'bandit_fierce': self.tileset.get(0, 2),
            'bandit_wander': self.tileset.get(0, 3),
            'bandit_wary': self.tileset.get(0, 4),
            'bandit_aggr': self.tileset.get(1, 2),
            'bandit_coward': self.tileset.get(1, 3),
            'bandit_def': self.tileset.get(1, 4),
            'guard_glass': self.tileset.get(1, 0),
            'guard_unlk': self.tileset.get(1, 1),
            'guard': self.tileset.get(2, 0),
            'guard_angry': self.tileset.get(2, 1),
            'guard_blnk': self.tileset.get(2, 2),
            'guard_chase': self.tileset.get(2, 3),
            'guard_def': self.tileset.get(2, 4),
            'player': self.tileset.get(3, 0),
            'player_h': self.tileset.get(3, 1),
            'player_d': self.tileset.get(3, 2),
            'player_dh': self.tileset.get(3, 3),
            'item': self.tileset.get(3, 4),
        }

        self.sounds = {
            'player_hit': StaticSource(load_media('sound/player_hit.wav')),
            'bandit_hit': StaticSource(load_media('sound/bandit_hit.wav')),
            'guard_hit': StaticSource(load_media('sound/guard_hit.wav')),
        }