Exemplo n.º 1
0
        private void TryToMovePlayer(float dx, float dy)
        {
            ILogicalPlayer tempPlayer = Player.CreateClone();
            bool           movePlayer = true;

            Vector2 delta = new Vector2(dx, dy);

            tempPlayer.Position += delta;

            if (Util.HasIntersection(tempPlayer, CurrentRoom.GetNonReflectingBounds()))
            {
                movePlayer = false;
            }
            if (Util.HasIntersection(tempPlayer, CurrentRoom.GetReflectingBounds()))
            {
                movePlayer = false;
            }
            if (Util.HasIntersection(tempPlayer, CurrentRoom.GetLightBounds()) && !_godMode)
            {
                movePlayer = false;
            }

            if (movePlayer)
            {
                Player.Position += delta;
            }
        }
Exemplo n.º 2
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);
                }
            }
        }