Exemplo n.º 1
0
        /// <summary>
        /// Execute movement-related logic on every update.
        /// </summary>
        private void Move()
        {
            //No movement if you're dead.
            if (playerState == PlayerState.Dead)
            {
                return;
            }

            Vector2 moveDir = new Vector2(horizontalInput.Value, verticalInput.Value);

            //Adjust for diagonal movement
            float moveMod = (moveDir.X != 0 && moveDir.Y != 0) ? 0.7071f : 1f;

            var movement = moveDir * MoveSpeed * moveMod * Time.DeltaTime;

            //No movement if trying to walk into something.
            if (moveDir.X < 0 && collisionResult.Normal.X > 0 ||
                moveDir.X > 0 && collisionResult.Normal.X < 0)
            {
                return;
            }
            if (moveDir.Y < 0 && collisionResult.Normal.Y > 0 ||
                moveDir.Y > 0 && collisionResult.Normal.Y < 0)
            {
                return;
            }

            mover.CalculateMovement(ref movement, out collisionResult);
            subPixelVector.Update(ref movement);
            mover.ApplyMovement(movement);
        }