Пример #1
0
 public MovementTest()
 {
     graphics = new GraphicsDeviceManager(this);
     graphics.PreferredBackBufferWidth = 1024;
     graphics.PreferredBackBufferHeight = 768;
     graphics.ApplyChanges();
     _inputState = new InputState();
     Content.RootDirectory = "Content";
 }
Пример #2
0
        /// <summary>
        /// Set speed and direction of player based on their input.
        /// TODO: Implement variable speed.
        /// </summary>
        /// <param name="inputState">Current state of all controllers.</param>
        /// <param name="index">PlayerIndex of Player to respond to input from.</param>
        public void UpdateMovement(InputState inputState, PlayerIndex index)
        {
            if (CurrentState != State.Dead)
            {
                _speed = Vector2.Zero;
                _direction = Vector2.Zero;

                if (inputState.IsUpHeld(index))
                {
                    _speed.Y = MovementSpeed;
                    _direction.Y = (float)Move.Up;
                    Facing = Face.Up;
                }
                else if (inputState.IsDownHeld(index))
                {
                    _speed.Y = MovementSpeed;
                    _direction.Y = (float)Move.Down;
                    Facing = Face.Down;
                }

                if (inputState.IsLeftHeld(index))
                {
                    _speed.X = MovementSpeed;
                    _direction.X = (float)Move.Left;
                    Facing = Face.Left;
                }
                else if (inputState.IsRightHeld(index))
                {
                    _speed.X = MovementSpeed;
                    _direction.X = (float)Move.Right;
                    Facing = Face.Right;
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Responds to a Player's input and checks for collisions.
 /// </summary>
 /// <param name="inputState">Current state of all controllers.</param>
 /// <param name="index">PlayerIndex of Player to respond to input from.</param>
 /// <param name="bounds">Rectangle containing the bounds of the box to check for collisions with.</param>
 /// <param name="blocks">An arr of <see cref="Obstacle"/>s to check for collisions with.</param>
 public void HandleInput(InputState inputState, PlayerIndex index, Rectangle bounds, Obstacle[] blocks)
 {
     UpdateMovement(inputState, index);
     CheckBounds(bounds);
     CheckCollisions(bounds, blocks);
 }