Esempio n. 1
0
        private void ProcessKeyboard()
        {
            prevKeyboardState    = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();
            prevMouseState       = currentMouseState;
            currentMouseState    = Mouse.GetState();

            if (KeyJustPressed(Keys.Escape))
            {
                this.Exit();
            }

            if (currentKeyboardState.IsKeyDown(Keys.LeftAlt))
            {
                camera.Velocity *= 10.0f;
            }
            if (currentKeyboardState.IsKeyUp(Keys.LeftAlt))
            {
                camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY);
            }

            if (currentKeyboardState.IsKeyDown(Keys.LeftAlt) ||
                currentKeyboardState.IsKeyDown(Keys.RightAlt))
            {
                if (KeyJustPressed(Keys.Enter))
                {
                    ToggleFullScreen();
                }
            }

            if (KeyJustPressed(Keys.D1))
            {
                camera.CurrentBehavior = Camera.Behavior.FirstPerson;
                camera.Velocity        = new Vector3(Settings.CAMERA_VELOCITY);
                camera.Acceleration    = new Vector3(Settings.CAMERA_ACCELERATION);
            }

            if (KeyJustPressed(Keys.D2))
            {
                camera.CurrentBehavior = Camera.Behavior.Spectator;
                camera.Velocity        = new Vector3(Settings.CAMERA_VELOCITY) * 1.5f;
                camera.Acceleration    = new Vector3(Settings.CAMERA_ACCELERATION) * 2.0f;
            }

            if (KeyJustPressed(Keys.D3))
            {
                camera.CurrentBehavior = Camera.Behavior.FreeView;
                camera.Velocity        = new Vector3(Settings.CAMERA_VELOCITY) * 1.5f;
                camera.Acceleration    = new Vector3(Settings.CAMERA_ACCELERATION) * 2.0f;
            }

            //if (KeyJustPressed(Keys.D4))
            //{
            //    camera.CurrentBehavior = Camera.Behavior.Orbit;
            //    camera.Velocity = new Vector3(Settings.CAMERA_VELOCITY) * 1.5f;
            //    camera.Acceleration = new Vector3(Settings.CAMERA_ACCELERATION) * 2.0f;
            //}

            if (KeyJustPressed(Keys.D4))
            {
                camera.CurrentBehavior = Camera.Behavior.Flight;
                camera.Velocity        = new Vector3(Settings.CAMERA_VELOCITY) * 0.3f;
                camera.Acceleration    = new Vector3(Settings.CAMERA_ACCELERATION) * 0.5f;
            }

            // SETTINGS WITH CONTROL
            if (currentKeyboardState.IsKeyDown(Keys.LeftControl))
            {
                if (KeyJustPressed(Keys.Z))
                {
                    AI.AIParams.CONFIG_ENABLE_DEFAULT_LIGHTING = !AI.AIParams.CONFIG_ENABLE_DEFAULT_LIGHTING;
                }

                if (KeyJustPressed(Keys.Space))
                {
                    terrain.ToggleDrawingTechnique();
                }

                if (KeyJustPressed(Keys.C))
                {
                    cursor.IsActivated = !cursor.IsActivated;
                    AIGame.terrain.ShowGroundCursor = !AIGame.terrain.ShowGroundCursor;
                }

                if (KeyJustPressed(Keys.F))
                {
                    Settings.FOG_ENABLED = !Settings.FOG_ENABLED;
                }

                if (KeyJustPressed(Keys.P))
                {
                    camera.PerspectiveInitial();
                }

                if (KeyJustPressed(Keys.B))
                {
                    Settings.DRAW_BOUNDING_BOXES = !Settings.DRAW_BOUNDING_BOXES;
                }

                if (KeyJustPressed(Keys.R))
                {
                    Settings.DRAW_RANGE_CIRCLES = !Settings.DRAW_RANGE_CIRCLES;
                }

                if (KeyJustPressed(Keys.A))
                {
                    Settings.ACCELERATED_MODE = !Settings.ACCELERATED_MODE;
                }

                if (KeyJustPressed(Keys.PageDown))
                {
                    Settings.GAME_SPEED -= 0.1f;
                    if (Settings.GAME_SPEED < 0.2f)
                    {
                        Settings.GAME_SPEED = 0.2f;
                    }
                }
                if (KeyJustPressed(Keys.PageUp))
                {
                    Settings.GAME_SPEED += 0.1f;
                }
                if (KeyJustPressed(Keys.Home))
                {
                    Settings.GAME_SPEED = 1f;
                }

                if (KeyJustPressed(Keys.L))
                {
                    Settings.DRAW_STATICS_LABELS = !Settings.DRAW_STATICS_LABELS;
                }

                if (KeyJustPressed(Keys.H))
                {
                    Settings.DRAW_GRAPH = !Settings.DRAW_GRAPH;
                }


                if (currentKeyboardState.IsKeyDown(Keys.LeftShift) && KeyJustPressed(Keys.L))
                {
                    Settings.DRAW_OBJECTS_LABELS = !Settings.DRAW_OBJECTS_LABELS;
                }

                if (KeyJustPressed(Keys.G))
                {
                    AIParams.CONFIG_DUMP_ANN_VECTORS = !AIParams.CONFIG_DUMP_ANN_VECTORS;
                }
            }
            // SETTINGS WITHOUT CONTROL
            else
            {
                // Clear selection
                if (KeyJustPressed(Keys.U))
                {
                    _aicontainer.ClearSelect();
                }

                // FOLLOW FITTEST OBJECT
                if (KeyJustPressed(Keys.F) && _aicontainer.GenethicAlgorithm.FittestObject != null)
                {
                    if (camera.ObjectToFollow != null)
                    {
                        camera.ObjectToFollow = null;
                    }
                    else
                    {
                        camera.ObjectToFollow = _aicontainer.GenethicAlgorithm.FittestObject;
                        camera.Position       = camera.ObjectToFollow.Position + Vector3.UnitY * 1000;
                        camera.LookAt(camera.ObjectToFollow.Position);
                        AIContainer.Select(camera.ObjectToFollow);
                    }
                }

                // process teams and objects movements
                if (camera.CurrentBehavior == Camera.Behavior.FreeView && _aicontainer.IsOneOfAIObjectSelected)
                {
                    // toggle objects status: walk, run, crawl, cover
                    if (KeyJustPressed(Keys.Z))
                    {
                        _aicontainer.SelectedObject.ToggleMoveStatus();
                    }

                    // toggle formation
                    if (KeyJustPressed(Keys.F))
                    {
                        _aicontainer.SelectedTeam.ToggleFormation();
                    }

                    // toggle oaau
                    if (KeyJustPressed(Keys.O))
                    {
                        _aicontainer.SelectedTeam.OperateAsAUnit = !_aicontainer.SelectedTeam.OperateAsAUnit;
                    }

                    // toggle kf
                    if (KeyJustPressed(Keys.K))
                    {
                        _aicontainer.SelectedTeam.KeepFormation = !_aicontainer.SelectedTeam.KeepFormation;
                    }

                    // go to cover
                    if (KeyJustPressed(Keys.C))
                    {
                        _aicontainer.SelectedObject.TakeCover();
                    }

                    // pick up static
                    if (KeyJustPressed(Keys.B))
                    {
                        _aicontainer.SelectedObject.PickUpBonus();
                    }

                    // pick up static
                    if (KeyJustPressed(Keys.M))
                    {
                        _aicontainer.SelectedObject.PickUpMedKit();
                    }
                }
            }
        }