示例#1
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;
            }
        }
示例#2
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);
            }
        }
示例#3
0
        protected void BaseUpdateBoundingBox(Component pStart)
        {
            GameObject pNode = (GameObject)pStart;

            // point to ColTotal
            ColRect ColTotal = this.poColObj.poColRect;

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

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

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

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

                this.x = this.poColObj.poColRect.x;
                this.y = this.poColObj.poColRect.y;
            }
        }
示例#4
0
        static public bool Intersect(ColRect ColRect_A, ColRect ColRect_B)
        {
            bool status = false;

            float A_minX = ColRect_A.x - ColRect_A.width / 2;
            float A_maxX = ColRect_A.x + ColRect_A.width / 2;

            float A_minY = ColRect_A.y - ColRect_A.height / 2;
            float A_maxY = ColRect_A.y + ColRect_A.height / 2;

            float B_minX = ColRect_B.x - ColRect_B.width / 2;
            float B_maxX = ColRect_B.x + ColRect_B.width / 2;

            float B_minY = ColRect_B.y - ColRect_B.height / 2;
            float B_maxY = ColRect_B.y + ColRect_B.height / 2;

            if ((B_maxX < A_minX) || (B_minX > A_maxX) || (B_maxY < A_minY) || (B_minY > A_maxY))
            {
                status = false;
            }

            else
            {
                status = true;
            }

            return(status);
        }
示例#5
0
        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();
            }
        }
示例#6
0
        protected void BaseUpdateBoundingBox(Component pStart)
        {
            GameObject pNode = (GameObject)pStart;

            // point to ColTotal
            ColRect ColTotal = this.poColObj.poColRect;

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

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

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

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

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

                //  Debug.WriteLine("x:{0} y:{1} w:{2} h:{3}", ColTotal.x, ColTotal.y, ColTotal.width, ColTotal.height);
            }
        }
        static public bool Intersect(ColRect ColRectA, ColRect 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);
        }
示例#8
0
        // method for classes that inherit from Game Object
        // updates x, y, height, and width for the collision rectangle that encapsulates the child collission rectangles
        protected void BaseUpdateBoundingBox(Component pStart)
        {
            GameObject pNode = (GameObject)pStart;

            //get collision retangle so we can update in a loop of it's children
            ColRect ColTotal = this.poColObj.poColRect;

            //Get its first child so we can do a loop
            pNode = (GameObject)Iterator.GetChild(pNode);

            if (pNode != null)
            {
                //make "this" parent collision rectangle start off
                //as the size of its first child
                ColTotal.Set(pNode.poColObj.poColRect);

                //Now we loop through children
                //and make parent collision box bigger via a union method
                while (pNode != null)
                {
                    ColTotal.Union(pNode.poColObj.poColRect);

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


                this.x = this.poColObj.poColRect.x;
                this.y = this.poColObj.poColRect.y;
            }
        }
示例#9
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);
            }
        }
示例#10
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);
            }
        }
示例#11
0
 override public void Notify(float xCurs, float yCurs)
 {
     if (ColRect.Intersect(this.pFont.pFontSprite.pColRect, new ColRect(xCurs, yCurs, 1, 1)))
     {
         SceneContext.SetState(SceneContext.Scene.Select);
     }
 }
示例#12
0
        public ColObject(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 ColRect(pSprite.GetScreenRect());
            Debug.Assert(this.poColRect != null);

            // Create the box sprite

            //WORKING
            //this.pColSprite = BoxSpriteManager.Add(GameSprite.Name.Box, this.poColRect.x, this.poColRect.y, this.poColRect.width, this.poColRect.height);

            //TEST
            this.pColSprite = BoxSpriteManager.Add(pProxySprite.pSprite.GetName(), this.poColRect.x, this.poColRect.y, this.poColRect.width, this.poColRect.height);


            ////get the box name from the matching sprite name;
            //BoxSprite.Name colBoxName = (BoxSprite.Name) pProxySprite.pSprite.GetName();
            //Debug.Assert(colBoxName != null);
            //this.pColSprite = BoxSpriteManager.Find(colBoxName);
            //this.pColSprite.SetScreenRect(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);
        }
        override public void Notify(float xCurs, float yCurs)
        {
            var inter = ColRect.Intersect(this.pFont.pFontSprite.pColRect, new ColRect(xCurs, yCurs, 1, 1));

            if (!this.pState && inter)
            {
                Sound.Name sound = Sound.Name.Uninitialized;
                switch (this.pRandom.Next(0, 3))
                {
                case (0):
                    sound = Sound.Name.Invader1;
                    break;

                case (1):
                    sound = Sound.Name.Invader2;
                    break;

                case (2):
                    sound = Sound.Name.Invader3;
                    break;

                case (3):
                    sound = Sound.Name.Invader4;
                    break;
                }
                SoundMan.PlaySound(sound);
                this.pFont.SetColor(1.0f, 1.0f, 1.0f);
                this.pState = true;
            }
            else if (!inter)
            {
                this.pState = false;
                this.pFont.SetColor(0.60f, 0.60f, 0.60f);
            }
        }
 override public void Notify(float xCurs, float yCurs)
 {
     if (ColRect.Intersect(this.pFont.pFontSprite.pColRect, new ColRect(xCurs, yCurs, 1, 1)))
     {
         SceneContext.SetState(SceneContext.Scene.Aliens);
         SoundMan.PlaySound(Sound.Name.Shoot);
     }
 }
示例#15
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);
            }
        }
示例#16
0
        public void Union(ColRect ColRect)
        {
            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))
            {
                minY = (this.y - this.height / 2);
            }
            else
            {
                minY = (ColRect.y - ColRect.height / 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);
            }

            //dont switch these up
            this.width  = (maxX - minX);
            this.height = (maxY - minY);
            this.x      = minX + this.width / 2;
            this.y      = minY + this.height / 2;
        }
示例#17
0
        public void Union(ColRect 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;
        }
示例#18
0
        public ColObject(ProxySprite pProxySprite, BoxSprite.Name boxSpriteName)
        {
            Debug.Assert(pProxySprite != null);

            Sprite pSprite = pProxySprite.pSprite;

            Debug.Assert(pSprite != null);

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

            this.pColSprite = ProxyBoxSpriteManager.Add(boxSpriteName);
            Debug.Assert(this.pColSprite != null);

            this.enabled = true;
        }
示例#19
0
        public ColObject(ProxySprite pProxySprite)
        {
            Debug.Assert(pProxySprite != null);

            //use the Proxy's game Sprite for size and shape of collision rectangle
            GameSprite pSprite = pProxySprite.GetRealSprite();

            Debug.Assert(pSprite != null);

            //get the dimensions from the game sprite's rectangle
            // and store it in the collision rectangle
            this.poColRect = new ColRect(pSprite.GetScreenRect());
            Debug.Assert(this.poColRect != null);

            //create the collision sprite from the collision rectangle
            this.pColSprite = BoxSpriteMan.Add(BoxSprite.Name.BoxSprite1, this.poColRect.x, this.poColRect.y, this.poColRect.width, this.poColRect.height);
            Debug.Assert(this.pColSprite != null);
            this.pColSprite.SetLineColor(1.0f, 1.0f, 1.0f);
        }
示例#20
0
        protected void BaseUpdateBoundingBox(Component pStart)
        {
            GameObject pNode    = (GameObject)pStart;
            ColRect    ColTotal = this.poColObj.poColRect;

            pNode = (GameObject)Iterator.GetChild(pNode);

            if (pNode != null)
            {
                ColTotal.Set(pNode.poColObj.poColRect);
                while (pNode != null)
                {
                    ColTotal.Union(pNode.poColObj.poColRect);
                    pNode = (GameObject)Iterator.GetSibling(pNode);
                }

                this.x = this.poColObj.poColRect.x;
                this.y = this.poColObj.poColRect.y;
            }
        }
示例#21
0
        public ColObject(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 ColRect(pSprite.GetScreenRect());
            Debug.Assert(this.poColRect != null);

            // Create the sprite
            //Debug.WriteLine("{0} {1} {2} {3}",this.poColRect.x, this.poColRect.y, this.poColRect.width, this.poColRect.height);
            this.pColSprite = BoxSpriteMan.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, 0.0f, 0.0f);
        }
示例#22
0
        protected void baseUpdateBoundingBox()
        {
            //go to the first child in the PCS tree;
            PCSNode pcsNode = (PCSNode)this;

            pcsNode = pcsNode.pChild;

            //cast the pcsNode as a GameObject
            GameObject gameObject = (GameObject)pcsNode;

            //check to see if pcsNode is null (has it been removed?)
            if (pcsNode != null)
            {
                Debug.Assert(this.poColObj != null);
                Debug.Assert(this.poColObj.poColRect != null);
                ColRect collisionTotal = this.poColObj.poColRect;

                Debug.Assert(this.poColObj != null);
                Debug.Assert(this.poColObj.poColRect != null);
                collisionTotal.Set(gameObject.poColObj.poColRect);

                //loop through the siblings to get the total collisionRectSize;
                while (pcsNode != null)
                {
                    //cast each sibling pcsNode as a GameObject for consistency;
                    gameObject = (GameObject)pcsNode;
                    //total will be the size of the Union / combination of all the collisionRect sizes of the siblings;
                    collisionTotal.Union(gameObject.poColObj.poColRect);

                    //point to the next sibling;
                    //if the next sibling is null, then the loop will break out automatically;
                    pcsNode = pcsNode.pSibling;
                }

                this.x = this.poColObj.poColRect.x;
                this.y = this.poColObj.poColRect.y;
            }
        }
示例#23
0
        public override void Update()
        {
            //privMoveGrid

            // Go to first child
            PCSNode pNode = (PCSNode)this;

            pNode = pNode.pChild;

            // Set ColTotal to first child
            GameObject pGameObj = (GameObject)pNode;

            //todo add an AlienRoot to continue game after all aliens are destroyed
            //without a semi-permenant alien root, system breaks after last alien/column is destroyed,
            //thus destroying the grid and returning a null game object here;
            ColRect ColTotal = this.poColObj.poColRect;

            ColTotal.Set(pGameObj.GetColObject().poColRect);

            // loop through sliblings
            while (pNode != null)
            {
                pGameObj = (GameObject)pNode;
                ColTotal.Union(pGameObj.GetColObject().poColRect);

                // go to next sibling
                pNode = pNode.pSibling;
            }

            //this.pColObj.pColRect.Set(201, 201, 201, 201);
            this.x = this.poColObj.poColRect.x;
            this.y = this.poColObj.poColRect.y;

            //Debug.WriteLine("x:{0} y:{1} w:{2} h:{3}", ColTotal.x, ColTotal.y, ColTotal.width, ColTotal.height);

            base.baseUpdateBoundingBox();
            base.Update();
        }
示例#24
0
 public ColRect(ColRect pRect)
     : base(pRect)
 {
 }