コード例 #1
0
    private static LevelTiles CreateFrom(TiledFile tiledFile)
    {
        var level = new LevelTiles(tiledFile.width,
                                   tiledFile.height,
                                   tiledFile.tilewidth,
                                   tiledFile.tileheight);

        var background = tiledFile.layers.FirstOrDefault(l => l.name.Equals(Background));
        var platforms  = tiledFile.layers.FirstOrDefault(l => l.name.Equals(Platforms));

        var playerStartLayer = tiledFile.layers.FirstOrDefault(l => l.name.Equals(PlayerStart));

        if (!string.IsNullOrEmpty(playerStartLayer.name))
        {
            var playerSpawn = playerStartLayer.objects.FirstOrDefault(l => l.name.Equals(Spawn));
            if (!string.IsNullOrEmpty(playerSpawn.name))
            {
                level.SetPlayerStart(playerSpawn.x, playerSpawn.y);
            }
        }

        level.SetLayers(background, platforms);

        return(level);
    }
コード例 #2
0
        public override void LoadContent()
        {
            base.LoadContent();

            levelData = Engine.Instance.Content.Load <LevelData>("TestMap");
            tile.LoadContent(levelData);

            bool[,] collisionInfo = LevelTiler.TileConverison(tile.CollisionLayer, 513);
            tiles = new LevelTiles(collisionInfo);
            this.Add(tiles);

            player = new Player(tile.PlayerPosition[0]);
            this.Add(player);
            player.Added(this);

            initalizeMusic();
        }
コード例 #3
0
ファイル: Exporter.cs プロジェクト: lhbelfanti/mahjong
        public void Save(int level, int fillType, string path)
        {
            LevelData levelData = new LevelData();

            levelData.level      = level;
            levelData.fillMethod = fillType;
            levelData.data       = new List <LevelInfo>();

            for (int f = 0; f < _floorEditor.FloorsQuantity; f++)
            {
                LevelInfo levelInfo = new LevelInfo();
                levelInfo.floor = f;
                levelInfo.rows  = new List <LevelTiles>();
                for (int h = 0; h < _gridEditor.Height; h++)
                {
                    LevelTiles levelTiles = new LevelTiles();
                    levelTiles.tiles = new List <int>();
                    for (int w = 0; w < _gridEditor.Width; w++)
                    {
                        levelTiles.tiles.Add(_tiles[h, w, f]);
                    }

                    levelInfo.rows.Add(levelTiles);
                }

                levelData.data.Add(levelInfo);
            }


            string url = path == ""
                                ? $"{Application.dataPath}/Resources/{EditorLevelPath}.json"
                                : $"{path}level{level.ToString()}.json";

            JsonSerializerSettings settings = new JsonSerializerSettings {
                Formatting = Formatting.Indented,
            };

            settings.Converters.Add(new CustomJsonConverter());
            string levelDataJson = JsonConvert.SerializeObject(levelData, settings);

            System.IO.File.WriteAllText(url, levelDataJson);
        }
コード例 #4
0
        public override void LoadContent()
        {
            base.LoadContent();

            levelData = Engine.Instance.Content.Load <LevelData>("Arena");
            tile.LoadContent(levelData);

            bool[,] collisionInfo = LevelTiler.TileConverison(tile.CollisionLayer, 65);
            tiles = new LevelTiles(collisionInfo);
            this.Add(tiles);

            for (int i = 0; i < tile.PlayerPosition.Count; i++)
            {
                if (i == 0)
                {
                    players.Add(new Player1(tile.PlayerPosition[i], i, Color.Blue, GameTags.Player1,
                                            new Vector2(tile.MapWidthInPixels, tile.MapHeightInPixels)));
                }

                if (i == 1)
                {
                    players.Add(new Player2(tile.PlayerPosition[i], i, Color.Green, GameTags.Player2,
                                            new Vector2(tile.MapWidthInPixels, tile.MapHeightInPixels)));
                }
            }

            this.HelperEntity.Add(counters);
            this.Add(players);

            foreach (var player in players)
            {
                player.Added(this);
            }

            initalizeMusic();
        }