public static MyGameMap GenerateDungeonMap(int width, int height)
        {
            // Generate a rectangular map for the sake of testing with GoRogue's map generation system.
            //
            // CUSTOMIZATION: Use a different set steps in AddSteps to generate a different type of map.
            var generator = new Generator(width, height)
                            .ConfigAndGenerateSafe(gen =>
            {
                gen.AddSteps(DefaultAlgorithms.RectangleMapSteps());
            });

            var generatedMap = generator.Context.GetFirst <ISettableGridView <bool> >("WallFloor");

            // Create actual integration library map.
            var map = new MyGameMap(generator.Context.Width, generator.Context.Height, null);

            // Add a component that will implement a character "memory" system, where tiles will be dimmed when they aren't seen by the player,
            // and remain visible exactly as they were when the player last saw them regardless of changes to their actual appearance,
            // until the player sees them again.
            //
            // CUSTOMIZATION: If you want to handle FOV visibility differently, you can create an instance of one of the
            // other classes in the FieldOfView namespace, or create your own by inheriting from FieldOfViewHandlerBase
            map.AllComponents.Add(new DimmingMemoryFieldOfViewHandler(0.6f));

            // Translate GoRogue's terrain data into actual integration library objects.  Our terrain must be of type
            // MemoryAwareRogueLikeCells because we are using the integration library's "memory-based" fov visibility
            // system.
            map.ApplyTerrainOverlay(generatedMap, (pos, val) => val ? MapObjectFactory.Floor(pos) : MapObjectFactory.Wall(pos));

            // Generate 10 enemies, placing them in random walkable locations for demo purposes.
            for (int i = 0; i < 10; i++)
            {
                var enemy = MapObjectFactory.Enemy();
                enemy.Position = map.WalkabilityView.RandomPosition(true);
                map.AddEntity(enemy);
            }

            return(map);
        }
Ejemplo n.º 2
0
        public MapScreen(MyGameMap map)
        {
            // Record the map we're rendering
            Map = map;

            // Create a renderer for the map, specifying viewport size.  The value in DefaultRenderer is automatically
            // managed by the map, and renders whenever the map is the active screen.
            //
            // CUSTOMIZATION: Pass in custom fonts/viewport sizes here.
            //
            // CUSTOMIZATION: If you want multiple renderers to render the same map, you can call CreateRenderer and
            // manage them yourself; but you must call the map's RemoveRenderer when you're done with these renderers,
            // and you must add any non-default renderers to the SadConsole screen object hierarchy, IN ADDITION
            // to the map itself.
            Map.DefaultRenderer = Map.CreateRenderer((Program.Width, Program.Height - MessageLogHeight));

            // Make the Map (which is also a screen object) a child of this screen.  You MUST have the map as a child
            // of the active screen, even if you are using entirely custom renderers.
            Map.Parent = this;

            // Make sure the map is focused so that it and the entities can receive keyboard input
            Map.IsFocused = true;

            // Generate player, add to map at a random walkable position, and calculate initial FOV
            Player          = MapObjectFactory.Player();
            Player.Position = Map.WalkabilityView.RandomPosition(true);
            Map.AddEntity(Player);
            Player.AllComponents.GetFirst <PlayerFOVController>().CalculateFOV();

            // Center view on player as they move
            Map.DefaultRenderer?.SadComponents.Add(new SadConsole.Components.SurfaceComponentFollowTarget {
                Target = Player
            });

            // Create message log
            MessageLog          = new MessageLogConsole(Program.Width, MessageLogHeight);
            MessageLog.Parent   = this;
            MessageLog.Position = new(0, Program.Height - MessageLogHeight);
        }