Exemplo n.º 1
0
        private int getObjectNodeID(GameObject obj)
        {
            //Lấy bounding box của obj
            MyRECT rectObject = obj.getBoundingBoxInWorldAxis();

            MyRECT rectLT = this.NodeLT.getBoundingBox();
            MyRECT rectRT = this.NodeRT.getBoundingBox();
            MyRECT rectLB = this.NodeLB.getBoundingBox();
            MyRECT rectRB = this.NodeRB.getBoundingBox();

            //Kiểm tra xem Object có nằm trọn trong node phần tư nào
            if (rectLT.Contains(rectObject))
            {
                return(1);
            }
            else if (rectRT.Contains(rectObject))
            {
                return(2);
            }
            else if (rectLB.Contains(rectObject))
            {
                return(3);
            }
            else if (rectRB.Contains(rectObject))
            {
                return(4);
            }
            else //Nếu Object nằm ở nhiều node
            {
                int id = 0;
                if (rectObject.Intersects(rectLT))
                {
                    id = 1;
                }

                if (rectObject.Intersects(rectRT))
                {
                    id = id * 10 + 2;
                }

                if (rectObject.Intersects(rectLB))
                {
                    id = id * 10 + 3;
                }

                if (rectObject.Intersects(rectRB))
                {
                    id = id * 10 + 4;
                }

                return(id);
            }
        }
Exemplo n.º 2
0
        public GameObject(int left, int top, int right, int bottom, MyRECT moveRect, EObjectID objID, int posX = 0, int posY = 0)
        {
            mLeft      = left;
            mTop       = top;
            mRight     = right;
            mBottom    = bottom;
            mObjID     = objID;
            mPositionX = posX;
            mPositionY = posY;

            MStairLayer = 0;

            this.mMoveRect = moveRect;
        }
Exemplo n.º 3
0
        public GameObject(int left, int top, int right, int bottom, EObjectID objID, int posX = 0, int posY = 0, int stairLayer = 0, int stairLayerCh1 = 0)
        {
            mLeft      = left;
            mTop       = top;
            mRight     = right;
            mBottom    = bottom;
            mObjID     = objID;
            mPositionX = posX;
            mPositionY = posY;

            mStairLayer = stairLayer;

            mStairLayerChangeFr = stairLayer;
            MStairLayerChangeTo = stairLayerCh1;

            this.mMoveRect = new MyRECT(0, 0, 0, 0);
        }
Exemplo n.º 4
0
 //Kiểm tra xem hcn rect có giao với hcn this không
 public bool Intersects(MyRECT rect)
 {
     return(!(this.mLeft > rect.mRight || this.mRight < rect.mLeft || this.mTop < rect.mBottom || this.mBottom > rect.mTop));
 }
Exemplo n.º 5
0
 //Kiểm tra xem hcn rect có nằm trong hcn this không
 public bool Contains(MyRECT rect)
 {
     return((mLeft <= rect.mLeft) && (mRight >= rect.MRight) && (mTop >= rect.mTop) && (rect.mBottom >= mBottom));
 }