Beispiel #1
0
 def _draw_overlay(self):
     pattern = SolidColorImagePattern((0, 0, 0, 200))
     overlay_image = pattern.create_image(1000, 1000)
     overlay_image.anchor_x = overlay_image.width / 2
     overlay_image.anchor_y = overlay_image.height / 2
     overlay = Sprite(overlay_image, self.camera.x, self.camera.y)
     overlay.draw()
Beispiel #2
0
def get_white_texture():
    """Get a white texture, useful if a material does not provide a texture."""
    global white
    if white is None:
        fill = SolidColorImagePattern((255, 255, 255, 255))
        white = fill.create_image(1, 1).get_texture()
    return white
	def __init__(self, r=255, g=255, b=255, a=255, x=0, y=0, width=100, height=100,
	             batch=None, group=None, blend_src=gl.GL_SRC_ALPHA,
	             blend_dest=gl.GL_ONE_MINUS_SRC_ALPHA, usage='dynamic'):

		pattern = SolidColorImagePattern((int(r),int(g),int(b),int(a)))

		self._r = r
		self._g = g
		self._b = b
		self._a = a
		self._x = x
		self._y = y
		self._width = width
		self._height = height
		self._group = None
		self._batch = None
		self._blend_src = blend_src
		self._blend_dest = blend_dest
		self._usage = usage
		if batch is not None:
			self._batch = batch
		if group is not None:
			self._group = group

		super(Rectangle, self).__init__(
			pattern.create_image(width, height),
			x=self._x, y=self._y, batch=self._batch, group=self._group
		)
Beispiel #4
0
 def _draw_overlay(self):
     pattern = SolidColorImagePattern((0, 0, 0, 200))
     overlay_image = pattern.create_image(1000, 1000)
     overlay_image.anchor_x = overlay_image.width / 2
     overlay_image.anchor_y = overlay_image.height / 2
     overlay = Sprite(overlay_image, self.camera.x, self.camera.y)
     overlay.draw()
Beispiel #5
0
    def _draw_action_menu(self):
        pattern = SolidColorImagePattern((0, 0, 150, 200))
        overlay_image = pattern.create_image(1000, 200)
        overlay_image.anchor_x = overlay_image.width / 2
        overlay_image.anchor_y = overlay_image.height + 100
        overlay = Sprite(overlay_image, self.camera.x, self.camera.y)
        overlay.draw()

        self._generate_text()
Beispiel #6
0
    def _draw_action_menu(self):
        pattern = SolidColorImagePattern((0, 0, 150, 200))
        overlay_image = pattern.create_image(1000, 200)
        overlay_image.anchor_x = overlay_image.width / 2
        overlay_image.anchor_y = overlay_image.height + 100
        overlay = Sprite(overlay_image, self.camera.x, self.camera.y)
        overlay.draw()

        self._generate_text()
Beispiel #7
0
 def setUp(self):
     self.w = Window(width=1, height=1, visible=False)
     self.s = Sprite(
         10, 10, 10, 10,
         Image2d.from_image(
             SolidColorImagePattern((0, 0, 0, 0)).create_image(1, 1)))
     assert (self.s.x, self.s.y) == (10, 10)
Beispiel #8
0
 def _render_solid_colors(self, surface):
     black = pyglet.image.create(
         width=self.game.WIDTH,
         height=self.game.HEIGHT,
         pattern=SolidColorImagePattern(color=(0, 0, 0, 0xff)))
     offset = self.OFFSET
     black.blit_to_texture(surface.get_texture().target, 0, offset,
                           self.SCREEN_HEIGHT - self.game.HEIGHT - offset,
                           0)
Beispiel #9
0
    def bake_static_background(self):
        surface = pyglet.image.create(
            width=self.SCREEN_WIDTH,
            height=self.SCREEN_HEIGHT,
            pattern=SolidColorImagePattern(color=(0x5f, 0x57, 0x4f, 0xff)))

        self._render_solid_colors(surface)
        self._render_walls(surface)
        self._render_coins(surface)
        self.background = surface
Beispiel #10
0
def getPygeltColorMaps(step, height=1080, width=1440, suffix=""):
    """Return colormap in pyglet.image."""

    colormap = {}
    source = generateColorMapName(step)
    for name, array in source:
        r, g, b = [i if i < 256 else 255 for i in array]
        a = 255
        thename = name + suffix
        colormap[thename] = SolidColorImagePattern(
            (r, g, b, a)).create_image(width=width, height=height)

    source = [("white", (255, 255, 255)), ("black", (0, 0, 0))]
    for name, array in source:
        r, g, b = [i if i < 256 else 255 for i in array]
        a = 255
        colormap[name] = SolidColorImagePattern(
            (r, g, b, a)).create_image(width=1280, height=1080)

    logger.debug("generate colors: " + colormap.keys().__str__())
    return colormap
Beispiel #11
0
def generatePygletBWMap(height=1280, width=1024, L=50):
    """Generate image with a given function."""
    colormap = {}
    source = [("white", (255, 255, 255, 255)),
              ("black", (0, 0, 0, 255)),
              ("gray", (128, 128, 128, 255))]
    for name, array in source:
        r, g, b, a = array
        colormap[name] = SolidColorImagePattern((r, g, b, a)).create_image(
            width=width+2*L, height=height+2*L)

    return colormap  # {name: (image, speed)}
Beispiel #12
0
def getPygeltColorMaps(colornamefile, screensize=(1920, 1080, 3)):
    """Return colormap in pyglet.image."""
    with open(colornamefile, 'r') as f:
        content = f.read()
    logger.debug("read colormap file: " + colornamefile)

    colormap = {}
    for name, array in json.loads(content).items():
        r, g, b = array
        a = 255
        colormap[name] = SolidColorImagePattern((r, g, b, a)).create_image(
            width=screensize[0], height=screensize[1])

    logger.debug("generate colors: " + colormap.keys().__str__())
    return colormap
Beispiel #13
0
    def __init__(self,
                 tex_name,
                 tile_width,
                 tile_height,
                 game_state,
                 xpos=0,
                 ypos=0,
                 group=None,
                 health=3,
                 move_pattern=unlucky,
                 move_params=(),
                 name='enemy',
                 gold=1,
                 exp=1,
                 hitsound='bandit_hit',
                 damage=1):
        super().__init__(tex_name,
                         tile_width,
                         tile_height,
                         game_state,
                         xpos=xpos,
                         ypos=ypos,
                         group=group,
                         damage=damage,
                         health=health,
                         name=name,
                         hitsound=hitsound)

        self.is_guard = 'guard' in tex_name
        if type(move_pattern) == str:
            self.move_pattern = patterns[move_pattern](self, *move_params)
        else:
            self.move_pattern = move_pattern(self, *move_params)
        self.game.enemies.add(self)
        self.stats[G] = gold
        self.stats[EXP] = exp
        self.healthbar = Sprite(create(24, 4, SolidColorImagePattern(RED)),
                                x=self.x,
                                y=self.y,
                                batch=self.batch,
                                group=self.game.groups[1])
Beispiel #14
0
   def saveNormalMap( self, normals, filename ):
       siz = self.a-1
       from pyglet.image import SolidColorImagePattern
       c = 65, 65, 65, 65
       img = SolidColorImagePattern(c).create_image(siz, siz)
       img = img.get_image_data()
       
       toSave = lambda x : int(  (x+1)*127  )
       data2 = ""
 
       for i in xrange(0, siz**2*3, siz*3):
           for j in range(0, siz*3, 3):
               r, g, b = normals[i+j:i+j+3]
               r, g, b, a = toSave(r), toSave(g), toSave(b), 255
               data2 += chr(r) + chr(g) + chr(b) + chr(a)
       
       img.set_data('RGBA', img.width*4, data2)
       img.save('saved/{}.png'.format(filename))
Beispiel #15
0
 def saveHeightMap( self, filename):
     from pyglet.image import SolidColorImagePattern
     c = 65, 65, 65, 65
     img = SolidColorImagePattern(c).create_image(self.a, self.a)
     img = img.get_image_data()
     hm = self.hm
     mi = min([i for r in hm for i in r])
     ma = max([i for r in hm for i in r])
     print mi,ma
     height = ma - mi
     toSave = lambda x : int(  (x-mi)*255/height  )
     data2 = ""
     for i in range(self.a):
         for j in range(self.a):
             h = toSave( hm[i][j] )
             r, g, b, a = h, h, h, 255
             data2 += chr(r) + chr(g) + chr(b) + chr(a)
     img.set_data('RGBA', img.width*4, data2)
     img.save('saved/{}.png'.format(filename))
     with open('saved/{}.info'.format(filename), 'w') as file:
         file.write('mi={},ma={}'.format(mi, ma))
Beispiel #16
0
from pyglet import resource, font
from pyglet.image import SolidColorImagePattern

# Make our resource imports relative to the src/resources/ directory.
resource.path = ['resources']
resource.reindex()


def _set_anchor_center(img):
    """Centers the anchor point of img."""
    img.anchor_x = int(img.width / 2)
    img.anchor_y = int(img.height / 2)


player_image = SolidColorImagePattern(
    (255, 255, 255, 255)).create_image(32, 32)
_set_anchor_center(player_image)

enemy_pawn_image = resource.image('enemy/pawn.png')
_set_anchor_center(enemy_pawn_image)

enemy_slider_image = resource.image('enemy/slider.png')
_set_anchor_center(enemy_slider_image)

pellet_image = resource.image('pellet.png')
_set_anchor_center(pellet_image)

danger_image = resource.image('danger.png')
_set_anchor_center(danger_image)

resource.add_font('m5x7.ttf')
Beispiel #17
0
        else:
            p3 = Position(0, 0)
            p4 = other.get_size()
        if p2.x > p3.x and p4.x > p1.x and p2.y > p3.y and p4.y > p1.y:
            if fully:
                if (p2.x >= p4.x and p2.y >= p4.y and p3.x >= p1.x
                        and p3.y >= p1.y or p4.x >= p2.x and p4.y >= p2.y
                        and p1.x >= p3.x and p1.y >= p3.y):
                    return True
                return False
            return True
        return False


# make the apple
apple_img = SolidColorImagePattern((0, 255, 0, 255)).create_image(10, 10)
# round the apple
with PixelArray(apple_img) as apple_array:
    apple_array[0:3, 0] = (0, 0, 0, 0)
    apple_array[0:2, 1] = (0, 0, 0, 0)
    apple_array[0, 2] = (0, 0, 0, 0)
    apple_array[7:10, 0] = (0, 0, 0, 0)
    apple_array[8:10, 1] = (0, 0, 0, 0)
    apple_array[9:10, 2] = (0, 0, 0, 0)
    apple_array[0, 7] = (0, 0, 0, 0)
    apple_array[0:2, 8] = (0, 0, 0, 0)
    apple_array[0:3, 9] = (0, 0, 0, 0)
    apple_array[9, 7] = (0, 0, 0, 0)
    apple_array[8:10, 8] = (0, 0, 0, 0)
    apple_array[7:10, 9] = (0, 0, 0, 0)
# center the apple