示例#1
0
        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();
        }
示例#2
0
        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;
                    }
                }
            }
        }
示例#3
0
        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));
        }
示例#4
0
        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;
            }
        }
示例#5
0
        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);
        }