public static void Remove(GameObject pNode)
        {
            Debug.Assert(pNode != null);
            GameObjectManager pMan = GameObjectManager.PrivGetInstance();

            Debug.Assert(pMan != null);

            // pNode may be part of a tree. If so, find it's root.
            // The root will be on the GameObjectManager's Linked list
            GameObject pRoot = null;
            GameObject pTmp  = pNode;

            while (pTmp != null)
            {
                pRoot = pTmp;
                pTmp  = (GameObject)pTmp.GetParent();
            }

            Debug.Assert(pRoot != null);

            // Now that we have the root of pNode's tree, or we have pNode if it has no parent
            // lets find that node on the GameObjectManager's Linked list
            GameObjectNode pTree = (GameObjectNode)pMan.BaseGetActive();

            while (pTree != null)
            {
                if (pTree.pGameObj == pRoot)
                {
                    // found it
                    break;
                }
                // Goto Next tree
                pTree = (GameObjectNode)pTree.GetNext();
            }

            // pTree should now be holding the node that matches Root
            Debug.Assert(pTree != null);

            // we shouldn't kills nodes with families right?
            // we aren't monsters
            Debug.Assert(pNode.GetFirstChild() == null);

            // check to see if pTree is just holding pNode or if
            // it is holding a tree containing pNode
            GameObject pNodeParent = (GameObject)pNode.GetParent();

            if (pTree.pGameObj == pNode)
            {
                // pNode is not part of a tree so just remove it.
                Debug.Assert(pNodeParent == null);
                Remove(pTree);
            }
            else
            {
                // pNode is a part of a tree so we'll use the node's
                // parent composite remove method to remove it.
                Debug.Assert(pNodeParent != null);
                pNodeParent.Remove(pNode);
            }
        }
        public GameObject GetRandomAlienBombPos()
        {
            int colNum     = 1;
            int randColNum = pRandom.Next(1, 11);

            ForwardIterator pFor = new ForwardIterator(this);

            Component  pNode    = pFor.First();
            GameObject pGameObj = (GameObject)pNode;

            while (!pFor.IsDone())
            {
                pGameObj = (GameObject)pNode;

                if (pGameObj.name == Name.AlienColumn)
                {
                    if (colNum == randColNum)
                    {
                        pGameObj = (AlienCategory)pGameObj.GetFirstChild();
                        break;
                    }

                    colNum++;
                }

                pNode = pFor.Next();
            }

            return(pGameObj);
        }
Example #3
0
        public static void Remove(GameObject gameObject)
        {
            GameObject Parent = (GameObject)Iterator.GetParent(gameObject);

            if (Parent != null)
            {
                Parent.Remove(gameObject);
                if (Parent.GetFirstChild() == null)
                {
                    Parent.RemoveBox();
                    Remove(Parent);
                }
                Parent.Update();
            }
        }
Example #4
0
        public void MoveUp()
        {
            //this is when the aliens hit the player the reset
            GameObject pAlienColumn = (GameObject)this.GetFirstChild();

            while (pAlienColumn != null)
            {
                GameObject pNextCol = (GameObject)pAlienColumn.pNext;

                GameObject pAlien = (GameObject)pAlienColumn.GetFirstChild();
                while (pAlien != null)
                {
                    GameObject pNextAlien = (GameObject)pAlien.pNext;
                    pAlien.y += 400;

                    pAlien = pNextAlien;
                }

                pAlienColumn = pNextCol;
            }
        }
Example #5
0
        public virtual void Remove()
        {
            // Grab a reference to the object's parent
            // We may need to remove it as well if it has no children after this is removed
            GameObject pParent = (GameObject)this.GetParent();

            // Remove from SpriteBatch
            // Find the SBNode
            Debug.Assert(this.pProxySprite != null);
            SpriteBaseNode pSBNode = this.pProxySprite.GetSBNode();

            // Remove it from the manager
            Debug.Assert(pSBNode != null);
            SpriteBatchManager.Remove(pSBNode);

            // Remove collision sprite from spriteBatch

            Debug.Assert(this.poColObj != null);
            Debug.Assert(this.poColObj.pColSprite != null);
            pSBNode = this.poColObj.pColSprite.GetSBNode();

            Debug.Assert(pSBNode != null);
            SpriteBatchManager.Remove(pSBNode);

            // Remove from GameObjectMan
            GameObjectManager.Remove(this);

            // check to see if the parent has any more children
            if (pParent != null && pParent.GetFirstChild() == null)
            {
                // We just removed the last of the parent's children
                // so it is time to remove the parent as well
                pParent.Remove();
            }

            // TODO Add to ghost manager
        }
        // TODO Clean this up
        public override void Notify()
        {
            //Debug.WriteLine("RemoveShieldBrickObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB);

            // This cast will throw an exception if wrong
            this.pShieldBrick     = (ShieldBrick)this.pSubject.pObjA;
            this.pColComposite    = null;
            this.pShieldComposite = null;

            // Remove Shield from composite
            Composite       pShieldGrid = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.ShieldGroup);
            ForwardIterator pFwdIter    = new ForwardIterator(pShieldGrid);

            Component pNode = pFwdIter.First();

            while (!pFwdIter.IsDone())
            {
                if (pNode.containerType == Component.Container.LEAF)
                {
                    // If Component is target shield brick
                    if (pNode.GetHashCode() == this.pShieldBrick.GetHashCode())
                    {
                        // Remove shield brick from column
                        pNode.pParent.Remove(pNode);

                        // Get references to parent composites
                        Component pShieldColComposite = pNode.pParent;
                        Component pShieldComposite    = null;

                        if (pShieldColComposite != null)
                        {
                            pShieldComposite = pShieldColComposite.pParent;
                        }

                        // If column is now empty, delete column
                        if (pShieldColComposite.GetFirstChild() == null)
                        {
                            // Delete empty column from parent composite
                            if (pShieldColComposite.pParent != null)
                            {
                                pShieldColComposite.pParent.Remove(pShieldColComposite);
                            }

                            // Mark empty column for death
                            if (!((GameObject)pShieldColComposite).IsMarkedForDeath())
                            {
                                this.pColComposite = (GameObject)pShieldColComposite;
                                this.pColComposite.MarkForDeath();
                            }
                        }

                        // If Shield is now empty, delete column
                        if (pShieldComposite.GetFirstChild() == null)
                        {
                            // Delete empty shield from parent composite
                            if (pShieldComposite.pParent != null)
                            {
                                pShieldComposite.pParent.Remove(pShieldComposite);
                            }

                            // Mark empty shield for death
                            if (!((GameObject)pShieldComposite).IsMarkedForDeath())
                            {
                                this.pShieldComposite = (GameObject)pShieldComposite;
                                this.pShieldComposite.MarkForDeath();
                            }
                        }

                        break;
                    }
                }

                pNode = pFwdIter.Next();
            }

            if (!pShieldBrick.IsMarkedForDeath())
            {
                pShieldBrick.MarkForDeath();

                // Delay - remove object later
                RemoveShieldBrickObserver pObserver = new RemoveShieldBrickObserver(this);
                GameStateManager.GetGame().GetStateDelayedObjectManager().Attach(pObserver);
            }
        }
Example #7
0
        public override void Update()
        {
            //first time through set a time to change states
            if (this.bStateToggle == true)
            {
                //inititally used the game to get time
                //Testing timer man
                //could use Timer Man for current time
                float curTime = TimerMan.GetCurrentTime();
                this.ChangeStateTime = curTime + 10;
                this.bStateToggle    = false;
            }


            else
            {
                SpaceInvaders pGame = GameMan.GetGame();

                //time has elapsed start over
                if (this.ChangeStateTime <= pGame.GetTime())
                {
                    this.bStateToggle = true;

                    SpriteBatch pSB_Intro = SpriteBatchMan.Find(SpriteBatch.Name.IntroScreen);
                    pSB_Intro.bToggle = true;

                    SpriteBatch pGameOverScreen = SpriteBatchMan.Find(SpriteBatch.Name.GameOver);
                    pGameOverScreen.bToggle = false;

                    //SpriteBatch pSB_Splats = SpriteBatchMan.Find(SpriteBatch.Name.Splats);
                    //pSB_Splats.bToggle = false;

                    //----------------------------------------------------------------------------------------------------
                    //Things we need to reset for the Next game?
                    //----------------------------------------------------------------------------------------------------

                    // need to remove ship from its root
                    GameObject pShipRoot = GONodeMan.Find(GameObject.Name.ShipRoot);
                    GameObject pShip     = (GameObject)pShipRoot.GetFirstChild();

                    if (pShip != null)
                    {
                        pShip.Remove();
                    }

                    ShipMan.Destroy();

                    GraveyardMan.KillAll();
                    //GraveyardMan.DumpNodes();
                    GraveyardMan.Destroy();


                    TimerMan.ClearActiveList();
                    TimerMan.DumpTimeEvents();

                    AlienGroup pAlienGroup = (AlienGroup)GONodeMan.Find(GameObject.Name.AlienGrid);
                    pAlienGroup.SetDeltaMove(15.0f);

                    SpriteBatch pSB_Projectiles = SpriteBatchMan.Find(SpriteBatch.Name.Projectiles);
                    pSB_Projectiles.bToggle = false;

                    //----------------------------------------------------------------------------------------------------

                    pGame.SetGameState(GameMan.State.Intro);
                    pGame.GetCurrentState().Update();
                }
            }
        }
Example #8
0
        //rebuilds the Alien Group Tree
        public static void RaiseDead()
        {
            SpriteBatch pSB_Aliens = SpriteBatchMan.Find(SpriteBatch.Name.Aliens);
            SpriteBatch pSB_Boxes  = SpriteBatchMan.Find(SpriteBatch.Name.Boxes);
            GameObject  pRoot      = GONodeMan.Find(GameObject.Name.AlienGrid);

            GraveyardMan pGraveyard = GraveyardMan.PrivGetInstance();

            GameObject pSafety = pGraveyard.poHead;

            GameObject pNode = pSafety;

            GameObject pNextNode = null;

            //search for the columns
            while (pNode != null)
            {
                //save this to iterate, because we will possibly remove the next pointer
                pNextNode = (GameObject)pNode.pNext;

                //we still have the parent reference on the objects
                if (pRoot == pNode.pParent)
                {
                    //dettach from list then add it to tree
                    pGraveyard.PrivDetach(pNode, ref pGraveyard.poHead);

                    pNode.Clear();

                    pRoot.Add(pNode);
                    pNode.ActivateGameSprite(pSB_Aliens);
                    pNode.ActivateCollisionSprite(pSB_Boxes);
                }

                pNode = pNextNode;
            }

            //random check
            //check to see if AlienGroup has a column
            Debug.Assert(pRoot.GetFirstChild() != null);

            GameObject pColumn = (GameObject)pRoot.GetFirstChild();

            //iterate through the column siblings
            while (pColumn != null)
            {
                //iterate through the graveyard
                pNode = pGraveyard.poHead;
                while (pNode != null)
                {
                    //save this to iterate, because we will possibly remove the next pointer it
                    pNextNode = (GameObject)pNode.pNext;

                    //check the parent reference to the column
                    if (pColumn == pNode.pParent)
                    {
                        //dettach from list then add it to tree
                        pGraveyard.PrivDetach(pNode, ref pGraveyard.poHead);

                        AlienCategory pAlien = (AlienCategory)pNode;
                        pAlien.x             = pAlien.OrigX();
                        pAlien.y             = pAlien.OrigY() - 100.0f;
                        pAlien.bMarkForDeath = false;

                        pNode.Clear();

                        pColumn.Add(pNode);
                        pNode.ActivateGameSprite(pSB_Aliens);
                        pNode.ActivateCollisionSprite(pSB_Boxes);
                    }

                    pNode = pNextNode;
                }


                pColumn = (GameObject)pColumn.pNext;
            }
        }
Example #9
0
        public static void KillAll()
        {
            GraveyardMan pGraveyard = GraveyardMan.PrivGetInstance();

            Debug.Assert(pGraveyard != null);

            // trying to gather leftover Aliens
            GameObject pAlienGroup = GONodeMan.Find(GameObject.Name.AlienGrid);

            //Start with the columns
            GameObject pColumn = (GameObject)pAlienGroup.GetFirstChild();

            while (pColumn != null)
            {
                //store the next column
                GameObject pNextColumn = (GameObject)pColumn.pNext;

                //remove aliens from the column
                GameObject pAlien = (GameObject)pColumn.GetFirstChild();
                while (pAlien != null)
                {
                    GameObject pNextAlien = (GameObject)pAlien.pNext;

                    pAlien.Remove();

                    pAlien = pNextAlien;
                }

                //once your out do a check to see if its null
                Debug.Assert(pColumn.GetFirstChild() == null);

                //remove the column
                pColumn.Remove();

                pColumn = pNextColumn;
            }

            // trying to gather leftover Shieldbricks
            GameObject pShieldRoot = GONodeMan.Find(GameObject.Name.ShieldRoot);

            //start with shields (4 of them if all there)
            GameObject pShield = (GameObject)pShieldRoot.GetFirstChild();

            while (pShield != null)
            {
                //store the next shield
                GameObject pNextShield = (GameObject)pShield.pNext;

                //go to the shield columns
                GameObject pShieldColumn = (GameObject)pShield.GetFirstChild();
                while (pShieldColumn != null)
                {
                    GameObject pNextColumn = (GameObject)pShieldColumn.pNext;

                    //finally at the bricks
                    GameObject pBrick = (GameObject)pShieldColumn.GetFirstChild();
                    while (pBrick != null)
                    {
                        GameObject pNextBrick = (GameObject)pBrick.pNext;

                        pBrick.Remove();

                        pBrick = pNextBrick;
                    }

                    //once your out do a check to see if its null
                    Debug.Assert(pShieldColumn.GetFirstChild() == null);

                    //remove the column from shield
                    pShieldColumn.Remove();

                    pShieldColumn = pNextColumn;
                }

                //once your out do a check to see if its null
                Debug.Assert(pShield.GetFirstChild() == null);

                //remove the shield from root
                pShield.Remove();

                pShield = pNextShield;
            }
        }
Example #10
0
        //make it rebuild the Shields now
        public static void RebuildShields()
        {
            SpriteBatch pSB_Shields = SpriteBatchMan.Find(SpriteBatch.Name.Shields);
            SpriteBatch pSB_Boxes   = SpriteBatchMan.Find(SpriteBatch.Name.Boxes);
            GameObject  pShieldRoot = GONodeMan.Find(GameObject.Name.ShieldRoot);

            GraveyardMan pGraveyard = GraveyardMan.PrivGetInstance();

            GameObject pSafety = pGraveyard.poHead;

            GameObject pNode = pSafety;

            GameObject pNextNode = null;

            //-------------------------------------------------------------------------------------------------
            //add the Shields to the Shield Root
            //-------------------------------------------------------------------------------------------------

            //search for the shields
            while (pNode != null)
            {
                //save this to iterate, because we will possibly remove the next pointer it
                pNextNode = (GameObject)pNode.pNext;

                //we still have the parent reference on the objects
                if (pShieldRoot == pNode.pParent)
                {
                    //dettach from list then add it to tree
                    pGraveyard.PrivDetach(pNode, ref pGraveyard.poHead);

                    pNode.Clear();

                    pShieldRoot.Add(pNode);
                    pNode.ActivateGameSprite(pSB_Shields);
                    pNode.ActivateCollisionSprite(pSB_Boxes);
                }

                pNode = pNextNode;
            }

            //-------------------------------------------------------------------------------------------------
            //add the Columns to the Shields
            //-------------------------------------------------------------------------------------------------

            //random check
            //check to see if ShieldRoot has a shield
            Debug.Assert(pShieldRoot.GetFirstChild() != null);

            GameObject pShield = (GameObject)pShieldRoot.GetFirstChild();

            //iterate through the shield siblings
            while (pShield != null)
            {
                //iterate through the graveyard
                pNode = pGraveyard.poHead;
                while (pNode != null)
                {
                    //save this to iterate, because we will possibly remove the next pointer it
                    pNextNode = (GameObject)pNode.pNext;

                    //check the parent reference to the shield
                    if (pShield == pNode.pParent)
                    {
                        //dettach from list then add it to tree
                        pGraveyard.PrivDetach(pNode, ref pGraveyard.poHead);

                        pNode.Clear();

                        pShield.Add(pNode);
                        pNode.ActivateGameSprite(pSB_Shields);
                        pNode.ActivateCollisionSprite(pSB_Boxes);
                    }

                    pNode = pNextNode;
                }


                pShield = (GameObject)pShield.pNext;
            }

            //-------------------------------------------------------------------------------------------------
            //lastly add the bricks to the Shield columns in each shield
            //-------------------------------------------------------------------------------------------------

            pShield = (GameObject)pShieldRoot.GetFirstChild();
            Debug.Assert(pShield != null);

            while (pShield != null)
            {
                GameObject pShieldColumn = (GameObject)pShield.GetFirstChild();
                Debug.Assert(pShieldColumn != null);

                //iterate through the shield columns
                while (pShieldColumn != null)
                {
                    //iterate through the graveyard
                    pNode = pGraveyard.poHead;
                    while (pNode != null)
                    {
                        //save this to iterate, because we will possibly remove the next pointer it
                        pNextNode = (GameObject)pNode.pNext;

                        //check the parent reference to the column
                        if (pShieldColumn == pNode.pParent)
                        {
                            //dettach from list then add it to tree
                            pGraveyard.PrivDetach(pNode, ref pGraveyard.poHead);

                            ShieldBrick pAlien = (ShieldBrick)pNode;
                            pAlien.x             = pAlien.OrigX();
                            pAlien.y             = pAlien.OrigY();
                            pAlien.bMarkForDeath = false;

                            pNode.Clear();

                            pShieldColumn.Add(pNode);
                            pNode.ActivateGameSprite(pSB_Shields);
                            pNode.ActivateCollisionSprite(pSB_Boxes);
                        }

                        pNode = pNextNode;
                    }


                    pShieldColumn = (GameObject)pShieldColumn.pNext;
                }

                pShield = (GameObject)pShield.pNext;
            }
        }