public Game()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = GameConstants.windowWidth;
            graphics.PreferredBackBufferHeight = GameConstants.windowHeight;
            Content.RootDirectory = "Content";

            input = new InputManager(this);
            input.SetMouseVisible(GameConstants.mouseVisible);
            Services.AddService(typeof(IInputService), input);

            Window.Title = "Labyrinth Survival. You can make it!";
            Window.Title = Window.Title.PadRight(200);
            Window.Title += "....hahaha not!";

            IsFixedTimeStep = GameConstants.verticalSyncOn;

            SoundManager = new AudioManager(this);
            Components.Add(SoundManager);
        }
        public Camera(Game game)
            : base(game)
        {
            UpdateOrder = 1;

            input = (InputManager)game.Services.GetService(typeof(IInputService));
            // Initialize camera state.
            fovx = DEFAULT_FOVX;
            znear = DEFAULT_ZNEAR;
            zfar = DEFAULT_ZFAR;
            accumHeadingDegrees = 0.0f;
            accumPitchDegrees = 0.0f;
            eyeHeightStanding = 0.0f;
            eyeHeightCrouching = 0.0f;
            eye = Vector3.Zero;
            target = Vector3.Zero;
            targetYAxis = Vector3.UnitY;
            xAxis = Vector3.UnitX;
            yAxis = Vector3.UnitY;
            zAxis = Vector3.UnitZ;
            viewDir = Vector3.Forward;
            acceleration = new Vector3(DEFAULT_ACCELERATION_X, DEFAULT_ACCELERATION_Y, DEFAULT_ACCELERATION_Z);
            velocityWalking = new Vector3(DEFAULT_VELOCITY_X, DEFAULT_VELOCITY_Y, DEFAULT_VELOCITY_Z);
            velocityRunning = velocityWalking * DEFAULT_RUNNING_MULTIPLIER;
            velocity = velocityWalking;
            orientation = Quaternion.Identity;
            viewMatrix = Matrix.Identity;
            posture = Posture.Standing;

            // Initialize mouse and keyboard input.
            enableMouseSmoothing = true;
            rotationSpeed = DEFAULT_SPEED_ROTATION;
            mouseSmoothingSensitivity = DEFAULT_MOUSE_SMOOTHING_SENSITIVITY;
            mouseSmoothingCache = new Vector2[MOUSE_SMOOTHING_CACHE_SIZE];
            mouseIndex = 0;
            mouseMovement = new Vector2[2];
            mouseMovement[0].X = 0.0f;
            mouseMovement[0].Y = 0.0f;
            mouseMovement[1].X = 0.0f;
            mouseMovement[1].Y = 0.0f;

            // Setup default action key bindings.
            actionKeys = new Dictionary<Actions, Keys>();
            actionKeys.Add(Actions.Crouch, Keys.LeftControl);
            actionKeys.Add(Actions.Jump, Keys.Space);
            actionKeys.Add(Actions.MoveForwards, Keys.W);
            actionKeys.Add(Actions.MoveBackwards, Keys.S);
            actionKeys.Add(Actions.StrafeRight, Keys.D);
            actionKeys.Add(Actions.StrafeLeft, Keys.A);
            actionKeys.Add(Actions.Run, Keys.LeftShift);

            currentMouseState = Mouse.GetState();

            // Setup perspective projection matrix.
            Rectangle clientBounds = game.Window.ClientBounds;
            float aspect = (float)clientBounds.Width / (float)clientBounds.Height;
            Perspective(fovx, aspect, znear, zfar);

            Position = GameConstants.PLAYER_START_POS*GameConstants.MAP_SCALE;
            CameraLocked = false;
        }
        public void HandlePlayerInput(InputManager input)
        {
            if (input.IsKeyDownOnce(Keys.C))
                PerformPlayerCollision = !PerformPlayerCollision;

            if (input.IsKeyDownOnce(Keys.E))
            {
                List<AABB> interactables = Interactables.GetInteractablesInRange(this);
                foreach (AABB aabb in interactables)
                {
                    if (aabb is IInteractableObject)
                    {
                        IInteractableObject obj = (IInteractableObject)aabb;
                        obj.Use(this);
                    }
                }
            }
        }
        public void UpdateMenu(InputManager input)
        {
            if(input.IsKeyDownOnce(MenuKeys[MenuActions.NEXT_ENTRY]))
            {
                ++currentSelectionIndex;
                if (menuType == GameStates.MainMenu)
                {
                    if (currentSelectionIndex >= MainMenuEntries.Count)
                        currentSelectionIndex = 0;
                    MainMenuEntries.ElementAt(currentSelectionIndex).Key.SetSelected();
                    MainMenuEntries.ElementAt(prevSelectionIndex).Key.SetUnselected();
                }
                else if (menuType == GameStates.PAUSE)
                {
                    if (currentSelectionIndex >= PauseMenuEntries.Count)
                        currentSelectionIndex = 0;
                    PauseMenuEntries.ElementAt(currentSelectionIndex).Key.SetSelected();
                    PauseMenuEntries.ElementAt(prevSelectionIndex).Key.SetUnselected();

                }
                prevSelectionIndex = currentSelectionIndex;
            }

            if(input.IsKeyDownOnce(MenuKeys[MenuActions.PREV_ENTRY]))
            {
                --currentSelectionIndex;
                if (menuType == GameStates.MainMenu)
                {
                    if (currentSelectionIndex < 0)
                        currentSelectionIndex = MainMenuEntries.Count - 1;
                    MainMenuEntries.ElementAt(currentSelectionIndex).Key.SetSelected();
                    MainMenuEntries.ElementAt(prevSelectionIndex).Key.SetUnselected();
                }
                else if (menuType == GameStates.PAUSE)
                {
                    if (currentSelectionIndex < 0)
                        currentSelectionIndex = PauseMenuEntries.Count-1;
                    PauseMenuEntries.ElementAt(currentSelectionIndex).Key.SetSelected();
                    PauseMenuEntries.ElementAt(prevSelectionIndex).Key.SetUnselected();
                }
                prevSelectionIndex = currentSelectionIndex;
            }
            if(input.IsKeyDownOnce(MenuKeys[MenuActions.SELECT_ENTRY]))
            {
                if (menuType == GameStates.MainMenu)
                    MainMenuEntries.ElementAt(currentSelectionIndex).Key.OnEntrySelected();
                else if (menuType == GameStates.PAUSE)
                    PauseMenuEntries.ElementAt(currentSelectionIndex).Key.OnEntrySelected();
            }

            if(input.IsKeyDownOnce(MenuKeys[MenuActions.BACK]))
            {
                if (previousGameState == GameStates.MainMenu)
                {
                    Game.quitGame = true;
                }
                else if (previousGameState == GameStates.GAME)
                {
                    Game.currentGameState = GameStates.GAME;
                }
                else if (previousGameState == GameStates.PAUSE)
                {
                    //it cant really be, can it %))
                    throw new Exception("Ok, what the f**k happened now, time to get some sleep?");
                }
            }
        }