def __init__(self,x,y): self.x = x self.y = y self.mode = '_' self.texes = [resource.image("MC/"+fn+".png") for fn in "idle;back;back1;back2;front;front1;front2;run1;run2;run3".split(';')] \ + [resource.image("MC/"+fn+".png",flip_x=True) for fn in "run1;run2;run3".split(";")] for _ in self.texes: _.anchor_x = _.width//2 _.anchor_y = _.height//2 self.texes = [[self.texes[0]],self.texes[1:4],self.texes[4:7],self.texes[7:10],self.texes[10:]] self.texnum = 0.0
def __set_movement_image(self): """ Changes sprite image depending of spaceship movement """ if self.target.velocity[0] > 0: self.target.image = resource.image( 'data/sprites/spaceship/right4.png') elif self.target.velocity[0] < 0: self.target.image = resource.image( 'data/sprites/spaceship/left4.png') else: self.target.image = resource.image( 'data/sprites/spaceship/center.png')
def __init__(self, x, y, img_fname, flip_x=False, color=None, opacity=None, batch=None): if flip_x: super(Item, self).__init__(img=resource.image(name=img_fname, flip_x=True), x=SPRITE_WIDTH*(x+1), y=SPRITE_HEIGHT*y, batch=batch) else: super(Item, self).__init__(img=resource.image(name=img_fname), x=SPRITE_WIDTH*x, y=SPRITE_HEIGHT*y, batch=batch) if color is not None: self.color = color if opacity is not None: self.opacity = opacity self._x_units, self._y_units = x, y
def __init__(self,x,y,c,l): self.gx = x self.gy = y self.x = x//2 if x!=1 else rand(0,1) self.y = 240 self.mode = -3 self.texes = [resource.image("sellers/"+"bry"[c]+fn+".png") for fn in "cry;front;frontwalk1;frontwalk2;hit;walk1;walk2;".split(';')]\ + [resource.image("sellers/"+"bry"[c]+fn+".png",flip_x=True) for fn in "walk1;walk2;".split(';')] for _ in self.texes: _.anchor_x = _.width//2 _.anchor_y = _.height//2 self.life = (1,2,3,5,10)[l] self.texnum = 0.0
def grabFrame(self): """ this version of grab frame asumes the timing information is in the clip xml node and extrapolates image number based on time """ #this version does not allow for "freezing" on last frame and requires looping otherwise returns None -> nothing is drawn #todo implement freezing, this should be a either a CLIP property or a GRAPHNODE property that overrides whatever the CLIP property is n = self.grabFrameNumber() if int(n) <= int(self.xml.getAttribute("frames"))-1: #print stupid.splitjoin(self.xml.getAttribute("folder")+self.xml.getAttribute("prefix")+n.zfill(5)+".jpg") return resource.image(stupid.splitjoin(self.xml.getAttribute("folder")+self.xml.getAttribute("prefix")+n.zfill(5)+".png")) #return the last frame in the clip if we specify freeze = True if self.freeze: n = str(int(self.xml.getAttribute("frames"))-1) return resource.image(stupid.splitjoin(self.xml.getAttribute("folder")+self.xml.getAttribute("prefix")+n.zfill(5)+".png")) return None
def __init__(self, runner): super().__init__(runner, width=512, height=512) tile = image('tile.png') tile.anchor_x = 32 tile.anchor_y = 32 self.sprite = Sprite(img=tile, x=0, y=0)
def __init__(self, posx, posy, image=None): self.posx = posx self.posy = posy self.right = False self.left = False self.up = False self.down = False self.image_angle = 0 self.spd = 0 self.velx = 0 self.vely = 0 self.scaling = False self.scale_spd = 0 self.angle = 0 if image != None: # self.image = pyglet.image.load(image) self.image = resource.image(image) self.image.anchor_x = self.image.width // 2 self.image.anchor_y = self.image.height // 2 # https://gamedev.stackexchange.com/questions/20297/how-can-i-resize-pixel-art-in-pyglet-without-making-it-blurry self.sprite = pyglet.sprite.Sprite(self.image, x=self.posx, y=self.posy) gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
def player_character_update(self, dt): self.player_character.update(dt) if self.player_xscale > 0: self.player_character.sprite.x = self.player.sprite.x - self.player.sprite.width/2 self.player_character.sprite.y = self.player.sprite.y - self.player.sprite.height/2 else: self.player_character.sprite.x = self.player.sprite.x + self.player.sprite.width/2 self.player_character.sprite.y = self.player.sprite.y - self.player.sprite.height/2 self.player_character.sprite.scale_x = self.player_xscale self.player_character.sprite.scale_y = self.player_yscale if self.sprite_change_occured: if self.player_moving: image = 'player_running.png' else: image = 'player_idle.png' player = resource.image(image) player_seq = pyglet.image.ImageGrid(player, 1, int(player.width/32), item_width=32, item_height=32) player_texture = pyglet.image.TextureGrid(player_seq) player_anim = pyglet.image.Animation.from_image_sequence(player_texture[0:], 0.1, loop=True) player_sprite = pyglet.sprite.Sprite(player_anim, x = self.player_character.sprite.x, y = self.player_character.sprite.y) player_sprite.scale_x = self.player_xscale player_sprite.scale_y = self.player_yscale self.player_character.sprite = player_sprite self.sprite_change_occured = False
def load(self): centre = Vector(self.size.width/2, self.size.height/2) image = centre_image(resource.image("lattyware.png")) self.logo = sprite.Sprite(image, centre.x, centre.y) self.logo.opacity = 0 self.fade = 0 self.fade_in = True
def __init__(self, client, points=9, eye=1, wait=1, randomize=1, auto=0, speed=1, level=3): super(CalibrationLayer, self).__init__(0, 0, 255, 255) self.client = client self.points = points self.eye = eye self.wait = wait self.randomize = randomize self.auto = auto self.speed = speed self.level = level self.on_success = None self.on_failure = None self.window = director.window.get_size() self.screen = director.get_window_size() self.center_x = self.screen[0] / 2 self.center_y = self.screen[1] / 2 self.win_scale = (self.screen[0] / self.window[0], self.screen[1] / self.window[1]) self.font = font.load("Cut Outs for 3D FX", 32) self.circle_img = self.font.get_glyphs("E")[0].get_texture(True) self.circle_img.anchor_x = "center" self.circle_img.anchor_y = "center" self.pnt_img = self.font.get_glyphs("Y")[0].get_texture(True) self.pnt_img.anchor_x = "center" self.pnt_img.anchor_y = "center" self.circle = Sprite(self.circle_img, color=(255, 255, 0), scale=1, opacity=0) self.spinner = Sprite( resource.image("spinner.png"), position=(self.screen[0] / 2, self.screen[1] / 2), color=(255, 255, 255) )
def __init__(self, *args, image=image('assets/blue_box.png'), **kwargs): super().__init__(image, **kwargs) self.__dict__.update(kwargs) self.aim_cursor = AimCursor(mouse_angle=0.00, player_x=self.cx, player_y=self.cy) # Setup Player Movement self.max_velocity = 10 self.vel_x = 0 self.vel_y = 0 self.acceleration = 2 self.quad_coefficient = 0.15 self.animation_time = 5 self.is_jumping = False self.is_falling = False self.quadrant_setup = False # Setup Mouse self.mouse_angle = 0 self.mouse_dx = 0 self.mouse_dy = 0 self.mouse_velocity = 4 # Setup Physics self.gravity = 5 self.mass = 5 self.terminal_velocity = self.max_velocity * self.gravity self.max_jumps = 2 self.jumps = 0 self.keys_pressed = {}
def __init__(self, window, bus, title='Welcome to tabulr', draw_waves=False): """ Initialize the Scene object. :param window: Pyglet window object. Must be same throughout application. :param bus: Event bus. Used for communicating scene changes to main application thread. """ self.window = window self.window_title = title self.bus = bus self.batch = Batch() self.margin = 36 self.sprites = {} self.inputs = [] # Error message self.error_msg = Text('', size=12, bold=True, batch=self.batch, x=self.margin, color=(236, 64, 122, 255)) self.error_elapsed = 0 self.error_opacity = 0 # Waves background if draw_waves: waves_img = image('side-waves.png') waves_img.anchor_x = waves_img.width waves = Sprite(waves_img, x=window.width, y=0, batch=self.batch) waves.opacity = 160 self.init_sprite('waves', waves, is_button=False)
def __init__(self, window, bus): super().__init__(window, bus) self.title = Text('Welcome to', batch=self.batch, x=self.margin, y=(self.window.height // 2) + 100) self.title_bold = Text('tabulr', bold=True, batch=self.batch, x=self.margin, y=(self.window.height // 2) + 60) self.subtitle = Text( 'Your schedule, from list to wallpaper. Like magic.', size=12, batch=self.batch, x=self.margin, y=self.window.height // 2) self.init_sprite( 'next_button', Button('next', self.window, self.batch, x=self.margin, y=(self.window.height // 2) - 100)) waves = Sprite(image('front-waves.png'), x=0, y=-30, batch=self.batch) waves.opacity = 140 self.elapsed = 0 self.init_sprite('waves', waves, is_button=False)
def get_texture(fname): cache = ImageCache.cache tex = cache.get(fname, None) if not tex: tex = resource.image(fname).texture ImageCache.cache[fname] = tex return tex
def _load(filename, key, anchor=False): cache = ImageCache.cache value = resource.image(filename) if anchor: value.anchor_x = value.width / 2 value.anchor_y = value.height / 2 cache[key] = value
def load(self): self.batch = graphics.Batch() self.background = graphics.OrderedGroup(0) self.stars = Stars(Size(2000, 2000), self.batch, self.background) centre = Vector(self.size.width/2, self.size.height/2) image = centre_image(resource.image("win.png")) self.logo = sprite.Sprite(image, centre.x, centre.y)
def __init__(self, i, j, pix_size, info): if info['relief'] == self.WATER: self.tile = Tile('water', info, image('h_water.png')) elif info['relief'] == self.SOIL: a = randint(-10, 7) a = '' if (a <= 0) else a self.tile = Tile('soil', info, image('h_earth' + str(a) + '.png')) elif info['relief'] == self.CITY: self.tile = Tile('sity', info, image('h_town1.png')) elif info['relief'] == self.BASE: a = info['player'] self.tile = Tile('base', {}, image('h_castle' + str(a) + '.png')) self.army = None HexCell.__init__(self, i, j, None, pix_size, info, self.tile) self.properties['capacity'] = self.start_capacity
def _load_multi(filename, labels, rows, columns, anchor=False): cache = ImageCache.cache multiimage = image.ImageGrid(resource.image(filename), rows, columns) for key, texture in zip(labels, multiimage): if anchor: texture.anchor_x = texture.width / 2 texture.anchor_y = texture.height / 2 cache[key] = texture
def load_sprite_animation(name, action, frames=8, duration=0.1): " Creates an animation from files in the assets folder " images = [resource.image("assets/%s/%s%d.png" % (name, action, i)) for i in range(1, frames + 1)] for image in images: image.anchor_x = image.width / 2 frames = [AnimationFrame(i, duration) for i in images] return Animation(frames)
def __init__(self): self.x = 850 self.y = 550 self.img = resource.image('sun.png') self.img.anchor_x = self.img.width / 2 self.img.anchor_y = self.img.height / 2 self.rotation = 0 pyglet.clock.schedule(self.update)
def __init__(self): super(BgLayer, self).__init__(176, 233, 252, 255) try: self.img = Sprite(image('water.png')) self.img.position = [650, 400] self.add(self.img) except GLException: # Если невозможно загрузить задний план, то оставляем цветной фон pass
def load(self): resource.path = ["data"] resource.reindex() numbers = resource.image("numbers.png") self.numbers = {} width = numbers.width / 10 for n in xrange(0, 10): self.numbers[n] = numbers.get_region(n * width, 0, width, numbers.height)
def __init__(self,x,y): self.x = x self.y = y self.mode = 0 self.texes = [resource.image("voters/"+fn+".png") for fn in "sitblack;sitwhite".split(';')] for _ in self.texes: _.anchor_x = _.width//2 _.anchor_y = _.height//2 self.life = 10.0
def _load_images(self, tiles): self.tile_images = [] for path, solid in tiles: image = resource.image(path) image.solid = solid self.tile_images.append(image) self.tile_width = max(image.width for image in self.tile_images) self.tile_height = max(image.height for image in self.tile_images)
def load(self, key, filename=None, reindex=False): if filename is None: filename = "%s.png" % key if reindex: pyglet.resource.reindex() self[key] = resource.image(filename) self[key].anchor_x = 0 self[key].anchor_y = 0 return self[key]
def __init__(self, game, circle=None, margin=20): self.game = game self.planets = {} self.fleets = {} self.margin = margin self.circle = circle # images self.bk_img = resource.image(IMAGES['background']) self.bk_sprite = sprite.Sprite(self.bk_img)
def selectLevel(self, name): """ Maybe add more levels? """ self.bgimage = resource.image('images/'+name+'.jpg') map = self.buildMap(name) for building in map: b = rabbyt.Sprite(None, building[0]) b.xy = building[1] self.map_objects.append(b)
def __init__(self): super().__init__(255, 255, 255, 255) sprite_set = resource.image("spriteset.png") image_grid = image.ImageGrid(sprite_set, 6, 10) image0 = image_grid[54] self.add(Sprite(image0, (200, 150))) image1 = image_grid[(5, 4)].get_transform(flip_y=True) self.add(Sprite(image1, (300, 150)))
def img(name, xy=[0, 0], wh=[None, None], batch=None, group=0, anchorXY=False): obj = pyRes.image('res/img/' + name + '.png') if anchorXY: objAnchorXY(obj) model = pySpt.Sprite(obj, x=xy[0], y=xy[1], batch=batch, group=genGroup(group)) scale(model, wh) return model
def load_sprite_animation(name, action, frames=8, duration=0.1): " Creates an animation from files in the assets folder " images = [ resource.image("assets/%s/%s%d.png" % (name, action, i)) for i in range(1, frames + 1) ] for image in images: image.anchor_x = image.width / 2 frames = [AnimationFrame(i, duration) for i in images] return Animation(frames)
def __init__(self, path): """ Takes the :param:`path` , verifies its dimensions and sets it as texture. :param path: The path of the image """ self.image_name = path.split('/')[-1] self.image = resource.image(self.image_name).texture self.verify_dimensions() glGenerateMipmap(self.image.target)
def populated(self, populated): if not populated == self._populated: self._populated = populated if populated: name = self.type else: name = "raw_"+self.type self.sprite.image = centre_image(resource.image(name+".png")) if self.type == "home": #HACK self.sprite.visible = True
def load_rltile(self, name, path): badimg = image(path) badimgd = badimg.get_image_data() bad_rgba = badimgd.get_data('RGBA', badimgd.pitch) good_data = bad_rgba.replace('\xffGll', '\x00Gll') good_data = good_data.replace('\xff.', '\x00.') badimgd.set_data('RGBA', badimgd.pitch, good_data) rtex = badimgd.get_texture() rtex.name = name self.imgdict[name] = rtex return rtex
def __init__(self): self.screen = director.get_window_size() super(TaskBackground, self).__init__() img = resource.image('background.jpg') if self.screen[0] > 1600: scale = max(self.screen[0]/1600,self.screen[1]/1000) elif self.screen[0] < 1600: scale = min(self.screen[0]/1600,self.screen[1]/1000) s = Sprite(img,position=(self.screen[0]/2,self.screen[1]/2),scale=scale) self.add(s) self.add(ColorLayer(128,128,128,128),z=1)
def grabFrameOLD(self): """ this version of grabframe assumes that the clip xml node has all its images listed with their respective times. Use this version if you want to have a non constant speed animation. """ #TODO you should really make at least a local dict of image names to map becaus ethis loads the same image multiple times... #print self.xml,"frame","number",self.grabFrameNumber() framexml = utils.getChildWithAttribute(self.xml,"frame","number",self.grabFrameNumber()) if framexml: return resource.image(stupid.splitjoin(framexml.getAttribute("folder")+framexml.getAttribute("filename"))) else: return None
def load(cls): if hasattr(cls, 'images'): return cls.images = { 'healthbar-full': resource.image('healthbar-full.png'), 'healthbar-empty': resource.image('healthbar-empty.png'), 'healthbar': resource.image('healthbar.png'), 'ammo-revolver': resource.image('ammo-revolver.png'), 'ammo-bullet': resource.image('ammo-bullet.png'), 'ammo': resource.image('ammo.png'), 'goldmeter': resource.image('goldmeter.png'), 'goldmeterbar': resource.image('goldmeterbar.png'), }
def __init__(self, x, y, batch, group, space): self.speed = 10 self.group = PhysicsBodyGroup(group, self) self.sprite = sprite.Sprite(centre_image(resource.image("pushing.png")), 0, 0, batch=batch, group=self.group) self.body = Body(2, moment_for_circle(2, 5, 14)) self.body.position = x, y self.shape = Circle(self.body, 15) self.shape.elasticity = 0 self.shape.friction = 0.5 self.old = (0, 0) self.target = (x, y) space.add(self.body, self.shape)
def test_resource_image_loading(event_loop, transforms, result): """Test loading an image resource with possible transformations.""" resource.path.append('@' + __name__) resource.reindex() img = resource.image('rgbm.png', **transforms) w = event_loop.create_window(width=10, height=10) @w.event def on_draw(): # XXX For some reason original on_draw is not called w.clear() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) img.blit(img.anchor_x, img.anchor_y) event_loop.interrupt_event_loop() # Need to force multiple draws for platforms that do not support immediate drawing event_loop.run_event_loop() w._legacy_invalid = True event_loop.run_event_loop() w._legacy_invalid = True event_loop.run_event_loop() image_data = image.get_buffer_manager().get_color_buffer().get_image_data() pixels = image_data.get_data('RGBA', image_data.width * 4) def sample(x, y): i = y * image_data.pitch + x * len(image_data.format) r, g, b, _ = pixels[i:i + len(image_data.format)] if type(r) is str: r, g, b = list(map(ord, (r, g, b))) return { (255, 0, 0): 'r', (0, 255, 0): 'g', (0, 0, 255): 'b', (255, 0, 255): 'm' }.get((r, g, b), 'x') samples = ''.join([sample(3, 3), sample(3, 0), sample(0, 0), sample(0, 3)]) if samples == samples[2] * 4: # On retina displays the image buffer is twice the size of the coordinate system samples = ''.join( [sample(6, 6), sample(6, 0), sample(0, 0), sample(0, 6)]) assert samples == result
def __init__(self): self.screen = director.get_window_size() super(AgarLayer, self).__init__(255, 255, 255, 255, self.screen[0], self.screen[1]) #self.position = ((self.screen[0]-self.screen[1])/2,0) self.imgs = { 'cell': resource.image("cell.png"), 'virus': resource.image("virus.png"), 'agitated': resource.image("agitated.png") } self.circles = [] self.sprite_pool = [CellSprite(self.imgs) for _ in xrange(2500)] self.sprites = {} self.name_pool = [Label("", font_name='DejaVu Mono', font_size=6, bold=True, color=(255, 255, 255, 255), anchor_x='center', anchor_y='center') for _ in xrange(500)] self.names = {} self.score = 0 # self.leaders = [] self.win_size = Vec(self.screen[0], self.screen[1]) self.screen_center = self.win_size / 2 self.screen_scale = 1 self.world_center = Vec(0, 0) self.mouse_pos = Vec(0, 0) self.movement_delta = Vec() # self.names_batch = BatchNode() # self.add(self.names_batch) self.leaders_batch = BatchNode() diff = int(self.screen[1]*.01) text.Label("Leaderboard", font_size=24, font_name='DejaVu Mono Bold', x=self.screen[0]-160, y=self.screen[1]-30, bold=True, color=(255, 255, 255, 255), anchor_x='center', anchor_y='top', width=150, batch=self.leaders_batch.batch) self.leaders = [text.Label("%d. An unnamed cell" % (i+1), font_size=14, font_name='DejaVu Mono', x=self.screen[0]-160, y=self.screen[1]-40-30-i*22, color=(255, 255, 255, 255), anchor_x='center', anchor_y='top', width=150, batch=self.leaders_batch.batch) for i in xrange(10)] self.add(self.leaders_batch, z=100) self.sprite_batch = BatchNode() self.add(self.sprite_batch) self.scoreSprite = None self.proto = None leaderBG = ColorLayer(0,0,0,64,280,280) leaderBG.position = (self.screen[0]-300,self.screen[1]-300) self.add(leaderBG,z=50)
def __init__(self, *args, **kwargs): self.debug = kwargs.pop('debug', False) # super() must be called before setting dimmensions super().__init__(*args, **kwargs) global WINDOW_WIDTH, WINDOW_HEIGHT WINDOW_WIDTH = self.width WINDOW_HEIGHT = self.height self.key_handler = key.KeyStateHandler() self.push_handlers(self.key_handler) # 1. set up static sprites: must be first (bottom layer) self.sprites.append( pyglet.sprite.Sprite(resource.image('white.png'), 0, 0)) self.sprites.append(StarImageField(resource.image('star.jpg'))) self.asteroid_grid = pyglet.image.ImageGrid( resource.image('asteroids.png'), 8, 8) # 2. HUD hud_padding = 40 self.fps = pyglet.window.FPSDisplay(self) self.fps.label.y = WINDOW_HEIGHT - 40 self.elapsed_label = pyglet.text.Label(text='0', anchor_x='right', x=WINDOW_WIDTH - 10, y=hud_padding) # 3. player ship self.ship = Ship(resource.image('ship.png'), self.key_handler) self.push_handlers(self.ship.key_handler) self.sprites.append(self.ship) self.start_time = time.time() pyglet.clock.schedule_once(self.new_asteroids, 1) pyglet.clock.schedule_interval(self.update, 1 / 120.0)
def test_resource_image_loading(event_loop, transforms, result): """Test loading an image resource with possible transformations.""" resource.path.append('@' + __name__) resource.reindex() img = resource.image('rgbm.png', **transforms) window = event_loop.create_window() # Create a Framebuffer to render into: framebuffer = pyglet.image.buffer.Framebuffer() texture = pyglet.image.Texture.create(width=10, height=10, min_filter=GL_NEAREST, mag_filter=GL_NEAREST) framebuffer.attach_texture(texture) # Draw into the Framebuffer: framebuffer.bind() img.blit(img.anchor_x, img.anchor_y) framebuffer.unbind() # Check the pixels that were drawn: image_data = texture.get_image_data() pixels = image_data.get_data('RGBA', image_data.width * 4) def sample(x, y): i = y * image_data.pitch + x * len(image_data.format) r, g, b, _ = pixels[i:i + len(image_data.format)] if type(r) is str: r, g, b = list(map(ord, (r, g, b))) return { (255, 0, 0): 'r', (0, 255, 0): 'g', (0, 0, 255): 'b', (255, 0, 255): 'm' }.get((r, g, b), 'x') samples = ''.join([sample(3, 3), sample(3, 0), sample(0, 0), sample(0, 3)]) if samples == samples[2] * 4: # On retina displays the image buffer is twice the size of the coordinate system samples = ''.join( [sample(6, 6), sample(6, 0), sample(0, 0), sample(0, 6)]) assert samples == result
def __init__(self, window, bus): super().__init__(window, bus, draw_waves=False, title='tabulr | Done') # Check mark check_img = image('check.png') check_img.anchor_x = check_img.width // 2 check_img.anchor_y = check_img.height // 2 check_sprite = Sprite(check_img, x=self.window.width // 2, y=self.window.height // 2 + 120, batch=self.batch) check_sprite.scale = 0.5 self.init_sprite('check', check_sprite, is_button=False) # Text self.title = Text('Done', batch=self.batch, size=22, bold=True, x=self.window.width // 2, y=self.window.height // 3 + 72) self.subtitle = Text('Open the following file to save your wallpaper:', batch=self.batch, size=14, x=self.window.width // 2, y=self.window.height // 3 + 8) self.path = Text(abspath('htmlfile.html'), batch=self.batch, size=8, bold=True, x=self.window.width // 2, y=self.window.height // 3 - 16) self.title.anchor_x = 'center' self.subtitle.anchor_x = 'center' self.path.anchor_x = 'center' # Restart button restart_button = Button('restart', self.window, self.batch, x=self.window.width // 2, y=self.margin) restart_button.x -= restart_button.width // 2 self.init_sprite('restart_button', restart_button)
def __init__(self, client): super(CalibrationLayer, self).__init__(0, 0, 255, 255) self.client = client self.on_success = None self.on_failure = None self.window = director.window.get_size() self.screen = director.get_window_size() self.center_x = self.screen[0] / 2 self.center_y = self.screen[1] / 2 self.win_scale = (self.screen[0] / self.window[0], self.screen[1] / self.window[1]) self.font = font.load('Cut Outs for 3D FX', 32) circle_img = self.font.get_glyphs("E")[0].get_texture(True) circle_img.anchor_x = 'center' circle_img.anchor_y = 'center' self.circle = Sprite(circle_img, color=(255, 255, 0), scale=1, opacity=0) self.spinner = Sprite(resource.image('spinner.png'), position=(self.screen[0] / 2, self.screen[1] / 2), color=(255, 255, 255))
def __init__(self): self.screen = director.get_window_size() super(ACTRScrim, self).__init__(255, 0, 0, 255, self.screen[0], self.screen[1]) self.wait_connection = Label("Waiting for connection from ACT-R", position=(self.width / 2, self.height / 5 * 2), font_name='Pipe Dream', font_size=24, color=(0, 0, 0, 255), anchor_x='center', anchor_y='center') self.wait_model = Label("Waiting for ACT-R model to run", position=(self.width / 2, self.height / 5 * 2), font_name='Pipe Dream', font_size=24, color=(0, 0, 0, 255), anchor_x='center', anchor_y='center') self.spinner = Sprite(resource.image('spinner.png'), position=(self.width / 2, self.height / 5 * 3), color=(255, 255, 255)) self.spinner.do(Repeat(RotateBy(360, 1))) self.setWaitConnection()
def __init__(self, window, bus, course_manager): super().__init__(window, bus, draw_waves=False, title='tabulr | Generating') self.manager = course_manager self.generated = False # Spinner self.elapsed = 0 spinner_img = image('spinner.png') spinner_img.anchor_x = spinner_img.width // 2 spinner_img.anchor_y = spinner_img.height // 2 self.init_sprite('spinner', Sprite(spinner_img, x=self.window.width//2, y=self.window.height//2 + 72, batch=self.batch), is_button=False) # Text self.title = Text('Generating', batch=self.batch, size=22, bold=True, x=self.window.width//2, y=self.window.height//3 + 24) self.subtitle = Text('Hang tight!', batch=self.batch, size=14, x=self.window.width//2, y=self.window.height//3 - 24) self.title.anchor_x = 'center' self.subtitle.anchor_x = 'center'
def main_loop(self): self.push_handlers(window.event.WindowEventLogger()) image = resource.image("mandel.png") instructions_text = font.Text( font.load('Arial', 12), y=10 ) while not self.has_exit: self.dispatch_events() self.clear() image.blit(0,0) instructions_text.text = ("Welcome, click a point to begin your fractal journey") instructions_text.draw() self.flip()
def __init__(self, x, y, size, batch, group, space): x, y = x-size/2, y-size/2 points = randint(15, 20) self.batch = batch self.body = Body(size, moment_for_circle(size, 0, size)) self.body.position = x, y self.shape = Circle(self.body, 1.1*size) self.shape.elasticity = 0.35 self.shape.friction = 0.1 self.group = PhysicsBodyGroup(group, self) colour = list(chain.from_iterable(repeat(self.grey(), points))) self.points = list(self.construct_points(points, size)) self.vertex_list = batch.add( points, gl.GL_POLYGON, self.group, ('v2i', list(chain.from_iterable(self.points))), ('c3B', colour) ) self.body.angle = randint(0, int(maths.radians(360)/points)) self.type = self._weighted_random_choice(Asteroid.TYPES) self.sprite = sprite.Sprite(centre_image(resource.image("raw_"+self.type+".png")), 0, 0, batch=batch, group=self.group) self.sprite.visible = False self._populated = False space.add(self.body, self.shape)
def get_sprite_batch(self): """ Getter for a new sprite batch """ if self.sprite_batch is None: world = self.world unit = self.unit window = self.window sprites = self.sprites sprite_batch = Batch() floor_group = OrderedGroup(0) width = world.width height = world.height z = 0 for y in range(height): for x in range(width + (window.width // unit)): offset_x = x % width key = world.get_tile_key_from(offset_x, y, z) floor = world.get_tile_at(key, y) path = '{}.png'.format(floor.type) img_floor = image(path) calculated_x = x * unit calculated_y = y * unit sprite = Sprite(img_floor, x=calculated_x, y=calculated_y, batch=sprite_batch, group=floor_group) sprites[(x, y)] = sprite self.sprite_batch = sprite_batch return self.sprite_batch
from pyglet import window from pyglet import clock from pyglet import resource import spryte NUM_CARS = 100 if len(sys.argv) > 1: NUM_CARS = int(sys.argv[1]) win = window.Window(vsync=False) fps = clock.ClockDisplay(color=(1, 1, 1, 1)) cars = spryte.SpriteBatch() car = resource.image('car.png') car.anchor_x = 16 car.anchor_y = 20 for i in range(NUM_CARS): s = spryte.Sprite(car, win.width * random.random(), win.height * random.random(), batch=cars, dr=-45 + random.random() * 90) while not win.has_exit: win.dispatch_events() clock.tick() win.clear() for car in cars:
def __init__(self, filename, points): self.img = resource.image(filename) center_anchor(self.img) self.next_size = None self.points = points
def centered_image(image): """Loads an image and centers it""" image = resource.image(image) center(image) return image
class Image: resource.path.append("../res/image") resource.reindex() try: background = resource.image("background.png") menu = resource.image("menu.png") mario = resource.image("mario.png") sprite_set = resource.image("sprite_set.png") except resource.ResourceNotFoundException: raise SystemExit("cannot find images!") sprite_set_small = ImageGrid(sprite_set, 20, 20) sprite_set_big = ImageGrid(sprite_set, 10, 20) # mario mario_walk_right_small = [sprite_set_small[(18, 0)], sprite_set_small[(18, 1)], sprite_set_small[(18, 2)]] mario_walk_left_small = [image.get_transform(flip_x=True) for image in mario_walk_right_small] mario_walk_right_big = [sprite_set_big[(8, 0)], sprite_set_big[(8, 1)], sprite_set_big[(8, 2)]] mario_walk_left_big = [image.get_transform(flip_x=True) for image in mario_walk_right_big] mario_walk_right_fire = [sprite_set_big[(7, 0)], sprite_set_big[(7, 1)], sprite_set_big[(7, 2)]] mario_walk_left_fire = [image.get_transform(flip_x=True) for image in mario_walk_right_fire] mario_walk = [[mario_walk_right_small, mario_walk_left_small], [mario_walk_right_big, mario_walk_left_big], [mario_walk_right_fire, mario_walk_left_fire]] mario_jump_right_small = sprite_set_small[(18, 4)] mario_jump_left_small = mario_jump_right_small.get_transform(flip_x=True) mario_jump_right_big = sprite_set_big[(8, 4)] mario_jump_left_big = mario_jump_right_big.get_transform(flip_x=True) mario_jump_right_fire = sprite_set_big[(7, 4)] mario_jump_left_fire = mario_jump_right_fire.get_transform(flip_x=True) mario_jump = [[mario_jump_right_small, mario_jump_left_small], [mario_jump_right_big, mario_jump_left_big], [mario_jump_right_fire, mario_jump_left_fire]] mario_stand_right_small = sprite_set_small[(18, 6)] mario_stand_left_small = mario_stand_right_small.get_transform(flip_x=True) mario_stand_right_big = sprite_set_big[(8, 6)] mario_stand_left_big = mario_stand_right_big.get_transform(flip_x=True) mario_stand_right_fire = sprite_set_big[(7, 6)] mario_stand_left_fire = mario_stand_right_fire.get_transform(flip_x=True) mario_stand = [[mario_stand_right_small, mario_stand_left_small], [mario_stand_right_big, mario_stand_left_big], [mario_stand_right_fire, mario_stand_left_fire]] mario_die = sprite_set_small[(18, 5)] mario_walk_to_castle = [Animation.from_image_sequence(mario_walk_right_small, 0.1), Animation.from_image_sequence(mario_walk_right_big, 0.1), Animation.from_image_sequence(mario_walk_right_fire, 0.1)] mario_lower_flag_small = [sprite_set_small[(18, 7)], sprite_set_small[(18, 8)]] mario_lower_flag_big = [sprite_set_big[(8, 7)], sprite_set_big[(8, 8)]] mario_lower_flag_fire = [sprite_set_big[(7, 7)], sprite_set_big[(7, 8)]] mario_lower_flag = [Animation.from_image_sequence(mario_lower_flag_small, 0.2), Animation.from_image_sequence(mario_lower_flag_big, 0.2), Animation.from_image_sequence(mario_lower_flag_fire, 0.2)] mario_lower_flag_turn_around = [sprite_set_small[(18, 8)].get_transform(flip_x=True), sprite_set_big[(8, 8)].get_transform(flip_x=True), sprite_set_big[(7, 8)].get_transform(flip_x=True)] # prop normal_mushroom = sprite_set_small[(7, 0)] life_mushroom = sprite_set_small[(7, 1)] frames = [sprite_set_small[(5, 0)], sprite_set_small[(5, 1)]] fire_flower_blink = Animation.from_image_sequence(frames, 0.3) # enemy frames = [sprite_set_small[(10, 7)], sprite_set_small[(10, 8)]] goomba_move = Animation.from_image_sequence(frames, 0.3) goomba_die = sprite_set_small[(10, 9)] frames = [sprite_set_big[(5, 0)], sprite_set_big[(5, 1)]] koopa_move = Animation.from_image_sequence(frames, 0.3) koopa_die = sprite_set_small[(10, 4)] # others # cliff is a total transparent image cliff = sprite_set_small[(2, 2)] coin = sprite_set_big[(3, 4)] flag = sprite_set_small[(0, 0)] castle_flag = sprite_set_small[(2, 0)] normal_brick = sprite_set_small[(0, 3)] unknown_brick = sprite_set_small[(0, 6)] try: normal_brick2 = load("../res/image/brick.png") except Exception as e: raise SystemExit(e)
from pyglet import resource resource.path = ['./resources'] resource.reindex() x16_with_border = resource.image("cell16x16.png") x16_with_border.anchor_y = 16
def on_key_press(symbol, modifiers): global plyr_dx, plyr_dy if symbol == key.LEFT: plyr_dx = -plyr_speed plyr_dy = 0 elif symbol == key.RIGHT: plyr_dx = +plyr_speed plyr_dy = 0 elif symbol == key.UP: plyr_dy = +plyr_speed plyr_dx = 0 elif symbol == key.DOWN: plyr_dy = -plyr_speed plyr_dx = 0 resource.path = ['resources'] resource.reindex() player_img = resource.image("player.png") player_sprite = sprite.Sprite(img=player_img, x=500, y=500) plyr_speed = 100 plyr_dx = 0 plyr_dy = 0 clock.schedule_interval(update, 1 / 120) app.run()
def __init__(self, background): super(BackgroundLayer, self).__init__() self.image = resource.image(background)
# 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') font_m5x7 = font.load( 'm5x7') # Only assigned so it doesn't get garbage collected immediately