コード例 #1
0
        public T CreateMap()
        {
            var cave      = CellularAutomata.GenerateCaves(_width, _height, _density);
            var regionMap = MapFeatureDetector.GetRegions(cave);

            // Pick a random room to start and dig a tunnel to a random other room.
            // Go from there to another random room until all are connected.
            var roomCenters = GetRoomCenters(regionMap).ToList();
            var startPoint  = roomCenters[random.Next(roomCenters.Count)];

            roomCenters.Remove(startPoint);

            while (roomCenters.Count > 0)
            {
                var nextPoint = roomCenters[random.Next(roomCenters.Count)];
                roomCenters.Remove(nextPoint);
                cave       = CreatePath(cave, startPoint.X, startPoint.Y, nextPoint.X, nextPoint.Y);
                startPoint = nextPoint;
            }
            var map = new RogueSharp.Map(_width, _height);

            foreach (var cell in map.GetAllCells())
            {
                var open = cave[cell.X, cell.Y] == 0;
                map.SetCellProperties(cell.X, cell.Y, isTransparent: open, isWalkable: open, false);
            }

            return((T)(object)map);
        }
コード例 #2
0
ファイル: Level.cs プロジェクト: hotdiggitydoddo/axiom
		public static Level Generate(int width, int height)
		{
			DungeonGenerator.Instance.GenerateHauberkDungeon(width, height, 195000, 5, 5, 50, false, true);

			var tileData = DungeonGenerator._dungeon;
			var map = new Map (width, height);
			var tiles = new Tile[width, height];

			for (int x = 0; x < width; x++)
			{
				for (int y = 0; y < height; y++)
				{
					switch (tileData[x, y])
					{
						case TileType.Floor: 
							map.SetCellProperties (x, y, true, true); 
							break;
						case TileType.RoomFloor: 
							map.SetCellProperties(x, y, true, true); 
							break;
						case TileType.Wall: 
							map.SetCellProperties(x, y, false, false); 
							break;
						case TileType.Door: 
							map.SetCellProperties (x, y, false, false); 
							break;
					}
					tiles [x, y] = new Tile (tileData [x, y]);
				}
			}

			return new Level (map, tiles);
		}
コード例 #3
0
ファイル: GameLevel.cs プロジェクト: hotdiggitydoddo/Helios
        public static Level Generate(GameWorld world, int width, int height, TextureAtlas atlas, int cellSize)
        {
            DungeonGenerator.Instance.GenerateHauberkDungeon(width, height, 195000, 5, 5, 50, false, true);

            var tileData = DungeonGenerator._dungeon;
            var map = new Map(width, height);
            var tiles = new Tile[width, height];

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    Color color = Color.White;

                    switch (tileData[x, y])
                    {
                        case TileType.Floor:
                            map.SetCellProperties(x, y, true, true);
                            color = new Color(194, 194, 194);
                            break;
                        case TileType.RoomFloor:
                            map.SetCellProperties(x, y, true, true);
                            color = new Color(35, 255, 255);
                            break;
                        case TileType.Wall:
                            map.SetCellProperties(x, y, false, false);
                            color = new Color(163, 163, 163);
                            break;
                        case TileType.Door:
                            map.SetCellProperties(x, y, false, true);
                            color = new Color(132, 81, 0);
                            break;
                    }

                    tiles[x, y] = new Tile(tileData[x, y], color);
                    tiles[x, y].Cell = map.GetCell(x, y);
                }
            }

            var tilemap = new Tilemap(atlas, width, height, atlas.SpriteSize, cellSize, tiles);

            return new Level(world, map, tilemap);
        }
コード例 #4
0
        public CaveFloorMap(int width, int height)
        {
            this.random = new RogueSharp.Random.DotNetRandom();
            // If you specify width=20, RogueSharp's map x-index goes from 0..20 inclusive. That's not what we want. Hence, -1
            this.width  = width - 1;
            this.height = height - 1;

            var mapCreationStrategy = new RogueSharp.MapCreation.RandomRoomsMapCreationStrategy <RogueSharp.Map>(width, height, 100, 15, 4);

            //var mapCreationStrategy = new RogueSharp.MapCreation.CaveMapCreationStrategy<RogueSharp.Map>(width, height, 40, 2, 1);
            this.tileData = RogueSharp.Map.Create(mapCreationStrategy);

            this.stairsDown = new Entities.Stairs();
            this.stairsDown.Move(this.FindEmptyPosition());

            this.playerStartPosition = this.FindEmptyPosition();
            var distanceSquared = Math.Pow(Math.Min(this.width, this.height), 2);
            int tries           = 0;

            // Approximate distance must be the width of the map or more. Try it 100 times, then quit.
            while (tries <= 100 && Math.Pow(this.playerStartPosition.X - this.stairsDown.X, 2) + Math.Pow(this.playerStartPosition.Y - this.stairsDown.Y, 2) <= distanceSquared)
            {
                this.playerStartPosition = this.FindEmptyPosition();
                distanceSquared          = Math.Pow(Math.Min(this.width, this.height), 2);
                tries += 1;
            }

            if (random.Next(100) <= Config.Instance.Get <int>("PushPuzzleProbability"))
            {
                this.GeneratePushPuzzle();
            }

            this.GenerateLockedDoorsAndKeys();

            if (random.Next(100) <= Config.Instance.Get <int>("SwitchPuzzleProbability"))
            {
                this.GenerateSwitchPuzzle();
            }

            this.GenerateMonsters();
        }
コード例 #5
0
ファイル: Map.cs プロジェクト: hotdiggitydoddo/axiom
        public static Dungeon Generate(int width, int height)
        {
            DungeonGenerator.Instance.GenerateHauberkDungeon(width, height, 195000, 5, 5, 50, false, true);
            var tiles = DungeonGenerator._dungeon;
            var map = new RogueSharp.Map(width, height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    switch (tiles[x, y])
                    {
                        case TileType.Floor: map.SetCellProperties(x, y, true, true); break;
                        case TileType.RoomFloor: map.SetCellProperties(x, y, true, true); break;
                        case TileType.Wall: map.SetCellProperties(x, y, false, false); break;
                        case TileType.Door: map.SetCellProperties(x, y, false, false); break;
                    }
                }
            }
            return new Map(tiles, map);
        }
コード例 #6
0
ファイル: Map.cs プロジェクト: hybrid1969/RogueSharp
 /// <summary>
 /// Create and return a deep copy of an existing Map
 /// </summary>
 /// <returns>IMap deep copy of the original Map</returns>
 public IMap Clone()
 {
     var map = new Map( Width, Height );
      foreach ( Cell cell in GetAllCells() )
      {
     map.SetCellProperties( cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, cell.IsExplored );
      }
      return map;
 }