/// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(GameTime gameTime, Cutlass.GameComponents.Input input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            GamePadState gamePadState = input.CurrentGamePadState;

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected;

            if (input.PauseGame || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen());
            }
            else
            {
                Player.HandleInput(gameTime, input, _Player.Position - _VisibleArea.Min);
            }
        }
        /// <summary>
        /// The Main CutlassEngine constructor
        /// </summary>
        public CutlassEngine(string windowTitle = "Cutlass Engine")
        {
            _GraphicsDeviceManager = new GraphicsDeviceManager(this);
            _ContentManager = new ContentManager(this.Services);

            _GraphicsDeviceManager.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(GraphicsDeviceManager_PreparingDeviceSettings);
            Window.Title = _WindowTitle = windowTitle;

            GameSettingsManager.Initialize();

            //Initialize Resolution settings.
            ResolutionManager.Initialize(this, _GraphicsDeviceManager);

            //#if DEBUG
            //Disable vertical retrace to get highest framerates possible for
            //testing performance.
            _GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
            //#endif
            //Demand to update as fast as possible, do not use fixed time steps.
            this.IsFixedTimeStep = false;

            //Init the Input component
            _Input = new Input(this);
            Components.Add(_Input);

            //Init the Font Manager component
            _FontManager = new FontManager(this);
            Components.Add(_FontManager);

            //Init the Texture Manager component
            _TextureManager = new TextureManager(this);
            Components.Add(_TextureManager);

            //Init the Sound Manager component
            _SoundManager = new SoundManager(this);
            Components.Add(_SoundManager);

            //Init the screen manager component.
            _ScreenManager = new ScreenManager(this);
            Components.Add(_ScreenManager);

            #if DEBUG
            //Init the FpsCounter
            _FpsCounter = new FpsCounter(this);
            Components.Add(_FpsCounter);
            #endif
        }
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(GameTime gameTime, Input input)
 {
 }
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(GameTime gameTime, Input input)
        {
            #region Up
            // Move to the previous menu entry?
            if (input.MenuUp)
            {
                _SelectedEntry--;

                if (_SelectedEntry < 0)
                    _SelectedEntry = _MenuEntries.Count - 1;
            }

            #endregion Up

            #region Down

            // Move to the next menu entry?
            if (input.MenuDown)
            {
                _SelectedEntry++;

                if (_SelectedEntry >= _MenuEntries.Count)
                    _SelectedEntry = 0;
            }

            #endregion Down

            #region Right

            // Move the current entry right?
            if (input.MenuRight)
            {
                OnRightEntry(_SelectedEntry);
            }
            //Keep moving the current entry right?
            else if (input.MenuStillRight)
            {
                OnStillRight(_SelectedEntry);
            }
            //Right released
            else if (input.MenuRightReleased)
            {
                OnRightReleased(_SelectedEntry);
            }

            #endregion Right

            #region Left

            // Move the current entry left?
            if (input.MenuLeft)
            {
                OnLeftEntry(_SelectedEntry);
            }
            //Keep moving the current entry let?
            else if (input.MenuStillLeft)
            {
                OnStillLeft(_SelectedEntry);
            }
            //Right released
            else if (input.MenuLeftReleased)
            {
                OnLeftReleased(_SelectedEntry);
            }

            #endregion Left

            // Select the current entry?
            if (input.MenuSelect)
            {
                OnSelectEntry(_SelectedEntry);
            }
            // Cancel?
            else if (input.MenuCancel)
            {
                OnCancel();
            }
        }
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(GameTime gameTime, Input input)
        {
            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.MenuSelect)
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new EventArgs());

                ExitScreen();
            }
            else if (input.MenuCancel && _IncludeCancelOption)
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new EventArgs());

                ExitScreen();
            }
        }
Exemple #6
0
        public void HandleInput(GameTime gameTime, Cutlass.GameComponents.Input input, Vector2 playerScreenPosition)
        {
            KeyboardState keyboardState = input.CurrentKeyboardState;
            MouseState    mouseState    = input.CurrentMouseState;
            GamePadState  gamePadState  = input.CurrentGamePadState;

            //Keyboard Input
            _IsJumpingDown = false;
            _WalkDirection = 0;

            if (keyboardState.IsKeyDown(GameSettingsManager.Default.LeftKey))
            {
                _WalkDirection = _WalkDirection - 1;
                _Velocity.X    = Math.Max(_Velocity.X - (0.1f * (float)gameTime.ElapsedGameTime.TotalMilliseconds), -MAX_PLAYER_HORIZONTAL_SPEED);
            }

            if (keyboardState.IsKeyDown(GameSettingsManager.Default.RightKey))
            {
                _WalkDirection = _WalkDirection + 1;
                _Velocity.X    = Math.Min(_Velocity.X + (0.1f * (float)gameTime.ElapsedGameTime.TotalMilliseconds), MAX_PLAYER_HORIZONTAL_SPEED);
            }

            if (keyboardState.IsKeyDown(GameSettingsManager.Default.JumpKey) && _IsOnGround)
            {
                _IsOnGround = false;

                if (keyboardState.IsKeyDown(GameSettingsManager.Default.DownKey))
                {
                    _IsJumpingDown = true;
                    _Velocity.Y   += 1.0f;
                }
                else
                {
                    _Velocity.Y = _Velocity.Y - (6.0f);
                }
            }

            //Mouse Input
            Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);

            _LookDirection = mousePosition - (playerScreenPosition);// + new Vector2(Width / 2, Height / 2));
            _LookDirection.Normalize();

            //Looking Right
            if (_LookDirection.X >= 0)
            {
                //On the ground
                if (_WasOnGround)
                {
                    //Walking forward
                    if (_WalkDirection > 0)
                    {
                        _CurrentTexture = _Player_TexId_Walking_R;
                    }
                    //Walking backward
                    else if (_WalkDirection < 0)
                    {
                        _CurrentTexture = _Player_TexId_Walking_Reverse_R;
                    }
                    //Standing
                    else
                    {
                        _CurrentTexture = _Player_TexId_Standing_R;
                    }
                }
                //Jumping
                else
                {
                    _CurrentTexture = _Player_TexId_Jumping_R;
                }
            }
            //Looking Left
            else
            {
                //On the ground
                if (_WasOnGround)
                {
                    //Walking forward
                    if (_WalkDirection < 0)
                    {
                        _CurrentTexture = _Player_TexId_Walking_L;
                    }
                    //Walking backward
                    else if (_WalkDirection > 0)
                    {
                        _CurrentTexture = _Player_TexId_Walking_Reverse_L;
                    }
                    //Standing
                    else
                    {
                        _CurrentTexture = _Player_TexId_Standing_L;
                    }
                }
                //Jumping
                else
                {
                    _CurrentTexture = _Player_TexId_Jumping_L;
                }
            }
        }