Exemple #1
0
        public void LineCircleIntersection()
        {
            BoundaryCircle circleOnOrigin = new BoundaryCircle(1.0f, new Vector2D(0.0f,0.0f));

            Line intersectingLine = new Line(new Vector2D(-1.0f, -1.0f), new Vector2D(1.0f, 1.0f));
            Line nonIntersectingLine = new Line(new Vector2D(-1.0f, 1.0f), new Vector2D(1.0f, 2.0f));
            Line boundedNonIntersectingLine = new Line(new Vector2D(1.1f, 1.1f), new Vector2D(2.6f, 2.6f));
            Line internalLine = new Line(new Vector2D(0.5f, 0.5f), new Vector2D(0.4f, 0.4f));

            Assert.IsTrue(circleOnOrigin.TestIntersection(intersectingLine));
            Assert.IsFalse(circleOnOrigin.TestIntersection(nonIntersectingLine));
            Assert.IsFalse(circleOnOrigin.TestIntersection(boundedNonIntersectingLine));
            Assert.IsTrue(circleOnOrigin.TestIntersection(internalLine));
        }
 public static bool TestIntersection(this Bounds bounds, BoundaryCircle circle)
 {
     if (bounds is BoundaryCircle)
     {
         return circle.TestIntersection(bounds as BoundaryCircle);
     }
     else if (bounds is BoundaryRect)
     {
         return circle.TestIntersection(bounds as BoundaryRect);
     }
     else
     {
         throw new InvalidOperationException("Attempting to test boundary on unknown types");
     }
 }
Exemple #3
0
    void Start()
    {
        boundary         = GameObject.FindGameObjectWithTag("Boundary").GetComponent <BoundaryCircle>();
        cursor           = GameObject.FindGameObjectWithTag("Cursor");
        reflectionArea   = GameObject.FindGameObjectWithTag("ReflectionArea");
        cameraShake      = Camera.main.GetComponent <CameraShake>();
        teleportGauge    = GameObject.FindGameObjectWithTag("TeleportGauge").GetComponent <Slider>();
        timeControlGauge = GameObject.FindGameObjectWithTag("TimeControlGauge").GetComponent <Slider>();
        lifeText         = GameObject.FindGameObjectWithTag("LifeText").GetComponent <Text>();
        destructible     = GetComponent <Destructible>();

        GetComponent <MeshRenderer>().material.color = playerColor;

        teleportTimer    = teleportDelay;
        timeControlTimer = timeControlDuration;
    }
 public static bool DoesCircleIntersectRect(BoundaryRect rect, BoundaryCircle circle)
 {
     // 2 cases:
     // case 1: the center of the circle is within the rect
     // case 2: the rectange has an edge that intersects the circle
     if (rect.ContainsPoint(circle.Center))
     {
         return true;
     }
     else
     {
         return  rect.Top.TestIntersection(circle) ||
                 rect.Bottom.TestIntersection(circle) ||
                 rect.Left.TestIntersection(circle) ||
                 rect.Right.TestIntersection(circle);
     }
 }
Exemple #5
0
 void Start()
 {
     boundaryCircle = GameObject.FindGameObjectWithTag("Boundary").GetComponent <BoundaryCircle>();
     boundaryCircle.targetRadius = boundaryRadius[level];
 }
 public static bool TestIntersection(this Line line, BoundaryCircle circle)
 {
     return DoesLineIntersectCircle(circle, line);
 }
 public static bool TestIntersection(this BoundaryRect rect, BoundaryCircle circle)
 {
     return DoesCircleIntersectRect(rect, circle);
 }
 public static bool DoesLineIntersectCircle(BoundaryCircle circle, Line line)
 {
     return MathHelper.DistanceBetweenPointAndLineSegment(circle.Center, line) < circle.Radius;
 }