Beispiel #1
0
        private static DungeonMap GenerateDungeon(int width, int height)
        {
            // Same size as screen, but we set up to center the camera on the player so expanding beyond this should work fine with no other changes.
            var map = new DungeonMap(width, height);

            // Generate map via GoRogue, and update the real map with appropriate terrain.
            var tempMap = new ArrayMap <bool>(map.Width, map.Height);

            // QuickGenerators.GenerateDungeonMazeMap(tempMap, minRooms: 10, maxRooms: 20, roomMinSize: 5,
            //     roomMaxSize: 11);
            // QuickGenerators.GenerateRectangleMap(tempMap);
            // MapGenerators.GenerateBSPDungeon(tempMap);
            QuickGenerators.GenerateRandomRoomsMap(tempMap, 20, 7, 12);
            map.ApplyTerrainOverlay(tempMap, SpawnTerrain);

            Coord posToSpawn;

            // Spawn a few mock enemies
            for (int i = 0; i < 10; i++)
            {
                posToSpawn = map.WalkabilityView.RandomPosition(true); // Get a location that is walkable
                var zombie = Zombie.Create(Difficulties.NORMAL, posToSpawn);
                map.AddMonster(zombie);
            }

            // Spawn player
            posToSpawn           = map.WalkabilityView.RandomPosition(true);
            Game.Player.Position = posToSpawn;
            map.AddEntity(Game.Player);

            return(map);
        }
Beispiel #2
0
        public void TestRandomRoomsGenSize()
        {
            var map = new ArrayMap <bool>(40, 40);

            QuickGenerators.GenerateRandomRoomsMap(map, 30, 4, 6, 10);

            Console.WriteLine(map.ToString(b => b ? "." : "#"));
        }
Beispiel #3
0
        public void ManualTestRandomRoomsGen()
        {
            var random = new StandardGenerator();
            var map    = new ArrayMap <bool>(80, 50);

            QuickGenerators.GenerateRandomRoomsMap(map, random, 10, 4, 15, 5);

            displayMap(map);
            // TODO: Some assert here
        }
Beispiel #4
0
        private static void Main(string[] args)
        {
            Animations = new AnimationHandler();
            rand       = new Random();

            var engine = new Engine(Width, Height, "Gaserel", true, StepUpdate, Render, Animations);

            map = new Map(Width, Height, 1, Distance.MANHATTAN);
            ISettableMapView <bool> mapview = new ArrayMap <bool>(Width, Height);

            QuickGenerators.GenerateRandomRoomsMap(mapview, 20, 8, 20);
            map.ApplyTerrainOverlay(mapview, (pos, val) => val ? TerrainFactory.Floor(pos) : TerrainFactory.Wall(pos));

            _gasLayers = new List <GasInfo>()
            {
                new GasInfo(Width, Height, Color.Red),
                new GasInfo(Width, Height, Color.Blue),
                new GasInfo(Width, Height, Color.Green),
                new GasInfo(Width, Height, Color.Purple)
            };

            Coord p1 = map.Terrain.RandomPosition((_, tile) => tile.IsWalkable);
            var   e1 = new GameObject(p1, 1, null);

            e1.AddComponent(new DrawComponent('%', Color.Red));
            e1.AddComponent(new EmitComponent(_gasLayers[0], 100, 6, 100));
            map.AddEntity(e1);

            Coord p2 = map.Terrain.RandomPosition((_, tile) => tile.IsWalkable);
            var   e2 = new GameObject(p2, 1, null);

            e2.AddComponent(new DrawComponent('%', Color.Blue));
            e2.AddComponent(new EmitComponent(_gasLayers[1], 200, -100, -10));
            map.AddEntity(e2);

            Coord p3 = map.Terrain.RandomPosition((_, tile) => tile.IsWalkable);

            e3 = new GameObject(p3, 1, null);
            e3.AddComponent(new DrawComponent('@', Color.White));
            e3.IsWalkable = false;

            map.AddEntity(e3);

            engine.Start();
            engine.Run();
        }
        public static TimeSpan TimeForRandomRooms(int mapWidth, int mapHeight, int iterations, int maxRooms, int roomMinSize, int roomMaxSize)
        {
            var s = new Stopwatch();
            // For caching
            var mapToGenerate = new ArrayMap <bool>(mapWidth, mapHeight);

            QuickGenerators.GenerateRandomRoomsMap(mapToGenerate, maxRooms, roomMinSize, roomMaxSize);

            s.Start();
            for (int i = 0; i < iterations; i++)
            {
                mapToGenerate = new ArrayMap <bool>(mapWidth, mapHeight);
                QuickGenerators.GenerateRandomRoomsMap(mapToGenerate, maxRooms, roomMinSize, roomMaxSize);
            }
            s.Stop();

            return(s.Elapsed);
        }
Beispiel #6
0
    public void GenerateMap()
    {
        var tempMap = new ArrayMap <bool>(50, 50);

        //QuickGenerators.GenerateRectangleMap(tempMap);
        QuickGenerators.GenerateRandomRoomsMap(tempMap, 20, 5, 12);
        Map = new Map(50, 50, 1, Distance.CHEBYSHEV);

        Map.ObjectMoved += OnObjectMoved;

        foreach (var position in tempMap.Positions())
        {
            if (tempMap[position])
            {
                Map.SetTerrain(new FloorTerrain(position));
            }
            else
            {
                Map.SetTerrain(new WallTerrain(position));
            }
        }

        // instance a player
        var playerInstance = GD.Load <PackedScene>("res://Characters/Player/Player.tscn").Instance() as Player;

        GetTree().Root.GetNode("Game").AddChild(playerInstance);
        playerInstance.Position        = Map.WalkabilityView.RandomPosition(true);
        playerInstance.Moved          += OnPlayerMoved;
        GameController.Instance.Player = playerInstance;
        AddCharacter(playerInstance);

        // generate monsters
        for (var i = 0; i < _numMonsters; ++i)
        {
            var skeleman = GD.Load <PackedScene>("res://Characters/Monsters/Skeleman.tscn").Instance() as Monster;
            GetTree().Root.GetNode("Game").AddChild(skeleman);
            skeleman.Position = Map.WalkabilityView.RandomPosition(true);
            AddCharacter(skeleman);
            Monsters.Add(skeleman);
        }

        Map.CalculateFOV(playerInstance.Position, playerInstance.FOVRadius, Radius.DIAMOND);
        Draw();
    }
Beispiel #7
0
    public void Generate(int width, int height)
    {
        var terrainMap = new ArrayMap2D <bool>(width, height);

        // QuickGenerators.GenerateRectangleMap(terrainMap);
        QuickGenerators.GenerateRandomRoomsMap(terrainMap, 20, 7, 12);

        Data = new Map(terrainMap.Width, terrainMap.Height, 1, Distance.CHEBYSHEV);

        foreach (var position in terrainMap.Positions())
        {
            if (terrainMap[position])
            {
                var floorTile = Instantiate(_floorTile);
                floorTile.Init(map: Data, tilemap: Terrain, position, isWalkable: true, isTransparent: true);
            }
            else
            {
                var wallTile = Instantiate(_wallTile);
                wallTile.Init(map: Data, tilemap: Terrain, position, isWalkable: false, isTransparent: false);
            }
        }

        // spawn some monsters
        for (var i = 0; i < 30; i++)
        {
            var randomPos = Data.WalkabilityView.RandomPosition(true);
            var monster   = Instantiate(_monsterPrefab);
            monster.Init(randomPos, Data);
        }

        // spawn the player
        var playerPrefab = Resources.Load <Player>("Actors/Player");

        Player = Instantiate(playerPrefab);
        var randomStartingPos = Data.WalkabilityView.RandomPosition(true);

        Player.Init(randomStartingPos, Data);

        UpdatePlayerFOV();
    }