Exemple #1
0
        public void ProcessGamePad(IScreenPad screenPad, PhysicalObject gameMap)
        {
            //var candidatePos = this.Position;
            //var candidateXPos = this.Position;
            //var candidateYPos = this.Position;

            //if (Math.Abs(screenPad.LeftStick.X) + Math.Abs(screenPad.LeftStick.Y) > 0)
            //{
            //    screenPad.LeftStick.Normalize();
            //    candidatePos = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * .5f;
            //    candidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * .5f;
            //    candidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * .5f;
            //}

            //var collisionResult = gameMap.TestCollision(this, candidatePos);
            //var collisionXResult = gameMap.TestCollision(this, candidateXPos);
            //var collisionYResult = gameMap.TestCollision(this, candidateYPos);
            //if (collisionResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidatePos;
            //}
            //else if (collisionXResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidateXPos;
            //}
            //else if (collisionYResult.CollisionType == CollisionType.None)
            //{
            //    this.Position = candidateYPos;
            //}
        }
Exemple #2
0
        public void ProcessGamePad(IScreenPad screenPad, PhysicalObject gameMap, float scrollRows)
        {
            float stepLength = GetStepLength();

            var candidatePositions = SetupScreenPadCandidatePositions(screenPad, stepLength);

            candidatePositions = SetupKeyboardCandidatePositions(stepLength, candidatePositions);
            NormalizeDirection(candidatePositions);
            SetNewPosition(gameMap, scrollRows, candidatePositions);
        }
Exemple #3
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;
            }
        }
Exemple #4
0
        public void ProcessGamePad(IScreenPad screenPad, PhysicalObject gameMap, float scrollRows)
        {
            var candidatePos  = this.Position;
            var candidateXPos = this.Position;
            var candidateYPos = this.Position;

#if WINDOWS_PHONE_APP
            var stepLength = .25f;
#endif

#if WINDOWS_APP
            var stepLength = .15f;
#endif

            if (Math.Abs(screenPad.LeftStick.X) + Math.Abs(screenPad.LeftStick.Y) > 0)
            {
                screenPad.LeftStick.Normalize();
                candidatePos  = this.Position + new Vector2(screenPad.LeftStick.X, -screenPad.LeftStick.Y) * stepLength;
                candidateXPos = this.Position + new Vector2(screenPad.LeftStick.X, 0) * stepLength;
                candidateYPos = this.Position + new Vector2(0, -screenPad.LeftStick.Y) * stepLength;
            }

            var keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

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

            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                candidatePos -= new Vector2(0, stepLength);
                candidateYPos = this.Position - new Vector2(0, stepLength);
            }
            else if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                candidatePos += new Vector2(0, stepLength);
                candidateYPos = this.Position + new Vector2(0, stepLength);
            }

            direction = candidatePos - this.position;

            direction.Normalize();

            var collisionResult  = gameMap.TestCollision(this, candidatePos, scrollRows);
            var collisionXResult = gameMap.TestCollision(this, candidateXPos, scrollRows);
            var collisionYResult = gameMap.TestCollision(this, candidateYPos, scrollRows);
            if (collisionResult.CollisionType == CollisionType.None)
            {
                this.Position = candidatePos;
            }
            else if (collisionXResult.CollisionType == CollisionType.None)
            {
                this.Position = candidateXPos;
            }
            else if (collisionYResult.CollisionType == CollisionType.None)
            {
                this.Position = candidateYPos;
            }
        }