コード例 #1
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);
            }
        }
コード例 #2
0
ファイル: ColPair.cs プロジェクト: xNeophyte/Space_Invaders
        static public void FwdCollide(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}({2}), {1}({3})", pNodeA.name, pNodeB.name, pNodeA.GetHashCode(), pNodeB.GetHashCode());

                    // Get rectangles
                    ColRect rectA = pNodeA.GetColObject().poColRect;
                    ColRect rectB = pNodeB.GetColObject().poColRect;

                    // test them
                    if (ColRect.Intersect(rectA, rectB))
                    {
                        // Boom - it works (Visitor in Action)
                        // Debug.WriteLine("Collision Detected!");
                        pNodeA.Accept(pNodeB);
                        break;
                    }

                    pNodeB = (GameObject)pNodeB.GetNextSibling();
                }

                pNodeA = (GameObject)pNodeA.GetNextSibling();
            }
        }
コード例 #3
0
        public static void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            // A vs B
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

            //     Debug.WriteLine("\nColPair: start {0}, {1}", pNodeA.name, pNodeB.name);
            while (pNodeA != null)
            {
                // Restart compare
                pNodeB = pSafeTreeB;

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

                    // Get rectangles
                    ColRect rectA = pNodeA.GetColObject().poColRect;
                    ColRect rectB = pNodeB.GetColObject().poColRect;

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

                    pNodeB = (GameObject)pNodeB.pSibling;
                }
                pNodeA = (GameObject)pNodeA.pSibling;
            }
        }
コード例 #4
0
        static public void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

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

                while (pNodeB != null)
                {
                    ColRect rectA = pNodeA.GetColObject().poColRect;
                    ColRect rectB = pNodeB.GetColObject().poColRect;

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

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

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
コード例 #5
0
        static public void Collide(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;



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

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

                    ColRect rectA = pNodeA.GetColObject().poColRect;
                    ColRect rectB = pNodeB.GetColObject().poColRect;

                    //check if their is a collision
                    if (ColRect.Intersect(rectA, rectB))
                    {
                        //then see what the reaction is
                        pNodeA.Accept(pNodeB);

                        break;
                    }

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

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
コード例 #6
0
        //----------------------------------------------------------------------------------
        // Static Methods
        //----------------------------------------------------------------------------------
        public static void Collide(GameObject pTreeNodeA, GameObject pTreeNodeB)
        {
            // Cache A & B
            GameObject pNodeA = pTreeNodeA;
            GameObject pNodeB = pTreeNodeB;

            while (pNodeA != null)
            {
                // Start back at the top
                pNodeB = pTreeNodeB;

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

                    // Get Rectangles
                    CollRect rectA = pNodeA.GetCollObj().poColRect;
                    CollRect rectB = pNodeB.GetCollObj().poColRect;

                    // Check
                    if (CollRect.Intersect(rectA, rectB))
                    {
                        // Success, liftoff!!
                        pNodeA.Accept(pNodeB);
                        break;
                    }

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

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
コード例 #7
0
        public static void detectCollision(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            // Debug.WriteLine("Dectecting collision");
            // A vs B
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

            // Debug.WriteLine("\nColPair: start {0}, {1}", pNodeA.cGameObjectName, pNodeB.cGameObjectName);
            while (pNodeA != null)
            {
                // Restart compare
                pNodeB = pSafeTreeB;

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

                    // Get rectangles
                    CollisionRectangle rectA = pNodeA.cCollisionObj.cCollisionRectangle;
                    CollisionRectangle rectB = pNodeB.cCollisionObj.cCollisionRectangle;

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

                    pNodeB = (GameObject)pNodeB.pSibling;
                }
                pNodeA = (GameObject)pNodeA.pSibling;
            }
        }
コード例 #8
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)
                {
                    // Get rectangles
                    ColRect rectA = pNodeA.poColObj.poColRect;
                    ColRect rectB = pNodeB.poColObj.poColRect;

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

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

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
コード例 #9
0
        //FOR THE RECORD
        //I'm not proud of this, but i created another collision with a slight difference for columns
        // i'm breaking the D.R.Y rule, but i'm sucking right now
        static public void CollideColumns(GameObject pSafeTreeA, GameObject pSafeTreeB)
        {
            GameObject pNodeA = pSafeTreeA;
            GameObject pNodeB = pSafeTreeB;

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

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

                    ColRect rectA = pNodeA.GetColObject().poColRect;
                    ColRect rectB = pNodeB.GetColObject().poColRect;

                    //check if their is a collision
                    if (ColRect.Intersect(rectA, rectB))
                    {
                        //then see what the reaction is
                        pNodeA.Accept(pNodeB);
                        break;
                    }

                    //this is the change and questionable part
                    //finicky when the aliens weren't close enough
                    Component pComp = (Component)pNodeB.pNext;

                    //Checked all the Columns and there weren't any collisions so... continue
                    if (pComp == null)
                    {
                        break;
                    }

                    //check the next column
                    if (pComp.holder == Component.Container.COMPOSITE)
                    {
                        Component pTemp    = (Component)pNodeB;
                        Component pParent  = pTemp.pParent;
                        Component pSibling = ForwardIterator.GetSibling(pParent);

                        //if there are no more columns check the children of the last column?
                        if (pSibling == null)
                        {
                            pNodeB = (GameObject)ForwardIterator.GetChild(pNodeB);
                            continue;
                        }

                        pNodeB = (GameObject)ForwardIterator.GetChild(pSibling);
                        continue;
                    }
                    pNodeB = (GameObject)Iterator.GetSibling(pNodeB);
                }

                pNodeA = (GameObject)Iterator.GetSibling(pNodeA);
            }
        }
コード例 #10
0
ファイル: CollisionPair.cs プロジェクト: Arnold-2/SInvader
        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);
                }
            }
        }
コード例 #11
0
ファイル: CollisionPair.cs プロジェクト: ccaunca/Projects
        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;
            }
        }
コード例 #12
0
ファイル: CollisionPair.cs プロジェクト: wangjo22/Final
        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);
            }
        }
コード例 #13
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);
            }
        }