def __init__(self, filename): tm = load_pyglet(filename) self.size = tm.width * tm.tilewidth, tm.height * tm.tileheight self.tmx_data = tm self.batches = [] # list of batches, e.g. layers self.sprites = [] # container for tiles self.generate_sprites()
def __init__(self, window, filename): tm = load_pyglet(filename) self.size = tm.width * tm.tilewidth, tm.height * tm.tileheight self.tmx_data = tm self.window = window self.sprites = [] self.loadmap()
def __init__(self, window, keys, levelname): super(Level, self).__init__(window, keys) self.tiled_map = load_pyglet(levelname, invert_y=True) self.view = LevelView(self.window.width, self.window.height, self.tiled_map) self.collition_layer = self.tiled_map.get_layer_by_name('collision') self.startLocation = self.tiled_map.get_object_by_name('Starting Location') self.exitLocation = self.tiled_map.get_object_by_name('Exit Location') self.setupPlayer(self.startLocation)
from pytmx.util_pyglet import load_pyglet import pyglet from os import path tiled_map = load_pyglet('resources/map.tmx') MAP_WIDTH = tiled_map.width * tiled_map.tilewidth MAP_HEIGHT = tiled_map.height * tiled_map.tileheight TILE_WIDTH, TILE_HEIGHT = tiled_map.tilewidth, tiled_map.tileheight CHARACTERS = {'warrior'} UNITS_PIC = {} for name in CHARACTERS: UNITS_PIC[name] = pyglet.image.load(path.join("resources", name + '.png'))
def load(self, player_name, zone_source, players, monsters, npcs, containers, zone_data): # unload monsters for m in self.monsters.values(): m.unload() for p in self.players.values(): p.unload() for n in self.npcs.values(): n.unload() for s in self.spells: s.unload() # Load zone and save to cache if not self.zones.has_key(zone_source): # write zone_data to zone_source with open('client_data/zones/' + zone_source, 'w') as tmxfile: tmxfile.write(zone_data) self.zones[zone_source] = load_pyglet('client_data/zones/' + zone_source) self.zone = self.zones[zone_source] for layer in self.zone.layers: if layer.name == 'character' or layer.name == 'blocked' or layer.name == 'block' or layer.name == 'spawns': pass else: layer.batch = pyglet.graphics.Batch() layer.sprites = [] for x, y, image in layer.tiles(): y = self.zone.height - y - 1 sprite = pyglet.sprite.Sprite(image, x * self.zone.tilewidth, y * self.zone.tileheight, batch=layer.batch) layer.sprites.append(sprite) else: # Set zone from cache self.zone = self.zones[zone_source] self.player_name = player_name self.players = {} self.monsters = {} self.npcs = {} self.containers = {} self.offset = [] for name, player in players.items(): self.players[name] = Player(player['title'], player['gender'], player['body'], player['hairstyle'], player['haircolor'], player['armor'], player['head'], player['weapon'], player['x'], player['y']) for name, npc in npcs.items(): self.npcs[name] = Npc(npc['title'], npc['gender'], npc['body'], npc['hairstyle'], npc['haircolor'], npc['armor'], npc['head'], npc['weapon'], npc['x'], npc['y'], npc['villan']) for name, monster in monsters.items(): self.monsters[name] = Monster(monster['title'], monster['source'], monster['x'], monster['y']) for name, container in containers.items(): self.containers[name] = Container( container['title'], container['x'], container['y'], container['source'], container['source_w'], container['source_h'], container['source_x'], container['source_y']) # Set our label to green :) self.players[player_name].label.color = (0, 255, 0, 255)
def __init__(self, path): self.tmx = load_pyglet(path) assert self.tmx.orientation == 'orthogonal'