GetObjectRect() public method

public GetObjectRect ( ) : Rectangle
return System.Drawing.Rectangle
Example #1
0
        public Collision Intersects(GraphicObject SrcObject, GraphicObject DestObject)
        {
            Rectangle Src  = SrcObject.GetObjectRect();
            Rectangle Dest = DestObject.GetObjectRect();


            if (Src.X + Src.Width < Dest.X)
            {
                return(null);
            }
            if (Src.Y + Src.Height < Dest.Y)
            {
                return(null);
            }

            if (Src.X > Dest.X + Dest.Width)
            {
                return(null);
            }
            if (Src.Y > Dest.Y + Dest.Height)
            {
                return(null);
            }

            CollisionDirection Dir = CollisionDirection.CD_Down;

            int H, W;

            //Point ButtomRight = new Point(Src.X + Src.Width, Src.Y + Src.Height);
            //Point ButtomLeft = new Point(Src.X, Src.Y + Src.Height);
            //Point TopRight = new Point(Src.X + Src.Width, Src.Y);
            //Point TopLeft = new Point(Src.X, Src.Y);
            ButtomRight.X = Src.X + Src.Width;
            ButtomRight.Y = Src.Y + Src.Height;
            ButtomLeft.X  = Src.X;
            ButtomLeft.Y  = Src.Y + Src.Height;
            TopRight.X    = Src.X + Src.Width;
            TopRight.Y    = Src.Y;
            TopLeft.X     = Src.X;
            TopLeft.Y     = Src.Y;



            Boolean Found = false;

            if (Contains(ButtomRight, Dest))
            //if (Dest.Contains(ButtomRight))
            {
                Found = true;
                W     = ButtomRight.X - Dest.X;
                H     = ButtomRight.Y - Dest.Y;
                if (W > H)
                {
                    Dir = CollisionDirection.CD_Up;
                }
                else if (H > W)
                {
                    Dir = CollisionDirection.CD_Left;
                }
                else
                {
                    Dir = CollisionDirection.CD_TopLeft;
                }
            }
            if (Contains(ButtomLeft, Dest))
            //                if (Dest.Contains(ButtomLeft))
            {
                Found = true;
                W     = Dest.X + Dest.Width - ButtomLeft.X;
                H     = ButtomLeft.Y - Dest.Y;
                if (W > H)
                {
                    Dir = CollisionDirection.CD_Up;
                }
                else if (H > W)
                {
                    Dir = CollisionDirection.CD_Right;
                }
                else
                {
                    Dir = CollisionDirection.CD_TopRight;
                }
            }
            if (Contains(TopRight, Dest))
            //                if (Dest.Contains(TopRight))
            {
                Found = true;
                W     = TopRight.X - Dest.X;
                H     = Dest.Y + Dest.Height - TopRight.Y;
                if (W > H)
                {
                    Dir = CollisionDirection.CD_Down;
                }
                else
                {
                    Dir = CollisionDirection.CD_Left;
                }
            }

            if (Contains(TopLeft, Dest))
            //                if (Dest.Contains(TopLeft))
            {
                Found = true;
                W     = Dest.X + Dest.Width - TopLeft.X;
                H     = Dest.Y + Dest.Height - TopLeft.Y;// -5; //Bug
                if (W > H)
                {
                    Dir = CollisionDirection.CD_Down;
                }
                else
                {
                    Dir = CollisionDirection.CD_Right;
                }
            }

            if (Found == false)
            {
                return(null);
            }
            else
            {
                // For Better Performance.....
                MainColision.Src  = Src;
                MainColision.Dest = Dest;
                MainColision.Dir  = Dir;
                MainColision.Type = CollisionType.CT_Moveable;
                return(MainColision);
                // Old One
                //return new Collision(Src, Dest, CollisionType.CT_Moveable, Dir);
            }
        }
Example #2
0
        public Collision Intersects(GraphicObject SrcObject, GraphicObject DestObject)
        {
            Rectangle Src = SrcObject.GetObjectRect();
            Rectangle Dest = DestObject.GetObjectRect();

            if (Src.X + Src.Width < Dest.X) return null;
            if (Src.Y + Src.Height < Dest.Y) return null;

            if (Src.X > Dest.X + Dest.Width) return null;
            if (Src.Y > Dest.Y + Dest.Height) return null;

            CollisionDirection Dir = CollisionDirection.CD_Down;

            int H, W;
            //Point ButtomRight = new Point(Src.X + Src.Width, Src.Y + Src.Height);
            //Point ButtomLeft = new Point(Src.X, Src.Y + Src.Height);
            //Point TopRight = new Point(Src.X + Src.Width, Src.Y);
            //Point TopLeft = new Point(Src.X, Src.Y);
            ButtomRight.X = Src.X + Src.Width;
            ButtomRight.Y = Src.Y + Src.Height;
            ButtomLeft.X = Src.X;
            ButtomLeft.Y = Src.Y + Src.Height;
            TopRight.X = Src.X + Src.Width;
            TopRight.Y = Src.Y;
            TopLeft.X = Src.X;
            TopLeft.Y = Src.Y;

            Boolean Found = false;
            if (Contains(ButtomRight, Dest))
            //if (Dest.Contains(ButtomRight))
            {
                Found = true;
                W = ButtomRight.X - Dest.X;
                H = ButtomRight.Y - Dest.Y;
                if (W > H)
                    Dir = CollisionDirection.CD_Up;
                else if (H > W)
                    Dir = CollisionDirection.CD_Left;
                else
                    Dir = CollisionDirection.CD_TopLeft;
            }
            if (Contains(ButtomLeft, Dest))
            //                if (Dest.Contains(ButtomLeft))
            {
                Found = true;
                W = Dest.X + Dest.Width - ButtomLeft.X;
                H = ButtomLeft.Y - Dest.Y;
                if (W > H)
                    Dir = CollisionDirection.CD_Up;
                else if (H > W)
                    Dir = CollisionDirection.CD_Right;
                else
                    Dir = CollisionDirection.CD_TopRight;
            }
            if (Contains(TopRight, Dest))
            //                if (Dest.Contains(TopRight))
            {
                Found = true;
                W = TopRight.X - Dest.X;
                H = Dest.Y + Dest.Height - TopRight.Y;
                if (W > H)
                    Dir = CollisionDirection.CD_Down;
                else
                    Dir = CollisionDirection.CD_Left;
            }

            if (Contains(TopLeft, Dest))
            //                if (Dest.Contains(TopLeft))
            {
                Found = true;
                W = Dest.X + Dest.Width - TopLeft.X;
                H = Dest.Y + Dest.Height - TopLeft.Y;// -5; //Bug
                if (W > H)
                    Dir = CollisionDirection.CD_Down;
                else
                    Dir = CollisionDirection.CD_Right;
            }

            if (Found == false)
                return null;
            else
            {
                // For Better Performance.....
                MainColision.Src = Src;
                MainColision.Dest = Dest;
                MainColision.Dir = Dir;
                MainColision.Type = CollisionType.CT_Moveable;
                return MainColision;
                // Old One
                //return new Collision(Src, Dest, CollisionType.CT_Moveable, Dir);
            }
        }