Esempio n. 1
0
        public void PopulateScene()
        {
            var mapWidth  = 35;
            var mapHeight = 35;

            var settings = DungeonMapGeneratorSettings.Random(mapWidth, mapHeight);

            DeferredRenderer.SetAmbientColor(settings.AmbientColor);

            var map = EntityFactory.Presets
                      .DungeonMap()
                      .AtPosition(0, 0)
                      .Create();

            map.Generate(settings);
            AddEntity(map);

            var miniMap = EntityFactory.Presets
                          .Minimap(map.TileLayers)
                          .AtPosition(Camera.Bounds.Width - mapWidth - 20, 20)
                          .Create();

            AddEntity(miniMap);

            var spawn = map.Spawn;

            var player = EntityFactory.Presets
                         .Player()
                         .AtPosition(spawn.Position.X, spawn.Position.Y)
                         .AddInput <KeyboardController>()
                         .Create();

            AddEntity(player);

            // Add extra players with random input
            var n = 0;

            for (var i = 0; i < n; i++)
            {
                float x, y;
                do
                {
                    x = Random.NextFloat() * mapWidth * Tile.Width;
                    y = Random.NextFloat() * mapHeight * Tile.Height;
                } while (map.GetTileAtPosition(x, y).Type != TileType.Floor);

                var bot = EntityFactory.Presets.UntrackedPlayer()
                          .With(new MiniMapTracker(Color.Blue))
                          .AddInput <RandomInputController>()
                          .AtPosition(x, y)
                          .Create();
                AddEntity(bot);
            }
        }
Esempio n. 2
0
        public void Generate(DungeonMapGeneratorSettings settings)
        {
            _mapWidth  = settings.Width;
            _mapHeight = settings.Height;

            _generator = new DungeonMapGenerator(settings);
            _generator.Generate();

            var result = _generator.Result;

            TileLayers = new List <Tile[, ]>();

            var normalMap = Core.Content.Load <Texture2D>(Content.Textures.Tileset_subtiles_test_normal);
            var material  = new DeferredSpriteMaterial(normalMap);

            foreach (var tileGroup in result.Tiles)
            {
                var layer = new Tile[_mapWidth, _mapHeight];
                layer.Initialize();

                foreach (var tile in tileGroup)
                {
                    layer[tile.TilePosition.X, tile.TilePosition.Y] = tile;
                }
                TileLayers.Add(layer);

                var layerRenderer = new DungeonMapLayerRenderer();
                var renderLayer   = DetermineRenderLayerForGroup(tileGroup.Key);
                layerRenderer.SetRenderLayer(renderLayer);
                layerRenderer.SetMaterial(material);
                layerRenderer.SetTiles(layer);

                AddComponent(layerRenderer);
            }

            foreach (var Entity in result.Entities)
            {
                Core.Scene.AddEntity(Entity);
            }

            foreach (var colliderBounds in result.ColliderBounds)
            {
                AddComponent(new BoxCollider(colliderBounds));
            }

            Spawn = result.Entities.First(e => e is Spawn) as Spawn;
            Exit  = result.Entities.First(e => e is Exit) as Exit;
        }