Exemplo n.º 1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public Game(ContentManager content, ReportProgressDelegate reporter = null)
        {
            ProgressReporter = reporter;

            ProgressReporter?.Invoke(0, "Loading Prefabs...");

            Content = content;

            var newMap = Content.Load <TiledMap>($"Maps/Prefabs");

            // Load tilesets
            foreach (var tileset in newMap.Tilesets)
            {
                Tilesets.Add(tileset);
            }

            foreach (var i in Tilesets)
            {
                int?anyLid = i.Tiles.FirstOrDefault(j => j.Properties.ContainsKey("name") && j.Properties["name"] == "BaseAny")?.LocalTileIdentifier;
                if (anyLid != null)
                {
                    BaseAnyTile = i.FirstGlobalIdentifier + anyLid.Value;
                }
                int?roadLid = i.Tiles.FirstOrDefault(j => j.Properties.ContainsKey("name") && j.Properties["name"] == "BaseRoad")?.LocalTileIdentifier;
                if (roadLid != null)
                {
                    BaseRoadTile = i.FirstGlobalIdentifier + roadLid.Value;
                }
                int?sidewalkLid = i.Tiles.FirstOrDefault(j => j.Properties.ContainsKey("name") && j.Properties["name"] == "BaseSidewalk")?.LocalTileIdentifier;
                if (sidewalkLid != null)
                {
                    BaseSidewalkTile = i.FirstGlobalIdentifier + sidewalkLid.Value;
                }
                int?wallLid = i.Tiles.FirstOrDefault(j => j.Properties.ContainsKey("name") && j.Properties["name"] == "BaseWall")?.LocalTileIdentifier;
                if (wallLid != null)
                {
                    BaseWallTile = i.FirstGlobalIdentifier + wallLid.Value;
                }

                foreach (var j in i.Tiles)
                {
                    TileByGid.Add(j.LocalTileIdentifier + i.FirstGlobalIdentifier, j);
                }
            }

            PrefabMap = newMap;

            GlobalMap = new MapTile[MetaTileWidth * MetaGlobalWidth, MetaTileHeight *MetaGlobalHeight];

            for (int ix = 0; ix < MapWidth; ++ix)
            {
                for (int iy = 0; iy < MapHeight; ++iy)
                {
                    var walkable = true;

                    GlobalMap[ix, iy] = new MapTile(Tilesets, BaseAnyTile);
                }
            }

            Player = new Player(GlobalMap, this);
            Actors.Add(Player);
            // Generate metamap

            ProgressReporter?.Invoke(10, "Building road network...");
            GenerateMetamap();
            PlayerStart = new XY(3 + MetaTileWidth * Metamap.GetLength(0) / 2, 3 + MetaTileHeight * Metamap.GetLength(1) / 2);
            ProgressReporter?.Invoke(20, "Generating map...");
            GenerateMap();
            ProgressReporter?.Invoke(90, "Placing mobs...");
            GenerateMobs();
            Player.Location = PlayerStart;
        }