def non_rigid_shapes_use_static_body_test(self): """ static shapes, like level geometry, should all use a common body, for performance reasons. the load_shape functions cannot handle shapes in this way since they do not have a reference to the space. a reference should be added, along with check to make sure the space is not none. - bitcraft """ space = pymunk.Space() all_good_tmxdata = load_tmx(join(self.path, "shapes_all_good.tmx")) shapes = load_shapes(all_good_tmxdata, space) self.assertTrue(len(shapes) > 0) for name, shape in shapes.items(): if name == "box2": self.assertIs(shape.body, space.static_body)
def load(level): """ Load level number from tmx file. """ levelfname = level + ".tmx" # first one is good for images. tmx = tmxloader.load_tmx( pyglet.resource.file(levelfname)) # this second one is good for scrolling background. maps = tmxreader.TileMapParser().parse_decode( pyglet.resource.file(levelfname)) return LevelLoader(tmx, maps)
# for platformer maps def toWorld(data, (x, y, z)): """ translate tiled map coordinates to world coordinates """ return z, x*data.tilewidth, (y-1)*data.tileheight # for zelda-style games #def toWorld(data, (x, y, l)): # """ translate tiled map coordinates to world coordinates """ # return y*data.tileheight, x*data.tilewidth, l area = PlatformArea() parent.add(area) area.setParent(parent) area.mappath = res.mapPath(mapname) data = tmxloader.load_tmx(area.mappath) for gid, prop in data.tile_properties.items(): try: prop['guid'] = int(prop['guid']) except KeyError: pass props = data.getTilePropertiesByLayer(-1) """ print "GID MAP:" for k in sorted(data.gidmap.keys()): print " {}: {}\t{}".format(k, data.gidmap[k], data.getTilePropertiesByGID(data.gidmap[k]))
def setUp(self): self.path = split(realpath(__file__))[0] self.tmxdata = load_tmx(join(self.path, "shapes.tmx")) self.objects_xml_path = join(self.path, "objects.xml") self.maxDiffDefault = self.maxDiff self.maxDiff = 1000
def munk_load_shapes_factory_mode_test(self): space = pymunk.Space() all_good_tmxdata = load_tmx(join(self.path, "shapes_all_good.tmx")) factory = load_shapes(all_good_tmxdata, space, factory_mode=True) self.assertIsInstance(factory, MunkModelFactory)
def load_shapes_with_global_defaults_test(self): space = pymunk.Space() all_good_tmxdata = load_tmx(join(self.path, "shapes_all_good.tmx")) shapes = load_shapes(all_good_tmxdata, space, self.objects_xml_path) self.assertEqual(12, len(shapes)) self.assertEqual(13, len(space._shapes))
def load_shapes_test(self): space = pymunk.Space() all_good_tmxdata = load_tmx(join(self.path, "shapes_all_good.tmx")) shapes = load_shapes(all_good_tmxdata, space) self.assertEqual(12, len(shapes)) self.assertEqual(13, len(space._shapes))
def fromTMX(parent, mapname): """Create a new area from a tmx map This body (called parent) must already be connected to the data tree, otherwise body loading will not work and area building will fail. """ def toWorld(data, (x, y, l)): """ translate tiled map coordinates to world coordinates """ return y * data.tileheight, x * data.tilewidth, l area = AdventureArea() parent.add(area) area.setParent(parent) area.mappath = res.mapPath(mapname) data = tmxloader.load_tmx(area.mappath) # set the boundries (extent) of this map area.setExtent(((0,0), \ (data.height * data.tileheight, data.width * data.tilewidth))) props = data.getTilePropertiesByLayer(-1) # load the level geometry and set it rects = [] for rect in tmxloader.buildDistributionRects(data, "Control", real_gid=1): # translate the tiled coordinates to world coordinates x, y, sx, sy = rect rects.append(Rect(y, x, sy, sx)) area.setLayerGeometry(4, rects)