示例#1
0
        public void MoveGrid()
        {
            // Initialize
            PCSTreeForwardIterator pIterator = new PCSTreeForwardIterator(this);

            Debug.Assert(pIterator != null);

            PCSNode pNode = pIterator.First();

            while (!pIterator.IsDone())
            {
                // delta
                GameObject pGameObj = (GameObject)pNode;
                pGameObj.x += this.delta;

                // Advance
                pNode = pIterator.Next();
            }

            this.total += this.delta;

            if (this.total > 400.0f || this.total < 0.0f)
            {
                this.delta *= -1.0f;
            }
        }
示例#2
0
        private void privRemoveNodeNoYoungerSiblings(PCSNode inNode, PCSNode pParent)
        {
            Debug.Assert(pParent != null);

            PCSNode pTmp;

            // goto eldest child
            pTmp = pParent.pChild;
            Debug.Assert(pTmp != null);

            if (pTmp.pSibling == null)
            {   // delete inNode so it's parent is 0
                // in child has no siblings
                pParent.pChild = null;
            }
            else
            {   // now iterate until child
                while (pTmp.pSibling != inNode)
                {
                    pTmp = pTmp.pSibling;
                }
                // this point we found the sibling
                PCSNode pPrev = pTmp;
                pPrev.pSibling = null;
            }
        }
        protected void updateUnionBox()
        {
            PCSNode node = (PCSNode)this;

            node = node.pChild;

            if (node == null)
            {
                this.cCollisionObj.cCollisionRectangle.Set(0, 0, 0, 0);
                this.x = 0;
                this.y = 0;
            }
            else
            {
                GameObject gameObj = (GameObject)node;

                CollisionRectangle collisionTotal = this.cCollisionObj.cCollisionRectangle;
                collisionTotal.Set(gameObj.cCollisionObj.cCollisionRectangle);

                while (node != null)
                {
                    gameObj = (GameObject)node;
                    collisionTotal.Union(gameObj.cCollisionObj.cCollisionRectangle);
                    node = node.pSibling;
                }
                this.x = this.cCollisionObj.cCollisionRectangle.x;
                this.y = this.cCollisionObj.cCollisionRectangle.y;
            }
        }
示例#4
0
        private void privRemoveNodeHasYoungerSiblings(PCSNode inNode)
        {
            // I have a sibling to the right of me
            // find the previous child
            PCSNode pParent;

            pParent = inNode.pParent;
            Debug.Assert(pParent != null);

            PCSNode pTmp;

            // goto eldest child
            pTmp = pParent.pChild;
            Debug.Assert(pTmp != null);

            if (pTmp == inNode)
            {   // we are deleting a eldest child with siblings
                pParent.pChild = pTmp.pSibling;
            }
            else
            {   // now iterate until child
                while (pTmp.pSibling != inNode)
                {
                    pTmp = pTmp.pSibling;
                }

                // this point we found the sibling
                PCSNode pPrev = pTmp;
                pPrev.pSibling = inNode.pSibling;
            }
        }
示例#5
0
 public WallFactory(PCSTree mPCSTree, SpriteBatch mSpriteBatch)
 {
     this.cPCSTree = mPCSTree;
     // this.cSpriteBatch = SpriteBatchManager.find(mSpriteBatch);
     this.cSpriteBatch = mSpriteBatch;
     cParent           = null;
 }
示例#6
0
 public PCSNode(PCSNode pParent, PCSNode pChild, PCSNode pSibling, PCSNode pForward, PCSNode pReverse)
 {
     this.pParent  = pParent;
     this.pChild   = pChild;
     this.pSibling = pSibling;
     this.pForward = pForward;
     this.pReverse = pReverse;
 }
示例#7
0
 public PCSNode(PCSNode pNode)
 {
     this.pParent  = pNode.pParent;
     this.pChild   = pNode.pChild;
     this.pSibling = pNode.pSibling;
     this.pReverse = pNode.pReverse;
     this.pForward = pNode.pForward;
 }
 public AlienFactory(PCSTree mPCSTree, SpriteBatch mSpriteBatch)
 {
     this.cPCSTree = mPCSTree;
     //this.cSpriteBatch = SpriteBatchManager.find(mSpriteBatch);
     this.cSpriteBatch = mSpriteBatch;
     cParent           = null;
     columnCount       = 0;
     alienCount        = 0;
 }
示例#9
0
        // Constructors: --------------------------------
        public PCSNode()
        {
            this.pParent  = null;
            this.pChild   = null;
            this.pSibling = null;

            this.pForward = null;
            this.pReverse = null;
        }
示例#10
0
        public AlienFactory(SpriteBatch.Name spriteBatchName, PCSTree pTree)
        {
            this.pSpriteBatch = SpriteBatchManager.Find(spriteBatchName);
            Debug.Assert(this.pSpriteBatch != null);

            Debug.Assert(pTree != null);
            this.pTree = pTree;

            //parent is null by default;
            this.pParent = null;
        }
示例#11
0
        // remove
        public void Remove(PCSNode inNode)
        {
            Debug.Assert(inNode != null);

            if (inNode.pChild == null)
            {
                // last node
                if (inNode.pSibling == null)
                {
                    // find the previous child
                    PCSNode pParent;
                    pParent = inNode.pParent;

                    // special case root
                    if (pParent == null)
                    {
                        this.pRoot = null;
                    }
                    else
                    {   // no children, no younger siblings
                        privRemoveNodeNoYoungerSiblings(inNode, pParent);
                    }
                }
                else
                {   // No children, but has other younger siblings
                    privRemoveNodeHasYoungerSiblings(inNode);
                }

                inNode.pChild   = null;
                inNode.pParent  = null;
                inNode.pSibling = null;
                this.privInfoRemoveNode();
                return;
            }
            else
            {
                // If we are here, recursively call
                PCSNode pTmp = inNode.pChild;
                Debug.Assert(pTmp != null);

                this.Remove(pTmp);
                this.Remove(inNode);
            }
        }
示例#12
0
        private void privMoveGrid()
        {
            PCSTreeForwardIterator iterator = new PCSTreeForwardIterator(this);

            Debug.Assert(iterator != null);

            PCSNode pNode = iterator.First();

            while (!iterator.IsDone())
            {
                Bomb bomb = (Bomb)pNode;
                if (bomb.active)
                {
                    bomb.y -= this.delta;
                }
                //gameObj.y -= this.delta;
                pNode = iterator.Next();
            }
        }
示例#13
0
文件: Grid.cs 项目: ccaunca/Projects
        private void MoveTree(GameObject pNode)
        {
            PCSNode pChild = null;

            pNode.pProxySprite.x += this.movementXDirection;
            pNode.pProxySprite.y += this.movementYDirection;
            if (pNode.pChild == null)
            {
                // base case
            }
            else
            {
                pChild = pNode.pChild;
                while (pChild != null)
                {
                    MoveTree((GameObject)pChild);
                    pChild = pChild.pSibling;
                }
            }
        }
示例#14
0
        public void moveGrid()
        {
            PCSTreeForwardIterator pcsIterator = new PCSTreeForwardIterator(this);

            Debug.Assert(pcsIterator != null);
            PCSNode    node = pcsIterator.First();
            GameObject gameObj;

            while (node != null)
            {
                gameObj    = (GameObject)node;
                gameObj.x += this.deltaX;
                if (this.edgeHit)
                {
                    gameObj.y -= this.deltaY;
                }
                node = pcsIterator.Next();
            }
            this.edgeHit = false;
        }
示例#15
0
        // insert
        public void Insert(PCSNode inNode, PCSNode pParent)
        {
            Debug.Assert(inNode != null);

            // insert to root
            if (null == pParent)
            {
                this.pRoot      = inNode;
                inNode.pChild   = null;
                inNode.pParent  = null;
                inNode.pSibling = null;

                this.privInfoAddNode();
            }
            else  // insert inside the tree
            {
                if (pParent.pChild == null)
                { // child is 0, just add child
                    pParent.pChild = inNode;

                    inNode.pParent  = pParent;
                    inNode.pChild   = null;
                    inNode.pSibling = null;

                    this.privInfoAddNode();
                }
                else
                { // add as sibling
                    // Get first child
                    PCSNode first = pParent.pChild;

                    inNode.pParent  = pParent;
                    inNode.pChild   = null;
                    inNode.pSibling = first;

                    pParent.pChild = inNode;

                    this.privInfoAddNode();
                }
            }
        }
示例#16
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;
        }
示例#17
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();
        }
示例#18
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;
            }
        }
示例#19
0
        private void privDumpTreeDepthFirst(PCSNode pNode)
        {
            PCSNode pChild = null;

            // dump
            pNode.dumpNode();

            // iterate through all of the active children
            if (pNode.pChild != null)
            {
                pChild = pNode.pChild;
                // make sure that allocation is not a child node
                while (pChild != null)
                {
                    privDumpTreeDepthFirst(pChild);
                    // goto next sibling
                    pChild = pChild.pSibling;
                }
            }
            else
            {
                // bye bye exit condition
            }
        }
示例#20
0
 public void SetParent(PCSNode pNode)
 {
     this.pParent = pNode;
 }
示例#21
0
 public void SetParent(GameObject parentNode)
 {
     //fine being null (null object)
     this.pParent = parentNode;
 }
示例#22
0
 public void setParent(PCSNode parentNode)
 {
     this.cParent = parentNode;
     Debug.Assert(this.cParent != null);
 }
示例#23
0
 public void SetRoot(PCSNode pRoot)
 {
     Debug.Assert(pRoot != null);
     this.pRoot = pRoot;
 }