示例#1
0
    def __init__(self):
        #super(Player, self).__init__(255,255,255,255)
        super(Player, self).__init__()

        self.sound = sound.SoundManager.instance()
        self.images = []
        self.images.append(pyglet.resource.image("img/player_up.png"))
        self.images.append(pyglet.resource.image("img/player_left.png"))
        self.images.append(pyglet.resource.image("img/player_down.png"))
        self.images.append(pyglet.resource.image("img/player_right.png"))
        for img in self.images:
            glTexParameteri(img.texture.target, GL_TEXTURE_MAG_FILTER,
                            GL_NEAREST)
            glTexParameteri(img.texture.target, GL_TEXTURE_MIN_FILTER,
                            GL_NEAREST)

        self.sprite = cocos.sprite.Sprite(
            self.images[gamelogic.DIRECTION_DOWN])

        (self.cell_x,
         self.cell_y) = gamelogic.Game.instance().get_start_point()
        self.sprite.position = self._get_drawing_coors()
        self.add(self.sprite)
        self.moving = False  # currently moving
        self.game = gamelogic.Game.instance()

        self.cheating = False
        self.controllable = True
        self.schedule(self.update)
示例#2
0
    def __init__(self):
        #super(Player, self).__init__(255,255,255,255)
        super(Player, self).__init__()

        self.sound = sound.SoundManager.instance()
        self.images = []
        self.images.append(pyglet.resource.image("img/player_up.png"))
        self.images.append(pyglet.resource.image("img/player_left.png"))
        self.images.append(pyglet.resource.image("img/player_down.png"))
        self.images.append(pyglet.resource.image("img/player_right.png"))
        for img in self.images :
            glTexParameteri(img.texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(img.texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        
        self.sprite = cocos.sprite.Sprite(self.images[gamelogic.DIRECTION_DOWN])

        (self.cell_x,self.cell_y) = gamelogic.Game.instance().get_start_point()
        self.sprite.position = self._get_drawing_coors()
        self.add(self.sprite)
        self.moving = False # currently moving
        self.game = gamelogic.Game.instance()

        self.cheating = False
        self.controllable = True
        self.schedule(self.update)
示例#3
0
def on_draw():
    window.clear()
    gl.glEnable(gl.GL_TEXTURE_2D)
    gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)

    if scene._current:
        scene._current.draw()
    fps_display.draw()
示例#4
0
 def __init__(self, maplayer):
     img = pyglet.resource.image("img/cloud.png")
     glTexParameteri(img.texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
     glTexParameteri(img.texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
     super(Storm, self).__init__(img)
     self.scale = 3
     self.maplayer = maplayer
     self.position = (-1000, 300)
示例#5
0
 def __init__(self) :
                             
     image = pyglet.resource.image("img/bomb.png")
     self.sounds = sound.SoundManager.instance()
    
     glTexParameteri(image.texture.target,
                     GL_TEXTURE_MAG_FILTER, GL_NEAREST)
     glTexParameteri(image.texture.target,
                     GL_TEXTURE_MIN_FILTER, GL_NEAREST)
     super(Bomb, self).__init__(image)
     self.position = (1000, 1000)
     self.game = gamelogic.Game.instance()
示例#6
0
    def __init__(self):

        image = pyglet.resource.image("img/bomb.png")
        self.sounds = sound.SoundManager.instance()

        glTexParameteri(image.texture.target, GL_TEXTURE_MAG_FILTER,
                        GL_NEAREST)
        glTexParameteri(image.texture.target, GL_TEXTURE_MIN_FILTER,
                        GL_NEAREST)
        super(Bomb, self).__init__(image)
        self.position = (1000, 1000)
        self.game = gamelogic.Game.instance()
示例#7
0
文件: main.py 项目: bagyr/DicePaint
 def compute(self):
     self.palette.new_palette()
     self.proc_img = process(self.test_image, self.palette())
     self.main_image = pil_to_pyg(self.proc_img)
     self.main_tex = self.main_image.get_texture()
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
     self.main_tex.width = 500
     self.main_tex.height = 500
     self.colors_widget = pil_to_pyg(colors_to_texture(self.palette()))
     self.colors_tex = self.colors_widget.get_texture()
     gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
     self.colors_tex.width = 100
     self.colors_tex.height = 500
示例#8
0
文件: tiles.py 项目: SMajev/blobjob
def imageatlas_factory(resource, tag):
    filename = resource.find_file(tag.get('file'))
    if not filename:
        raise ResourceError('No file= on <imageatlas> tag')
    atlas = pyglet.image.load(tag.get('file'))
    atlas.properties = _handle_properties(tag)
    if tag.get('id'):
        atlas.id = tag.get('id')
        resource.add_resource(atlas.id, atlas)

    # figure default size if specified
    if tag.get('size'):
        d_width, d_height = map(int, tag.get('size').split('x'))
    else:
        d_width = d_height = None

    for child in tag:
        if child.tag != 'image':
            raise ValueError, 'invalid child'

        if child.get('size'):
            width, height = map(int, child.get('size').split('x'))
        elif d_width is None:
            raise ValueError, 'atlas or subimage must specify size'
        else:
            width, height = d_width, d_height

        x, y = map(int, child.get('offset').split(','))
        image = atlas.get_region(x, y, width, height)

        # set texture clamping to avoid mis-rendering subpixel edges
        image.texture.id
        gl.glBindTexture(image.texture.target, image.texture.id)
        gl.glTexParameteri(image.texture.target,
            gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(image.texture.target,
            gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)

        # save the image off and set properties
        id = child.get('id')
        resource.add_resource(id, image)
        image.properties = _handle_properties(child)

    return atlas
示例#9
0
    def imshow(self, arr):
        from pyglet.gl import gl
        if self.window is None:
            height, width, _channels = arr.shape
            if width > self.maxwidth:
                scale = self.maxwidth / width
                width = int(scale * width)
                height = int(scale * height)
            self.window = pyglet.window.Window(width=width,
                                               height=height,
                                               display=self.display,
                                               vsync=False,
                                               resizable=True,
                                               caption=self.caption)
            self.width = width
            self.height = height
            self.isopen = True

            @self.window.event
            def on_resize(width, height):
                self.width = width
                self.height = height

            @self.window.event
            def on_close():
                self.isopen = False

        assert len(arr.shape
                   ) == 3, "You passed in an image with the wrong number shape"
        image = pyglet.image.ImageData(arr.shape[1],
                                       arr.shape[0],
                                       'RGB',
                                       arr.tobytes(),
                                       pitch=arr.shape[1] * -3)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER,
                           gl.GL_NEAREST)
        texture = image.get_texture()
        texture.width = self.width
        texture.height = self.height
        self.window.clear()
        self.window.switch_to()
        self.window.dispatch_events()
        texture.blit(0, 0)  # draw
        self.window.flip()
示例#10
0
    def __init__(self, position) :
        super(Enemy, self).__init__()
        self.sounds = sound.SoundManager.instance()

        self.images = []
        self.images.append(pyglet.resource.image("img/enemy_up.png"))
        self.images.append(pyglet.resource.image("img/enemy_left.png"))
        self.images.append(pyglet.resource.image("img/enemy_down.png"))
        self.images.append(pyglet.resource.image("img/enemy_right.png"))
        for img in self.images :
            glTexParameteri(img.texture.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(img.texture.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        
        self.sprite = cocos.sprite.Sprite(self.images[gamelogic.DIRECTION_DOWN])
        (self.cell_x,self.cell_y) = position
        self.sprite.position = self._get_drawing_coors()
        self.add(self.sprite)
        self.moving = False # currently moving
        self.game = gamelogic.Game.instance()

        self.schedule(self.update)
        self.target = self.__get_target()
示例#11
0
import pyglet
from pyglet import resource
from pyglet import sprite
from pyglet.gl import gl

gl.glEnable(gl.GL_TEXTURE_2D)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
pyglet.image.Texture.default_mag_filter = gl.GL_NEAREST
pyglet.image.Texture.default_min_filter = gl.GL_NEAREST

resource.path = ['../resources', '../resources/art', '../resources/sounds']
resource.reindex()

black = resource.image('black.png')
black_spr = sprite.Sprite(black, x=0, y=0)
grass_tile = resource.image('tile_test.png')
grass_spr = sprite.Sprite(grass_tile)