Exemple #1
0
        public void UpdateCollider()
        {
            if (collider == null)
            {
                collider = new Colliders.AABB(0, 0, 1, 1, this);
            }

            switch (type)
            {
            case MovementDetectorLaser.Direction.Up:
                collider.SetNew((int)Graphics.Position.X - 1, (int)Graphics.Position.Y - preCollisionLength, (int)Graphics.Position.X + 2, (int)Graphics.Position.Y);
                break;

            case MovementDetectorLaser.Direction.Left:
                collider.SetNew((int)Graphics.Position.X - preCollisionLength, (int)Graphics.Position.Y - 1, (int)Graphics.Position.X, (int)Graphics.Position.Y + 2);
                break;

            case MovementDetectorLaser.Direction.Down:
                collider.SetNew((int)Graphics.Position.X - 1, (int)Graphics.Position.Y, (int)Graphics.Position.X + 2, (int)Graphics.Position.Y + preCollisionLength);
                break;

            case MovementDetectorLaser.Direction.Right:
                collider.SetNew((int)Graphics.Position.X, (int)Graphics.Position.Y - 1, (int)Graphics.Position.X + preCollisionLength, (int)Graphics.Position.Y + 2);
                break;

            default:
                break;
            }
        }
 public static bool AreColliding(Collider c1, Collider c2, out AABB CollisionArea)
 {
     if (c1 is AABB)
     {
         if (c2 is AABB)
             return AreColliding(c1 as AABB, c2 as AABB, out CollisionArea);
     }
     throw new NotImplementedException("Collision checker not registered for types \"" + c1.GetType().ToString() + "\" and \"" + c2.GetType().ToString() + "\"");
 }
 public static bool AreColliding(AABB c1, AABB c2, out AABB CollisionArea)
 {
     if (c1.HaveSameArea(c2))
     {
         CollisionArea = c1.GetSameArea(c2);
         return true;
     }
     CollisionArea = null;
     return false;
 }
Exemple #4
0
        public void RegisterColliders()
        {
            if (collider == null)
            {
                collider = new Colliders.AABB(0, 0, 1, 1, this);
            }
            UpdateCollider();

            collider.onCollisionStarted += new Colliders.OnCollisionEvent(collider_onCollisionStarted);
            collider.onCollidionEnded   += new Colliders.OnCollisionEvent(collider_onCollidionEnded);

            ComponentsManager.CollidersManager.AddCollider(collider);
        }
Exemple #5
0
 public CollisionInfo(Collider c1, Collider c2, AABB intersection)
 {
     this.c1 = c1;
     this.c2 = c2;
     this.intersection = intersection;
 }
Exemple #6
0
 public void RegisterColliders()
 {
     collider = new Colliders.AABB(Graphics.Position, Graphics.Position + Graphics.Size, this);
     ComponentsManager.CollidersManager.AddCollider(collider);
 }
Exemple #7
0
 public bool Intersects(AABB a)
 {
     return (a.x1 <= x1 && a.x2 >= x1 && a.y1 >= y1 && a.y1 <= y2) || //a intersects left with top
            (a.x1 <= x1 && a.x2 >= x1 && a.y2 >= y1 && a.y2 <= y2) || //a intersects left with bottom
            (a.x1 <= x2 && a.x2 >= x2 && a.y1 >= y1 && a.y1 <= y2) || //a intersects right with top
            (a.x1 <= x2 && a.x2 >= x2 && a.y2 >= y1 && a.y2 <= y2) || //a intersects right with bottom
            (a.y1 <= y1 && a.y2 >= y1 && a.x1 >= x1 && a.x1 <= x2) || //a intersects top with left
            (a.y1 <= y1 && a.y2 >= y1 && a.x2 >= x1 && a.x2 <= x2) || //a intersects top with right
            (a.y1 <= y2 && a.y2 >= y2 && a.x1 >= x1 && a.x1 <= x2) || //a intersects bottom with left
            (a.y1 <= y2 && a.y2 >= y2 && a.x2 >= x1 && a.x2 <= x2);   //a intersects bottom with right
 }
Exemple #8
0
 public bool HaveSameArea(AABB a)
 {
     return Contains(a) || a.Contains(this) || Intersects(a);
 }
Exemple #9
0
 public AABB GetSameArea(AABB a)
 {
     if (Contains(a))
         return a;
     if (a.Contains(this))
         return this;
     return GetIntersectionArea(a);
 }
Exemple #10
0
 public AABB GetIntersectionArea(AABB a)
 {
     return new AABB(Math.Max(x1, a.x1), Math.Max(y1, a.y1), Math.Min(x2, a.x2), Math.Min(y1, a.y2), parent);
 }
Exemple #11
0
 public void RegisterColliders()
 {
     collider = new Colliders.AABB(Graphics.Position + new Vector2(8, 8), Graphics.Position + Graphics.Size - new Vector2(8, 8), this);
     collider.onCollisionStarted += new Colliders.OnCollisionEvent(collider_onCollisionStarted);
     ComponentsManager.CollidersManager.AddCollider(collider);
 }
Exemple #12
0
 public void RegisterColliders()
 {
     collider = new Colliders.AABB(Graphics.Position, Graphics.Position + Graphics.Size, this);
     ComponentsManager.CollidersManager.AddCollider(collider);
 }
        public void UpdateCollider()
        {
            if (collider == null)
                collider = new Colliders.AABB(0, 0, 1, 1, this);

            switch (type)
            {
                case MovementDetectorLaser.Direction.Up:
                    collider.SetNew((int)Graphics.Position.X - 1, (int)Graphics.Position.Y - preCollisionLength, (int)Graphics.Position.X + 2, (int)Graphics.Position.Y);
                    break;
                case MovementDetectorLaser.Direction.Left:
                    collider.SetNew((int)Graphics.Position.X - preCollisionLength, (int)Graphics.Position.Y - 1, (int)Graphics.Position.X, (int)Graphics.Position.Y + 2);
                    break;
                case MovementDetectorLaser.Direction.Down:
                    collider.SetNew((int)Graphics.Position.X - 1, (int)Graphics.Position.Y, (int)Graphics.Position.X + 2, (int)Graphics.Position.Y + preCollisionLength);
                    break;
                case MovementDetectorLaser.Direction.Right:
                    collider.SetNew((int)Graphics.Position.X, (int)Graphics.Position.Y - 1, (int)Graphics.Position.X + preCollisionLength, (int)Graphics.Position.Y + 2);
                    break;
                default:
                    break;
            }
        }
        public void RegisterColliders()
        {
            if (collider == null)
                collider = new Colliders.AABB(0, 0, 1, 1, this);
            UpdateCollider();

            collider.onCollisionStarted += new Colliders.OnCollisionEvent(collider_onCollisionStarted);
            collider.onCollidionEnded += new Colliders.OnCollisionEvent(collider_onCollidionEnded);

            ComponentsManager.CollidersManager.AddCollider(collider);
        }
        private CollisionInfo RegisterCollision(Collider c1, Collider c2, AABB intersection)
        {
            for (int i = 0; i < collisions.Count; i++)
            {
                if ((collisions[i].c1 == c1 && collisions[i].c2 == c2) || (collisions[i].c1 == c2 && collisions[i].c2 == c1))
                {
                    return collisions[i];
                }
            }
            CollisionInfo c = new CollisionInfo(c1, c2, intersection);
            collisions.Add(c);

            c1.InvokeCollisionStarted(c);
            c2.InvokeCollisionStarted(c);
            if (onCollisionStarted != null)
                onCollisionStarted.Invoke(c);

            return c;
        }
Exemple #16
0
 public void RegisterColliders()
 {
     collider = new Colliders.AABB(Graphics.Position + new Vector2(8, 8), Graphics.Position + Graphics.Size - new Vector2(8, 8), this);
     collider.onCollisionStarted += new Colliders.OnCollisionEvent(collider_onCollisionStarted);
     ComponentsManager.CollidersManager.AddCollider(collider);
 }
Exemple #17
0
 public bool Contains(AABB a)
 {
     return a.x1 > x1 && a.y1 > y1 && x2 > a.x2 && y2 > a.y2;
 }