Ejemplo n.º 1
0
        /// <summary>
        /// Does this Hitbox intersect with another one.
        /// </summary>
        /// <param name="hb">Hb.</param>
        /// <param name="xOff">X off.</param>
        /// <param name="yOff">Y off.</param>
        public CollisionResult IntersectHitbox(Hitbox hb, float speedX, float speedY)
        {
            var corners = GetCorners(speedX, speedY);

            foreach (var corner in corners) {
                if (corner.x > hb.left && corner.x < hb.right) {
                    if (corner.y > hb.bottom && corner.y < hb.top) {

                        var translation = new Vector2();

                        if (Center.x < hb.Center.x) {
                            translation.x = hb.left - right;
                        } else {
                            translation.x = hb.right - left;
                        }

                        if (Center.y > hb.Center.y) {
                            translation.y = hb.top - bottom;
                        } else {
                            translation.y = hb.bottom - top;
                        }

                        return new CollisionResult() {
                            Intersect = true,
                            Collider = hb,
                            CollisionObject = hb.GetGameObject(),
                            MinimumTranslation = translation
                        };
                    }
                }
            }

            return new CollisionResult() {
                Intersect = false
            };
        }
Ejemplo n.º 2
0
        public PolygonCollisionUtil.PolygonCollisionResult IntersectHitbox(Hitbox hb, float speedX, float speedY)
        {
            var poly = hb.GetPolygonRepresentation(0, 0);
            lastHitboxPoly = poly;

            return PolygonCollisionUtil.PolygonCollision(GetPolygonAtPosition(speedX, speedY), poly, new Vector2(0, 0));
        }