Пример #1
0
        private CandidatePositions SetupKeyboardCandidatePositions(float stepLength, CandidatePositions candidatePositions)
        {
            var keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                candidatePositions.CandidatePos -= new Vector2(stepLength, 0);
                candidatePositions.CandidateXPos = this.Position - new Vector2(stepLength, 0);
            }
            else if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                candidatePositions.CandidatePos += new Vector2(stepLength, 0);
                candidatePositions.CandidateXPos = this.Position + new Vector2(stepLength, 0);
            }

            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                candidatePositions.CandidatePos -= new Vector2(0, stepLength);
                candidatePositions.CandidateYPos = this.Position - new Vector2(0, stepLength);
            }
            else if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                candidatePositions.CandidatePos += new Vector2(0, stepLength);
                candidatePositions.CandidateYPos = this.Position + new Vector2(0, stepLength);
            }
            return(candidatePositions);
        }
Пример #2
0
 private void NormalizeDirection(CandidatePositions candidatePositions)
 {
     direction = candidatePositions.CandidatePos - this.position;
     direction.Normalize();
     //if (direction != Vector2.Zero
     //    && !float.IsNaN(direction.X) && !float.IsNaN(direction.Y))
     //    lastDirection = direction;
 }
Пример #3
0
        private CandidatePositions SetupScreenPadCandidatePositions(IScreenPad screenPad, float stepLength)
        {
            var candidatePositions = new CandidatePositions(this.Position);

            if (!screenPad.LeftStickIsIdle)
            {
                screenPad.LeftStick.Normalize();
                candidatePositions.CandidatePos  = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * stepLength;
                candidatePositions.CandidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * stepLength;
                candidatePositions.CandidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * stepLength;
            }
            return(candidatePositions);
        }
Пример #4
0
        private void SetNewPosition(PhysicalObject gameMap, float scrollRows, CandidatePositions candidatePositions)
        {
            var collisionResult  = gameMap.TestCollision(this, candidatePositions.CandidatePos, scrollRows);
            var collisionXResult = gameMap.TestCollision(this, candidatePositions.CandidateXPos, scrollRows);
            var collisionYResult = gameMap.TestCollision(this, candidatePositions.CandidateYPos, scrollRows);

            if (collisionResult.CollisionType == CollisionType.None)
            {
                this.Position = candidatePositions.CandidatePos;
            }
            else if (collisionXResult.CollisionType == CollisionType.None)
            {
                this.Position = candidatePositions.CandidateXPos;
            }
            else if (collisionYResult.CollisionType == CollisionType.None)
            {
                this.Position = candidatePositions.CandidateYPos;
            }
        }