Пример #1
0
        /// <summary> Проверить пересичение Actor2D с Trigger. </summary>
        /// <param name="a"> Актер. </param>
        /// <param name="t"> Триггер. </param>
        public static bool ActorTrigger(IActor a, Trigger t)
        {
            switch (t.type)
            {
            case GeometryType.Point:

                var r = a.GetRectCollision();
                var p = t.points[0];
                return p.X >= r.X && p.Y >= r.X && p.X <= r.X + r.Width && p.Y <= r.X + r.Height;

            case GeometryType.Line:
                return RectLine(a.GetRectCollision(), t.points[0], t.points[1]);

            case GeometryType.Rect:
                return
                    a.GetRectCollision().Intersects(new RectangleF(t.points[0].X, t.points[0].Y, t.points[1].X,
                        t.points[1].Y));

            //case GeometryType.Polygon:
            // TODO: GeometryType.Polygon
            default:
                throw new NotImplementedException("[DE] Collision: Тип геометрии " + t.type + " не реализован.");
            }
        }
Пример #2
0
        /// <summary> Проверка столкновение с актерами с учётом групп. </summary>
        /// <param name="a1"> Первый актер. </param>
        /// <param name="a2"> Второй актер. </param>
        /// <param name="checkGroup"> Учитывать группы столкновений. null - не проверять. </param>
        public static bool ActorActor(IActor a1, IActor a2, string checkGroup = null)
        {
            if (a1 == null || a1.Width <= 0 || a1.Height <= 0 || a2 == null || a2.Width <= 0 || a2.Height <= 0)
            {
                return false;
            }

            if (checkGroup != null && !Groups.GroupWith(a1.Group, a2.Group))
            {
                return false;
            }

            return a1.GetRectCollision().Intersects(a2.GetRectCollision());
        }