Beispiel #1
0
        protected override void LoadContent()
        {
            this.spriteBatch = new SpriteBatch(this.GraphicsDevice);

            Content.RootDirectory = "Content";

            this.mainFont = Content.Load <SpriteFont>("opensans");

            Texture2D rock = Content.Load <Texture2D>("rock");

            Texture2D boat       = Content.Load <Texture2D>("ship1");
            Texture2D pirateBoat = Content.Load <Texture2D>("ship-pirate");

            Texture2D birdTexture = Content.Load <Texture2D>("bird-white");

            Texture2D[] teamTextures =
            {
                boat, pirateBoat
            };

            Populate(5, 10, teamTextures, rock, birdTexture);

            IPathSmoother smoother = new CustomizablePathSmoother(this.world, 5);

            (float, float)dimensions   = (WORLD_WIDTH, WORLD_HEIGHT);
            (int, int)vertexCounts     = (24, 18);
            (float, float)offset       = (10, 10);
            this.world.NavigationGraph = GraphGenerator.GenerateGraphWithObstacles(
                dimensions, vertexCounts, offset, this.world.Entities.OfType <Rock>(),
                GraphGenerator.AxisAndDiagonalIndices
                );

            this.world.PathFinder = new PathFinder(this.world.NavigationGraph, smoother);

            this.graphRenderer = new GraphRenderer(this.world.NavigationGraph, this.mainFont, Color.White);

            this.keyboardInput = new KeyboardInput();
            this.mouseInput    = new MouseInput();

            this.mouseInput.OnKeyPress(MouseButtons.Left, (input, state) =>
            {
                IEnumerable <Ship> entitiesNearMouse = this.world.FindEntitiesNear(this.mouseInput.MouseState.Position.ToVector2(), 3).OfType <Ship>();

                if (!this.keyboardInput.KeyboardState.IsKeyDown(Keys.LeftShift))
                {
                    ClearSelected();
                }

                foreach (Ship baseGameEntity in entitiesNearMouse)
                {
                    this.selectedEntities.AddLast(baseGameEntity);
                    baseGameEntity.Color = Color.Red;
                }
            });

            this.keyboardInput.OnKeyPress(Keys.G, (key, state) => { this.graphRenderer.ToggleEnabled(); });
            this.keyboardInput.OnKeyPress(Keys.Space, (input, state) => { this.paused = !this.paused; });
            this.keyboardInput.OnKeyPress(Keys.O, (input, state) => { this.drawAgentGoals = !this.drawAgentGoals; });

            base.LoadContent();
        }