Beispiel #1
0
        private void AdjustPlayerPositionAndRotation(ILogicalMirror mirror)
        {
            Vector2 newPlayerPosition1 = mirror.GetDistance1FromMirrorCenter(_playerDistanceFromMirror);
            Vector2 newPlayerPosition2 = mirror.GetDistance2FromMirrorCenter(_playerDistanceFromMirror);

            bool isCloserToPosition1 = (Player.Position - newPlayerPosition1).Length < (Player.Position - newPlayerPosition2).Length;

            Vector2 normal = isCloserToPosition1 ? mirror.GetMirrorNormal1() : mirror.GetMirrorNormal2();

            float angle = Util.CalculateAngle(new Vector2(0f, -1f), normal);

            if (normal.X > 0)
            {
                angle *= -1;
            }

            Player.Rotation = angle;

            Player.Position = isCloserToPosition1 ? newPlayerPosition1 : newPlayerPosition2;
        }
Beispiel #2
0
        private void UnfocusPlayerFromMirror()
        {
            ILogicalMirror mirror = Player.CurrentMirror;

            Player.Rotation = 0.0f;

            float distanceFactor = _playerDistanceFromMirror;

            while (Util.HasIntersection(Player, mirror))
            {
                distanceFactor += 0.01f;

                Vector2 possiblePlayerPosition1 = mirror.GetDistance1FromMirrorCenter(distanceFactor);
                Vector2 possiblePlayerPosition2 = mirror.GetDistance2FromMirrorCenter(distanceFactor);

                bool isCloserToPosition1 = (Player.Position - possiblePlayerPosition1).Length < (Player.Position - possiblePlayerPosition2).Length;

                Player.Position = isCloserToPosition1 ? possiblePlayerPosition1 : possiblePlayerPosition2;
            }

            Player.UnfocusCurrentMirror();
        }
Beispiel #3
0
 public void UnfocusCurrentMirror()
 {
     CurrentMirror = null;
 }
Beispiel #4
0
 public void FocusMirror(ILogicalMirror mirror)
 {
     CurrentMirror = mirror;
 }
Beispiel #5
0
        private void CalculateLightRay(ILogicalLightRay lightRay)
        {
            Line currentRay = lightRay.GetLastRay();

            Intersection closestNonReflectingIntersection = Util.GetClosestIntersection(currentRay, CurrentRoom.GetNonReflectingBounds());

            var mirrorIntersections = new List <Tuple <Intersection, ILogicalMirror> >();

            foreach (ILogicalMirror mirror in Mirrors)
            {
                Intersection mirrorIntersection = Util.GetIntersection(currentRay, mirror.GetMirrorLine());

                if (mirrorIntersection != null)
                {
                    mirrorIntersections.Add(new Tuple <Intersection, ILogicalMirror>(mirrorIntersection, mirror));
                }
            }

            bool reflect = false;

            Tuple <Intersection, ILogicalMirror> closestReflectingIntersection = null;

            if (mirrorIntersections.Count > 0)
            {
                closestReflectingIntersection = mirrorIntersections[0];

                foreach (var mirrorIntersection in mirrorIntersections)
                {
                    if (mirrorIntersection.Item1.RelativeDistance < closestReflectingIntersection.Item1.RelativeDistance)
                    {
                        closestReflectingIntersection = mirrorIntersection;
                    }
                }

                reflect = closestReflectingIntersection.Item1.RelativeDistance < closestNonReflectingIntersection.RelativeDistance;
            }

            if (reflect)
            {
                Vector2        intersectionPoint = closestReflectingIntersection.Item1.Point;
                ILogicalMirror mirror            = closestReflectingIntersection.Item2;

                Vector2 lightDirection = currentRay.GetDirectionVector();
                lightDirection.Normalize();

                Vector2 normal = mirror.GetMirrorNormal1();

                Vector2 newDirection = lightDirection - 2 * (Vector2.Dot(normal, lightDirection)) * normal;
                Vector2 point        = new Vector2(intersectionPoint.X, intersectionPoint.Y) + newDirection * 0.0001f;

                lightRay.AddNewRay(point, newDirection);

                CalculateLightRay(lightRay);
            }
            else
            {
                if (closestNonReflectingIntersection != null)
                {
                    lightRay.FinishRays(closestNonReflectingIntersection.Point);
                }
            }
        }
Beispiel #6
0
        private void ProcessProlongedUserActions()
        {
            if (MovementInputBlocked)
            {
                return;
            }

            if (Player.IsFocusedToMirror())
            {
                _playerMovement.ResetSpeed();

                ILogicalMirror currentMirror = Player.CurrentMirror;

                // Movement

                float mirrorMovementSpeed = _mirrorMovement.GetSpeed();

                bool moveLeft  = InputManager.IsUserActionActive(UserAction.MoveLeft);
                bool moveRight = InputManager.IsUserActionActive(UserAction.MoveRight);
                bool moveUp    = InputManager.IsUserActionActive(UserAction.MoveUp);
                bool moveDown  = InputManager.IsUserActionActive(UserAction.MoveDown);

                if (moveLeft)
                {
                    currentMirror.MoveMirrorLeft(mirrorMovementSpeed);
                }
                if (moveRight)
                {
                    currentMirror.MoveMirrorRight(mirrorMovementSpeed);
                }
                if (moveUp)
                {
                    currentMirror.MoveMirrorUp(mirrorMovementSpeed);
                }
                if (moveDown)
                {
                    currentMirror.MoveMirrorDown(mirrorMovementSpeed);
                }

                if (!moveLeft && !moveRight && !moveUp && !moveDown)
                {
                    _mirrorMovement.ResetSpeed();
                }

                // Rotation

                float mirrorRotationSpeed = _mirrorRotation.GetSpeed();

                bool rotateCW  = InputManager.IsUserActionActive(UserAction.RotateMirrorCW);
                bool rotateCCW = InputManager.IsUserActionActive(UserAction.RotateMirrorCCW);

                if (rotateCW)
                {
                    currentMirror.RotateCW(mirrorRotationSpeed);
                }
                if (rotateCCW)
                {
                    currentMirror.RotateCCW(mirrorRotationSpeed);
                }

                if (!rotateCW && !rotateCCW)
                {
                    _mirrorRotation.ResetSpeed();
                }

                AdjustPlayerPositionAndRotation(currentMirror);
            }
            else
            {
                _mirrorMovement.ResetSpeed();
                _mirrorRotation.ResetSpeed();

                float dx = 0.0f;
                float dy = 0.0f;

                float playerMovementSpeed = _playerMovement.GetSpeed();

                if (InputManager.IsUserActionActive(UserAction.MoveUp))
                {
                    dy = playerMovementSpeed;
                }
                if (InputManager.IsUserActionActive(UserAction.MoveDown))
                {
                    dy = -playerMovementSpeed;
                }
                if (InputManager.IsUserActionActive(UserAction.MoveLeft))
                {
                    dx = -playerMovementSpeed;
                }
                if (InputManager.IsUserActionActive(UserAction.MoveRight))
                {
                    dx = playerMovementSpeed;
                }

                if (dx == 0.0f && dy == 0.0f)
                {
                    _playerMovement.ResetSpeed();
                }

                TryToMovePlayer(dx, 0.0f);
                TryToMovePlayer(0.0f, dy);
            }
        }