Beispiel #1
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();
             }
        }
Beispiel #2
0
        public ShadeGame(GraphicsConfiguration graphicsConfiguration, Renderer renderer, EntitySystem entitySystem)
        {
            this.graphicsConfiguration = graphicsConfiguration;
             this.renderer = renderer;
             this.entitySystem = entitySystem;

             this.graphicsDeviceManager = new GraphicsDeviceManager(this);
             this.graphicsDeviceManager.PreferredBackBufferWidth = graphicsConfiguration.Width;
             this.graphicsDeviceManager.PreferredBackBufferHeight = graphicsConfiguration.Height;
            //         this.graphicsDeviceManager.DeviceCreationFlags |= DeviceCreationFlags.Debug;

             Content.RootDirectory = "Content";
        }