示例#1
0
        private static IReadOnlyList<NavigationGridlet> CreateGridletsFromDungeonGrid(Grid grid, GridletFactory gridletFactory)
        {
            var cellSpacing = 70;
             var cellSize = 60;
             var connectorSize = 11;
             var connectorWidth = 5;

             var results = new List<NavigationGridlet>();
             foreach (var cell in grid.Cells) {
            results.Add(gridletFactory.Quad(cell.X * cellSpacing, cell.Y * cellSpacing, 0, 0, 0, 0, cellSize, cellSize));
             }
             var connectors = grid.Cells.SelectMany(x => x.Connectors).Distinct().Where(x => x.State == ConnectorState.Linked).ToArray();
            //         foreach (var connector in connectors) {
             for (var i = 0; i < connectors.Length; i++) {
            Console.WriteLine("C: " + i + " / " + connectors.Length);
            var connector = connectors[i];
            var first = connector.First;
            var second = connector.Second;
            var segment = connector.Segment;
            var theta = Math.Atan2(segment.Vector.Y, segment.Vector.X);
            var dx = Math.Cos(theta) * cellSpacing / 2;
            var dy = Math.Sin(theta) * cellSpacing / 2;
            results.Add(gridletFactory.Quad((float)(first.X * cellSpacing + dx), (float)(first.Y * cellSpacing + dy), 0, 0, (float)theta, 0, connectorSize, connectorWidth));
             }
             return results;
        }
示例#2
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();

             // Implement the Gruenes Schaf
             new Thread(() => {
            while (true) {
               GC.Collect();
               Thread.Sleep(5000);
            }
             }).Start();

             var gridWidth = 2;
             var gridHeight = 2;

             var grid = new GridFactory().Create(gridWidth, gridHeight);
             var manipulator = new GridManipulator(grid, new Random(0));
             var spiral = new SpiralParametricFunction(1, 10, 3, (float)gridWidth / 2, (float)gridHeight / 2, 0);
             manipulator.CutParametric(spiral.TInitial, spiral.TFinal, 20f, spiral.PointAt);
             var lastSpiralPoint = spiral.PointAt(spiral.TFinal - 30);
             var v = new Vector2D(lastSpiralPoint, new Point2D(gridWidth / 2.0f, gridHeight / 2.0f));
             v = v.ToUnitVector();
             var cutDestination = lastSpiralPoint + v * 3;
             manipulator.CutLine(new Line2D(lastSpiralPoint, cutDestination));
             var entranceCell = grid.Cells[(gridHeight / 2) * grid.Width + (gridWidth / 2)];
             var cells = manipulator.FillRegion(entranceCell);

             var graphicsConfiguration = new GraphicsConfiguration { Width = 1600, Height = 900 };
             var gridletFactory = new GridletFactory();
            //         IReadOnlyList<NavigationGridlet> gridlets = CreateGridletsFromDungeonGrid(grid, gridletFactory);
             IReadOnlyList<NavigationGridlet> gridlets = new List<NavigationGridlet> {
            gridletFactory.Quad(0, 0, 0, 0, 0, 0, 60, 60),
            //            gridletFactory.Quad(37, 0, 2, -0.3f, 0, 0, 15, 7),
            //            gridletFactory.Quad(47.60f, -9.0f, 4.22f, 0, 0, 0, 7, 25),
            //            gridletFactory.Quad(58.05f, -18.0f, 4.22f, 0, 0, 0, 15, 7)
             };
             var navigationGrid = new NavigationGrid(gridlets);
             navigationGrid.Initialize();
             var pathfinder = new Pathfinder(navigationGrid);
             var renderer = new Renderer();

             CommandFactory commandFactory = new CommandFactory(pathfinder);
             var entityFactory = new EntityFactory();
             var entitySystem = new EntitySystem();
             entitySystem.AddEntity(entityFactory.CreateUnitCubeEntity());
             navigationGrid.Gridlets.ForEach(gridlet => entitySystem.AddEntity(entityFactory.CreateAndAssociateGridletEntity(navigationGrid, gridlet, pathfinder, commandFactory)));
             var characterEntity = entityFactory.CreateCharacterEntity(pathfinder);
             entitySystem.AddEntity(characterEntity);
             entitySystem.AddEntity(entityFactory.CreateCameraEntity(graphicsConfiguration, characterEntity));
             entitySystem.AddBehavior(new PhysicsBehavior(navigationGrid));
             entitySystem.AddBehavior(new CommandQueueBehavior());

             // Dungeon Stuff
             DungeonKeyInventory dungeonKeyInventory = new DungeonKeyInventory();
            //         entitySystem.AddEntity(entityFactory.CreateDungeonKeyEntity(new Vector3(5, 10, 0), new Vector4(1, 0, 0, 1), commandFactory, dungeonKeyInventory));
            //         entitySystem.AddEntity(entityFactory.CreateDungeonLockEntity(new Vector3(0, 35, 0), new Vector4(1, 0, 0, 1), commandFactory, dungeonKeyInventory));
            //         entitySystem.AddBehavior(new DungeonLockDisablesGroundPathingBehavior(navigationGrid));
             foreach (var cell in cells) {
            if (cell.KeyColor != Color.Empty) {
               var color = new Vector4(cell.KeyColor.R / 255f, cell.KeyColor.G / 255f, cell.KeyColor.B / 255f, 1);
               entitySystem.AddEntity(entityFactory.CreateDungeonKeyEntity(new Vector3(cell.X * 70 + 5, cell.Y * 70 + 10, 0), color, commandFactory, dungeonKeyInventory));
            }
            if (cell.LockColor != Color.Empty) {
               var color = new Vector4(cell.LockColor.R / 255f, cell.LockColor.G / 255f, cell.LockColor.B / 255f, 1);
               entitySystem.AddEntity(entityFactory.CreateDungeonLockEntity(new Vector3(cell.X * 70, cell.Y * 70, 0), color, commandFactory, dungeonKeyInventory, navigationGrid));
            }
             }

             using (var game = new ShadeGame(graphicsConfiguration, renderer, entitySystem)) {
            game.Run();
             }
        }