コード例 #1
0
ファイル: QuadTree.cs プロジェクト: broding/bunkerhunter
 public QuadTree(int level, BoundingRectangle bounds)
 {
     this.level = level;
     objects = new List<Node>();
     this.bounds = bounds;
     this.nodes = new QuadTree[4];
 }
コード例 #2
0
        /// <summary>
        /// Calculates the signed depth of intersection between two rectangles.
        /// </summary>
        /// <returns>
        /// The amount of overlap between two intersecting rectangles. These
        /// depth values can be negative depending on which wides the rectangles
        /// intersect. This allows callers to determine the correct direction
        /// to push objects in order to resolve collisions.
        /// If the rectangles are not intersecting, Vector2.Zero is returned.
        /// </returns>
        public static Vector2 GetIntersectionDepth(this BoundingRectangle rectA, BoundingRectangle rectB)
        {
            // Calculate half sizes.
            float halfWidthA = rectA.Width / 2.0f;
            float halfHeightA = rectA.Height / 2.0f;
            float halfWidthB = rectB.Width / 2.0f;
            float halfHeightB = rectB.Height / 2.0f;

            // Calculate centers.
            Vector2 centerA = new Vector2(rectA.Left + halfWidthA, rectA.Top + halfHeightA);
            Vector2 centerB = new Vector2(rectB.Left + halfWidthB, rectB.Top + halfHeightB);

            // Calculate current and minimum-non-intersecting distances between centers.
            float distanceX = centerA.X - centerB.X;
            float distanceY = centerA.Y - centerB.Y;
            float minDistanceX = halfWidthA + halfWidthB;
            float minDistanceY = halfHeightA + halfHeightB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
                return Vector2.Zero;

            // Calculate and return intersection depths.
            float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
            float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
            return new Vector2(depthX, depthY);
        }
コード例 #3
0
 public void Intersects(ref BoundingRectangle rect, out bool result)
 {
     result =
         (this.Min.X < rect.Max.X) &&
         (this.Min.Y < rect.Max.Y) &&
         (this.Max.X > rect.Min.X) &&
         (this.Max.Y > rect.Min.Y);
 }
コード例 #4
0
 public bool Intersects(BoundingRectangle rect)
 {
     return
         (this.Min.X < rect.Max.X) &&
         (this.Min.Y < rect.Max.Y) &&
         (this.Max.X > rect.Min.X) &&
         (this.Max.Y > rect.Min.Y);
 }
コード例 #5
0
 public bool Equals(BoundingRectangle other)
 {
     return
         (this.Min.X == other.Min.X) &&
         (this.Min.Y == other.Min.Y) &&
         (this.Max.X == other.Max.X) &&
         (this.Max.Y == other.Max.Y);
 }
コード例 #6
0
 static BoundingRectangle()
 {
     BoundingRectangle.mEmpty = new BoundingRectangle();
     BoundingRectangle.mMinMax = new BoundingRectangle(Vector2.One * float.MinValue, Vector2.One * float.MaxValue);
 }
コード例 #7
0
 public void Contains(ref BoundingRectangle rect, out bool result)
 {
     result =
         (this.Min.X <= rect.Min.X) &&
         (this.Min.Y <= rect.Min.Y) &&
         (this.Max.X >= rect.Max.X) &&
         (this.Max.Y >= rect.Max.Y);
 }
コード例 #8
0
 public bool Contains(BoundingRectangle rect)
 {
     return
         (this.Min.X <= rect.Min.X) &&
         (this.Min.Y <= rect.Min.Y) &&
         (this.Max.X >= rect.Max.X) &&
         (this.Max.Y >= rect.Max.Y);
 }
コード例 #9
0
        public static void Union(ref BoundingRectangle rect1, ref BoundingRectangle rect2, out BoundingRectangle result)
        {
            float num6 = rect1.Max.X;
            float num5 = rect2.Max.X;
            float num4 = rect1.Max.Y;
            float num3 = rect2.Max.Y;
            float num2 = (rect1.Min.X < rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y < rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num8 = (num6 > num5) ? num6 : num5;
            float num7 = (num4 > num3) ? num4 : num3;

            result.Min.X = num2;
            result.Min.Y = num;
            result.Max.X = num8;
            result.Max.Y = num7;
        }
コード例 #10
0
        public static BoundingRectangle Union(BoundingRectangle rect1, BoundingRectangle rect2)
        {
            BoundingRectangle result;

            float num6 = rect1.Max.X;
            float num5 = rect2.Max.X;
            float num4 = rect1.Max.Y;
            float num3 = rect2.Max.Y;
            float num2 = (rect1.Min.X < rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y < rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num8 = (num6 > num5) ? num6 : num5;
            float num7 = (num4 > num3) ? num4 : num3;

            result.Min.X = num2;
            result.Min.Y = num;
            result.Max.X = num8;
            result.Max.Y = num7;

            return result;
        }
コード例 #11
0
        public static void Intersect(ref BoundingRectangle rect1, ref BoundingRectangle rect2, out BoundingRectangle result)
        {
            float num8 = rect1.Max.X;
            float num7 = rect2.Max.X;
            float num6 = rect1.Max.Y;
            float num5 = rect2.Max.Y;
            float num2 = (rect1.Min.X > rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y > rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num4 = (num8 < num7) ? num8 : num7;
            float num3 = (num6 < num5) ? num6 : num5;

            if ((num4 > num2) && (num3 > num))
            {
                result.Min.X = num2;
                result.Min.Y = num;
                result.Max.X = num4;
                result.Max.Y = num3;
            }

            result.Min.X = 0;
            result.Min.Y = 0;
            result.Max.X = 0;
            result.Max.Y = 0;
        }
コード例 #12
0
        public static BoundingRectangle Intersect(BoundingRectangle rect1, BoundingRectangle rect2)
        {
            BoundingRectangle result;

            float num8 = rect1.Max.X;
            float num7 = rect2.Max.X;
            float num6 = rect1.Max.Y;
            float num5 = rect2.Max.Y;
            float num2 = (rect1.Min.X > rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num = (rect1.Min.Y > rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num4 = (num8 < num7) ? num8 : num7;
            float num3 = (num6 < num5) ? num6 : num5;

            if ((num4 > num2) && (num3 > num))
            {
                result.Min.X = num2;
                result.Min.Y = num;
                result.Max.X = num4;
                result.Max.Y = num3;

                return result;
            }

            result.Min.X = 0;
            result.Min.Y = 0;
            result.Max.X = 0;
            result.Max.Y = 0;

            return result;
        }
コード例 #13
0
        public void ExplodeBomb(FatBomb bomb)
        {
            soundEffectBomb.Play();

            int width = 186;
            int height = 186;

            BoundingRectangle rect = new BoundingRectangle((int)bomb.Position.X - width / 2, (int)bomb.Position.Y - height / 2, width, height);

            foreach (Vetbol player in this.players)
            {
                if (player.GetBoundingBox().Intersects(rect) && !player.IsFlickering)
                {
                    Controller.Input.SetVibrationWithTimer(player.index, TimeSpan.FromMilliseconds(300));
                    player.Deactivate();
                    if(!respawnTimers.ContainsKey(player))
                        respawnTimers.Add(player, respawnTime);
                    hud.PlayerDied(player);
                }
            }
        }