public TileSet GetTileSet(TileContext context) { TileSet tileSheet = null; foreach (var sheet in _tileSets) { if (sheet.FirstGid > context.Tile.Gid) { break; } tileSheet = sheet; } return tileSheet ?? _tileSets.Last(); }
private void CreateWalls(TileContext context) { if (context.Tile.Gid == 0) { return; } var wallSheet = _spriteLibrary.GetTileSet(context); var correctedGid = context.Tile.Gid - wallSheet.FirstGid; var correctedWall = wallSheet.Tile.FirstOrDefault(x => x.Id == correctedGid); if (correctedWall != null) { var direction = correctedWall.Properties.FirstOrDefault(x => x.Name == "WallDirection"); if (direction != null) { GameObject wall = null; switch (direction.Value) { case WallDirection.Left: wall = Instantiate(LeftWall); break; case WallDirection.Top: wall = Instantiate(TopWall); break; case WallDirection.Corner: wall = Instantiate(CornerWall); break; } if (wall != null) { wall.transform.position = context.TilePosition; } } } }
private void CreateGround(TileContext context) { if (context.Tile.Gid <= 0) return; var floor = Instantiate(Floor); floor.transform.position = context.TilePosition; floor.GetComponentInChildren<Renderer>().material.SetTexture("_MainTex", _spriteLibrary.GetTexture(context.Tile.Gid)); }
private void CreateSpawns(TileContext context) { if (context.Tile.Gid == 0) { return; } var spawnSheet = _spriteLibrary.GetTileSet(context); var actualId = context.Tile.Gid - spawnSheet.FirstGid; switch (actualId) { case 0: var enemy = Instantiate(Enemy); enemy.transform.position = context.TilePosition; break; case 1: Player.transform.position = context.TilePosition; break; } }
private void BuildLevel(string levelName) { var map = XmlManager<Map>.Load("Assets/Resources/Levels/" + levelName + ".tmx"); _spriteLibrary.Generate(map.TileSets); var width = map.Width; var height = map.Height; foreach (var layer in map.Layer) { for (var z = 0; z < height; z++) { for (var x = 0; x < width; x++) { var tileContext = new TileContext { Tile = layer.Data[z * height + x], TilePosition = new Vector3(x, 0, -z) }; if (BuilderDefinitions.ContainsKey(layer.Name)) { BuilderDefinitions[layer.Name](tileContext); } } } } for (var i = 0; i < map.ObjectGroup.Length; i++) { var objectGroup = map.ObjectGroup[i]; if (objectGroup.Name == "BloodLayer") { LevelContext.BloodLayer = i; } else { BuildObjectGroup(objectGroup, i); } } AddWallCaps(map); }