예제 #1
0
        protected void BaseUpdateBoundingBox()
        {
            // Go to first child
            Component  pComponent = (Component)this;
            GameObject pNode      = (GameObject)ForwardIterator.GetChild(pComponent);

            Debug.Assert(pNode != null);

            CollisionRect ColTotal = this.pCollisionObject.GetCollisionRect();

            ColTotal.Set(pNode.GetCollisionObject().GetCollisionRect());

            // loop through sliblings
            while (pNode != null)
            {
                ColTotal.Union(pNode.GetCollisionObject().GetCollisionRect());

                // go to next sibling
                pComponent = ForwardIterator.GetSibling(pNode);

                if (pComponent != null)
                {
                    pNode = (GameObject)pComponent;
                }
                else
                {
                    pNode = null;
                }
            }

            this.x = this.GetCollisionObject().GetCollisionRect().x;
            this.y = this.GetCollisionObject().GetCollisionRect().y;

            //Debug.WriteLine("x:{0} y:{1} w:{2} h:{3}", ColTotal.x, ColTotal.y, ColTotal.width, ColTotal.height);
        }
예제 #2
0
        //----------------------------------------------------------------------
        // Static methods
        //----------------------------------------------------------------------
        public static void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            // treeA vs treeB
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

            while (pNodeA != null)
            {
                // restart compare
                pNodeB = pSafeTreeB;

                while (pNodeB != null)
                {
                    //Debug.WriteLine("ColPair:    test:  {0}, {1}", pNodeA.getName(), pNodeB.getName());

                    // get rectangles
                    CollisionRect rectA = pNodeA.poCollisionObject.poCollisionRect;
                    CollisionRect rectB = pNodeB.poCollisionObject.poCollisionRect;

                    if (CollisionRect.Intersect(rectA, rectB))
                    {
                        // when rectA and rectB are intersected
                        pNodeA.accept(pNodeB);
                        break;
                    }

                    pNodeB = (GameObject)Iterator.GetSibling(pNodeB);
                }

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
예제 #3
0
        //----------------------------------------------------------------------
        // Static methods
        //----------------------------------------------------------------------
        public static bool Intersect(CollisionRect colRectA, CollisionRect colRectB)
        {
            bool status = false;

            float A_minx = colRectA.x - colRectA.width / 2;
            float A_maxx = colRectA.x + colRectA.width / 2;
            float A_miny = colRectA.y - colRectA.height / 2;
            float A_maxy = colRectA.y + colRectA.height / 2;

            float B_minx = colRectB.x - colRectB.width / 2;
            float B_maxx = colRectB.x + colRectB.width / 2;
            float B_miny = colRectB.y - colRectB.height / 2;
            float B_maxy = colRectB.y + colRectB.height / 2;

            // Trivial reject
            if ((B_maxx < A_minx) || (B_minx > A_maxx) || (B_maxy < A_miny) || (B_miny > A_maxy))
            {
                status = false;
            }
            else
            {
                status = true;
            }


            return(status);
        }
예제 #4
0
        static public void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            // A vs B
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

            while (pNodeA != null)
            {
                pNodeB = pSafeTreeB;

                while (pNodeB != null)
                {
                    // Get rectangles
                    CollisionRect rectA = pNodeA.GetCollisionObject().GetCollisionRect();
                    CollisionRect rectB = pNodeB.GetCollisionObject().GetCollisionRect();

                    if (CollisionRect.Intersect(rectA, rectB))
                    {
                        pNodeA.Accept(pNodeB);
                        //break;
                    }

                    pNodeB = Iterator.GetSiblingGameObject(pNodeB);
                }

                pNodeA = Iterator.GetSiblingGameObject(pNodeA);
            }
        }
예제 #5
0
        static public void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            // A vs B
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

            while (pNodeA != null)
            {
                // Restart compare
                pNodeB = pSafeTreeB;

                while (pNodeB != null)
                {
                    // who is being tested?
                    //Debug.WriteLine("ColPair:    test:  {0}, {1}", pNodeA.name, pNodeB.name);

                    // Get rectangles
                    CollisionRect rectA = pNodeA.GetCollisionObject().poCollisionRect;
                    CollisionRect rectB = pNodeB.GetCollisionObject().poCollisionRect;

                    // test them
                    if (CollisionRect.Intersect(rectA, rectB))
                    {
                        // Boom - it works (Visitor in Action)
                        pNodeA.Accept(pNodeB);
                        break;
                    }

                    pNodeB = (GameObject)Iterator.GetSibling(pNodeB);
                }

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
예제 #6
0
        protected void BaseUpdateBoundingBox(Component pStart)
        {
            GameObject pNode = (GameObject)pStart;

            // point to ColTotal
            CollisionRect ColTotal = this.poCollisionObject.poCollisionRect;

            // Get the first child
            pNode = (GameObject)Iterator.GetChild(pNode);

            if (pNode != null)
            {
                // Initialized the union to the first block
                ColTotal.Set(pNode.poCollisionObject.poCollisionRect);

                // loop through sliblings
                while (pNode != null)
                {
                    ColTotal.union(pNode.poCollisionObject.poCollisionRect);

                    // go to next sibling
                    pNode = (GameObject)Iterator.GetSibling(pNode);
                }

                //this.poColObj.poColRect.Set(201, 201, 201, 201);
                this.x = this.poCollisionObject.poCollisionRect.x;
                this.y = this.poCollisionObject.poCollisionRect.y;

                //  Debug.WriteLine("x:{0} y:{1} w:{2} h:{3}", ColTotal.x, ColTotal.y, ColTotal.width, ColTotal.height);
            }
        }
예제 #7
0
        public void setDimension(CollisionRect r)
        {
            this.x      = r.x;
            this.y      = r.y;
            this.width  = r.width;
            this.height = r.height;

            this.box.setDimension(r);
            this.box.Update();
        }
예제 #8
0
 static public bool Intersect(CollisionRect pA, CollisionRect pB)
 {
     if (pA.x + pA.width / 2 < pB.x - pB.width / 2 ||
         pB.x + pB.width / 2 < pA.x - pA.width / 2 ||
         pA.y + pA.height / 2 < pB.y - pB.height / 2 ||
         pB.y + pB.height / 2 < pA.y - pA.height / 2)
     {
         return(false);
     }
     return(true);
 }
예제 #9
0
        public void Collide()
        {
            GameObject currentHost    = this.treeHost;
            GameObject currentVisitor = this.treeVisitor;

            // It is not possible to hit column before grid
            //  There's no standalone column

            if (currentHost.isComposite)
            {
                // if current host collide with the current visitor, go next level
                if (CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect))
                {
                    // Go to column level
                    currentHost = (GameObject)currentHost.pChildHead;
                    while (currentHost != null)
                    {
                        if (CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect))
                        {
                            // Go to leaf level
                            currentHost = (GameObject)currentHost.pChildHead;
                            while (currentHost != null)
                            {
                                if (currentHost.collidable && CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect))
                                {
                                    Debug.Print("<CollisionPair>: Collided!");

                                    // Visitor visits host
                                    currentHost.Accept(this.treeVisitor);
                                    return;
                                }
                                currentHost = (GameObject)currentHost.pNextSibling;
                            }
                        }
                        if (currentHost != null)
                        {
                            currentHost = (GameObject)currentHost.pNextSibling;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                if (this.treeHost.collidable && (CollisionRect.Intersect(currentHost.colliRect, currentVisitor.colliRect)))
                {
                    this.treeHost.Accept(this.treeVisitor);
                }
            }
        }
예제 #10
0
        //----------------------------------------------------------------------
        // Methods
        //----------------------------------------------------------------------
        // add boxes together
        public void union(CollisionRect colRect)
        {
            float minX = ((this.x - this.width / 2) < (colRect.x - colRect.width / 2)) ? (this.x - this.width / 2) : (colRect.x - colRect.width / 2);
            float maxX = ((this.x + this.width / 2) > (colRect.x + colRect.width / 2)) ? (this.x + this.width / 2) : (colRect.x + colRect.width / 2);
            float minY = ((this.y - this.height / 2) < (colRect.y - colRect.height / 2)) ? (this.y - this.height / 2) : (colRect.y - colRect.height / 2);
            float maxY = ((this.y + this.height / 2) > (colRect.y + colRect.height / 2)) ? (this.y + this.height / 2) : (colRect.y + colRect.height / 2);

            this.width  = (maxX - minX);
            this.height = (maxY - minY);
            this.x      = minX + this.width / 2;
            this.y      = minY + this.height / 2;
        }
예제 #11
0
        public void Union(CollisionRect CollisionRect)
        {
            float minX;
            float minY;
            float maxX;
            float maxY;

            // give minX the leftmost edge
            if ((this.x - this.width / 2) < (CollisionRect.x - CollisionRect.width / 2))
            {
                minX = (this.x - this.width / 2);
            }
            else
            {
                minX = (CollisionRect.x - CollisionRect.width / 2);
            }

            // give maxX the rightmost edge
            if ((this.x + this.width / 2) > (CollisionRect.x + CollisionRect.width / 2))
            {
                maxX = (this.x + this.width / 2);
            }
            else
            {
                maxX = (CollisionRect.x + CollisionRect.width / 2);
            }

            // give maxY the upper edge
            if ((this.y + this.height / 2) > (CollisionRect.y + CollisionRect.height / 2))
            {
                maxY = (this.y + this.height / 2);
            }
            else
            {
                maxY = (CollisionRect.y + CollisionRect.height / 2);
            }

            // give minY the lower edge
            if ((this.y - this.height / 2) < (CollisionRect.y - CollisionRect.height / 2))
            {
                minY = (this.y - this.height / 2);
            }
            else
            {
                minY = (CollisionRect.y - CollisionRect.height / 2);
            }

            this.width  = (maxX - minX);
            this.height = (maxY - minY);
            this.x      = minX + this.width / 2;
            this.y      = minY + this.height / 2;
        }
예제 #12
0
        public CollisionObject(ProxySprite proxySprite)
        {   // we'll pass in proxySprites to generate collision boxes around
            Debug.Assert(proxySprite != null);
            Sprite pSprite = proxySprite.pSprite;

            Debug.Assert(pSprite != null);
            this.pCollisionRect = new CollisionRect(pSprite.GetScreenRect());
            //Debug.WriteLine("ProxySprite Rect for {0}:({1},{2}),w:{3},h:{4}", proxySprite.pSprite.name, proxySprite.x, proxySprite.y, proxySprite.pSprite.pScreenRect.width, proxySprite.pSprite.pScreenRect.height);
            //Debug.WriteLine("CollisionRect for {0}:({1},{2}),w:{3},h:{4}", proxySprite.pSprite.name, this.pCollisionRect.x, this.pCollisionRect.y, this.pCollisionRect.width, this.pCollisionRect.height);
            this.pCollisionSpriteBox = SpriteBoxManager.Add(SpriteBaseName.Box, this.pCollisionRect);
            Debug.Assert(this.pCollisionSpriteBox != null);
            this.pCollisionSpriteBox.pLineColor = ColorFactory.Create(ColorName.Red).pAzulColor;
        }
예제 #13
0
        public BoxSprite AddBoxSprite(CollisionRect rect)
        {
            BoxSprite ret = (BoxSprite)this.PullFromReserved();

            // Modify the field
            ret.name            = BoxSprite.Name.CollisionRectBox;
            ret.poRect          = rect;
            ret.color           = new Azul.Color(1, 1, 1);
            ret.poAzulSpriteBox = new Azul.SpriteBox(ret.poRect, ret.color);

            this.Add(ret);

            return(ret);
        }
예제 #14
0
        public void Union(CollisionRect ColRect)
        {
            float minX;
            float minY;
            float maxX;
            float maxY;


            if ((this.x - this.width / 2) < (ColRect.x - ColRect.width / 2))
            {
                minX = (this.x - this.width / 2);
            }
            else
            {
                minX = (ColRect.x - ColRect.width / 2);
            }

            if ((this.x + this.width / 2) > (ColRect.x + ColRect.width / 2))
            {
                maxX = (this.x + this.width / 2);
            }
            else
            {
                maxX = (ColRect.x + ColRect.width / 2);
            }

            if ((this.y + this.height / 2) > (ColRect.y + ColRect.height / 2))
            {
                maxY = (this.y + this.height / 2);
            }
            else
            {
                maxY = (ColRect.y + ColRect.height / 2);
            }

            if ((this.y - this.height / 2) < (ColRect.y - ColRect.height / 2))
            {
                minY = (this.y - this.height / 2);
            }
            else
            {
                minY = (ColRect.y - ColRect.height / 2);
            }

            this.width  = (maxX - minX);
            this.height = (maxY - minY);
            this.x      = minX + this.width / 2;
            this.y      = minY + this.height / 2;
        }
예제 #15
0
        public void Union(CollisionRect pRect)
        {
            float minX;
            float minY;
            float maxX;
            float maxY;

            if (this.x - this.width / 2 < pRect.x - pRect.width / 2)
            {
                minX = this.x - this.width / 2;
            }
            else
            {
                minX = pRect.x - pRect.width / 2;
            }

            if ((this.x + this.width / 2) > (pRect.x + pRect.width / 2))
            {
                maxX = this.x + this.width / 2;
            }
            else
            {
                maxX = pRect.x + pRect.width / 2;
            }

            if (this.y + this.height / 2 > pRect.y + pRect.height / 2)
            {
                maxY = this.y + this.height / 2;
            }
            else
            {
                maxY = pRect.y + pRect.height / 2;
            }

            if ((this.y - this.height / 2) < (pRect.y - pRect.height / 2))
            {
                minY = this.y - this.height / 2;
            }
            else
            {
                minY = pRect.y - pRect.height / 2;
            }

            this.width  = (maxX - minX);
            this.height = (maxY - minY);
            this.x      = minX + this.width / 2;
            this.y      = minY + this.height / 2;
        }
예제 #16
0
        protected void BaseUpdateBoundingBox()
        {
            GameObject pNode = (GameObject)ForwardIterator.GetChild(this);
            CollisionRect pBigRect = this.pColObject.pColRect;
            if (pNode != null)
            {
                pBigRect.Set(pNode.pColObject.pColRect);
            }
            while (pNode != null)
            {
                pBigRect.Union(pNode.pColObject.pColRect);
                pNode = (GameObject)ForwardIterator.GetSibling(pNode);
            }

            this.x = this.pColObject.pColRect.x;
            this.y = this.pColObject.pColRect.y;
        }
예제 #17
0
        public CollisionObject(SpriteProxy pSpriteProxy)
        {
            Debug.Assert(pSpriteProxy != null);

            // Create Collision Rect
            // Use the reference sprite to set size and shape
            Sprite pSprite = pSpriteProxy.GetSprite();

            Debug.Assert(pSprite != null);

            // Origin is in the UPPER RIGHT
            this.pCollisionRect = new CollisionRect(pSprite.GetScreenRect());
            Debug.Assert(this.pCollisionRect != null);

            // Create the sprite
            this.pCollisionSprite = SpriteBoxManager.Add(SpriteBox.Name.Box, this.pCollisionRect.x, this.pCollisionRect.y, this.pCollisionRect.width, this.pCollisionRect.height);
            Debug.Assert(this.pCollisionSprite != null);
            this.pCollisionSprite.SetLineColor(1.0f, 0.0f, 0.0f);
        }
예제 #18
0
        // Update collision box based on child
        public void UpdateCompositeBox()
        {
            if (!this.isComposite)
            {
                return;
            }


            GameObject    current = (GameObject)this.pChildHead;
            CollisionRect cr      = null;

            while (current != null)
            {
                if (current.collidable || current.isComposite)
                {
                    // get box from first collidable child
                    if (cr == null)
                    {
                        cr = new CollisionRect(current.colliRect);
                    }
                    else
                    {
                        cr.Union(current.colliRect);
                    }
                }
                current = (GameObject)current.pNextSibling;
            }

            // no collidable child, shrink box to parent's center
            if (cr == null && this.pParent != null)
            {
                GameObject parent = (GameObject)this.pParent;
                cr = new CollisionRect(parent.colliRect.x, parent.colliRect.y, 0.1f, 0.1f);
            }
            else if (cr == null && this.pParent == null)
            {
                cr = new CollisionRect(this.colliRect.x, this.colliRect.y, 0.1f, 0.1f);
            }


            this.colliRect.setDimension(cr);
        }
        public CollisionObject(ProxySprite pProxySprite)
        {
            Debug.Assert(pProxySprite != null);

            // Create Collision Rect
            // Use the reference sprite to set size and shape
            // need to refactor if you want it different
            GameSprite pSprite = pProxySprite.pSprite;

            Debug.Assert(pSprite != null);

            // Origin is in the UPPER RIGHT
            this.poColRect = new CollisionRect(pSprite.GetScreenRect());
            Debug.Assert(this.poColRect != null);

            // Create the sprite
            this.pColSprite = BoxSpriteManager.Add(BoxSprite.Name.Box, this.poColRect.x, this.poColRect.y, this.poColRect.width, this.poColRect.height);
            Debug.Assert(this.pColSprite != null);
            this.pColSprite.SetLineColor(1.0f, 1.0f, 0.0f);
        }
예제 #20
0
        public GameObject Wash()
        {
            category      = Category.Uninitialized;
            id            = 0;
            pProxy        = null;
            mGameSprtName = GameSprite.Name.Uninitialized;
            mGameSprite   = null;
            colliRect     = null;
            collidable    = true;
            isComposite   = false;
            compositeType = CompositeType.NotComposite;
            dropID        = 0;

            this.pChildHead   = null;
            this.pNextSibling = null;
            this.pPrevSibling = null;
            this.pParent      = null;


            return(this);
        }
예제 #21
0
        protected void UpdateBoundingBox()
        {
            PCSNode node = (PCSNode)this;

            node = node.pChild;

            GameObject go = (GameObject)node;

            CollisionRect collisionTotal = this.pCollisionObject.pCollisionRect;

            collisionTotal.Set(go.pCollisionObject.pCollisionRect);

            while (node != null)
            {
                go = (GameObject)node;
                collisionTotal.Union(go.pCollisionObject.pCollisionRect);
                node = node.pSibling;
            }
            this.x = this.pCollisionObject.pCollisionRect.x;
            this.y = this.pCollisionObject.pCollisionRect.y;
        }
예제 #22
0
        public static void Collide(GameObject gameObject1, GameObject gameObject2)
        {
            GameObject go1 = gameObject1;
            GameObject go2 = gameObject2;

            while (go1 != null)
            {
                go2 = gameObject2;
                while (go2 != null)
                {
                    CollisionRect collisionRect1 = go1.pCollisionObject.pCollisionRect;
                    CollisionRect collisionRect2 = go2.pCollisionObject.pCollisionRect;
                    if (CollisionRect.Intersect(collisionRect1, collisionRect2))
                    {
                        go1.Accept(go2);
                        break;
                    }
                    go2 = (GameObject)go2.pSibling;
                }
                go1 = (GameObject)go1.pSibling;
            }
        }
예제 #23
0
        static public void Collide(GameObject pTreeA, GameObject pTreeB)
        {
            GameObject pNodeA = pTreeA;
            GameObject pNodeB = pTreeB;

            while (pNodeA != null)
            {
                pNodeB = pTreeB;
                while (pNodeB != null)
                {
                    CollisionRect rectA = pNodeA.pColObject.pColRect;
                    CollisionRect rectB = pNodeB.pColObject.pColRect;
                    //Debug.WriteLine("Collision Pair : {0} <----------> {1}", pNodeA.name, pNodeB.name);
                    if (CollisionRect.Intersect(rectA, rectB))
                    {
                        pNodeA.Accept(pNodeB);
                        break;
                    }
                    pNodeB = Iterator.GetSiblingGameObject(pNodeB);
                }
                pNodeA = Iterator.GetSiblingGameObject(pNodeA);
            }
        }
예제 #24
0
        public static void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            GameObject NodeA = pSafeTreeA;
            GameObject NodeB = pSafeTreeB;

            while (NodeA != null)
            {
                NodeB = pSafeTreeB;
                while (NodeB != null)
                {
                    CollisionRect rectA = NodeA.CollisionObj.Rect;
                    CollisionRect rectB = NodeB.CollisionObj.Rect;

                    if (rectA.Intersect(rectB))
                    {
                        NodeA.Accept(NodeB);
                        break;
                    }
                    NodeB = (GameObject)Iterator.GetSibling(NodeB);
                }
                NodeA = (GameObject)Iterator.GetSibling(NodeA);
            }
        }
예제 #25
0
        static public bool Intersect(CollisionRect ColRectA, CollisionRect ColRectB)
        {
            float A_minX = ColRectA.x - ColRectA.width / 2;
            float A_minY = ColRectA.y - ColRectA.height / 2;
            float A_maxX = ColRectA.x + ColRectA.width / 2;
            float A_maxY = ColRectA.y + ColRectA.height / 2;

            float B_minX = ColRectB.x - ColRectB.width / 2;
            float B_minY = ColRectB.y - ColRectB.height / 2;
            float B_maxX = ColRectB.x + ColRectB.width / 2;
            float B_maxY = ColRectB.y + ColRectB.height / 2;

            bool isIntersected;

            if (A_minX > B_maxX || A_maxX < B_minX || A_minY > B_maxY || A_maxY < B_minY)
            {
                isIntersected = false;
            }
            else
            {
                isIntersected = true;
            }
            return(isIntersected);
        }
예제 #26
0
        public static bool Intersect(CollisionRect rect1, CollisionRect rect2)
        {   // use picture and explanation from class
            bool result = false;
            // rect1's min and max values per axes
            float rect1MinX = rect1.x - rect1.width / 2.0f;
            float rect1MaxX = rect1.x + rect1.width / 2.0f;
            float rect1MinY = rect1.y - rect1.height / 2.0f;
            float rect1MaxY = rect1.y + rect1.height / 2.0f;
            // rect2's min and max values per axes
            float rect2MinX = rect2.x - rect2.width / 2.0f;
            float rect2MaxX = rect2.x + rect2.width / 2.0f;
            float rect2MinY = rect2.y - rect2.height / 2.0f;
            float rect2MaxY = rect2.y + rect2.height / 2.0f;

            if (rect2MaxX < rect1MinX || rect2MinX > rect1MaxX || rect2MaxY < rect1MinY || rect2MinY > rect1MaxY)
            {
                result = false;
            }
            else
            {
                result = true;
            }
            return(result);
        }
예제 #27
0
 public void SetRect(CollisionRect pRect)
 {
     base.Set(pRect);
 }
예제 #28
0
 internal void Set(CollisionRect collisionTotal)
 {
     this.pCollisionRect.Set(collisionTotal);
     this.pCollisionSpriteBox.Set(SpriteBaseName.Box, collisionTotal.x, collisionTotal.y, collisionTotal.width, collisionTotal.height);
 }
예제 #29
0
 public CollisionRect(CollisionRect pRect)
     : base(pRect)
 {
     box = BoxSpriteManager.getInstance().AddBoxSprite(this);
 }
예제 #30
0
 public CollisionRect(CollisionRect pRect)
     : base(pRect)
 {
 }