// TODO maybe this becomes a init crit method and make activategrid just display the grid rather than create a new one
        public static InvaderGrid GenerateGrid(int level)
        {
            // Get factory for producing gameobjects and adding them to the gameobject manager and spritebatches
            InvaderFactory rootLevelIF = new InvaderFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes);
            // create the grid composite data structure
            InvaderGrid pGrid = (InvaderGrid)rootLevelIF.ActiveCreate(GameObject.Type.InvaderGrid, 0, 0);

            // Get another factory for producing gameobjects and adding them to the Grid as well as the gameobject manager and sprite batches
            InvaderFactory columnIF = new InvaderFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, pGrid);

            for (int i = 0; i < 11; i++)
            {
                InvaderColumn pColumn = (InvaderColumn)columnIF.ActiveCreate(GameObject.Type.InvaderColumn, 0, 0);

                InvaderFactory gridAliensIF = new InvaderFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, pColumn);
                float          xPos         = Constants.gridXOrigin + i * Constants.gridColumnDelta;
                gridAliensIF.ActiveCreate(GameObject.Type.SmallInvader, xPos, Constants.smallInvaderYPos - level * 10);
                gridAliensIF.ActiveCreate(GameObject.Type.MediumInvader, xPos, Constants.MediumInvaderYPos1 - level * 10);
                gridAliensIF.ActiveCreate(GameObject.Type.MediumInvader, xPos, Constants.MediumInvaderYPos2 - level * 10);
                gridAliensIF.ActiveCreate(GameObject.Type.LargeInvader, xPos, Constants.LargeInvaderYPos1 - level * 10);
                gridAliensIF.ActiveCreate(GameObject.Type.LargeInvader, xPos, Constants.LargeInvaderYPos2 - level * 10);
            }
            pGrid.SetState(InvaderGridManager.State.NotCollingWithWall);

            return(pGrid);
        }
        public static InvaderCategory GetRandomBombDropper(InvaderGrid pGrid)
        {
            InvaderGridManager pMan = InvaderGridManager.PrivGetInstance();

            Debug.Assert(pMan != null);

            InvaderCategory pTmpInvader = null;

            // Find a random bottom row invader to drop the bomb
            int           numColumns        = pGrid.GetNumChildren();
            int           randomColumnIndex = pMan.pRandom.Next(numColumns);
            InvaderColumn pColumn           = (InvaderColumn)pGrid.GetChild(randomColumnIndex);

            pTmpInvader = (InvaderCategory)pColumn.GetChild(0);

            // Check to see if the invader drop the bomb, if not go find another invader

            InvaderCategory pInvader = null;

            for (int i = 0; i < numColumns; i++)
            {
                randomColumnIndex = pMan.pRandom.Next(numColumns);
                pColumn           = (InvaderColumn)pGrid.GetChild(randomColumnIndex);
                pTmpInvader       = (InvaderCategory)pColumn.GetChild(0);
                if (pTmpInvader.canLaunchBomb)
                {
                    pInvader = pTmpInvader;
                    break;
                }
            }

            return(pInvader);
        }
        public override void VisitInvaderColumn(InvaderColumn pColumn)
        {
            //Debug.WriteLine("in ShieldZone, visit from InvaderColumn");
            GameObject pGameObj = (GameObject)pColumn.GetFirstChild();

            ColPair.FwdCollide(this, pGameObj);
        }
Exemple #4
0
        // Creates invader And adds it to Batches or gameobject manager
        public GameObject ActiveCreate(GameObject.Type type, float posX, float posY)
        {
            GameObject pGameObj = null;

            switch (type)
            {
            case GameObject.Type.SmallInvader:
                pGameObj = new SmallInvader(GameObject.Name.SmallInvader, Sprite.Name.SmallInvader, BoxSprite.Name.SmallInvaderBox, posX, posY);
                break;

            case GameObject.Type.MediumInvader:
                pGameObj = new MediumInvader(GameObject.Name.MediumInvader, Sprite.Name.MediumInvader, BoxSprite.Name.MediumInvaderBox, posX, posY);
                break;

            case GameObject.Type.LargeInvader:
                pGameObj = new LargeInvader(GameObject.Name.LargeInvader, Sprite.Name.LargeInvader, BoxSprite.Name.LargeInvaderBox, posX, posY);
                break;

            case GameObject.Type.UFO:
                pGameObj = new UFO(GameObject.Name.UFO, Sprite.Name.UFO, BoxSprite.Name.UFOBox, posX, posY);
                break;

            case GameObject.Type.InvaderColumn:
                pGameObj = new InvaderColumn(GameObject.Name.InvaderColumn, BoxSprite.Name.InvaderColumnBox);
                break;

            case GameObject.Type.InvaderGrid:
                pGameObj = new InvaderGrid(GameObject.Name.InvaderGrid, BoxSprite.Name.InvaderGridBox);
                break;

            default:
                // something is wrong
                Debug.Assert(false, "GameObject type not supported by this factory");
                break;
            }

            // add it to the gameObjectManager
            Debug.Assert(pGameObj != null);
            GameObjectManager.Attach(pGameObj);

            if (pGOComposite != null)
            {
                // add to grouping
                pGOComposite.Add(pGameObj);
            }

            // Attached to Batches
            this.pBoxSpriteBatch.Attach(pGameObj.poColObj.pColSprite);
            this.pSpriteBatch.Attach(pGameObj.pProxySprite);
            return(pGameObj);
        }
Exemple #5
0
        // Creates invader but does not add it to Batches or gameobject manager
        public GameObject PassiveCreate(GameObject.Type type, float posX, float posY)
        {
            GameObject pGameObj = null;

            switch (type)
            {
            case GameObject.Type.SmallInvader:
                pGameObj = new SmallInvader(GameObject.Name.SmallInvader, Sprite.Name.SmallInvader, BoxSprite.Name.SmallInvaderBox, posX, posY);
                break;

            case GameObject.Type.MediumInvader:
                pGameObj = new MediumInvader(GameObject.Name.MediumInvader, Sprite.Name.MediumInvader, BoxSprite.Name.MediumInvaderBox, posX, posY);
                break;

            case GameObject.Type.LargeInvader:
                pGameObj = new LargeInvader(GameObject.Name.LargeInvader, Sprite.Name.LargeInvader, BoxSprite.Name.LargeInvaderBox, posX, posY);
                break;

            case GameObject.Type.UFO:
                pGameObj = new UFO(GameObject.Name.UFO, Sprite.Name.UFO, BoxSprite.Name.UFOBox, posX, posY);
                break;

            case GameObject.Type.InvaderColumn:
                pGameObj = new InvaderColumn(GameObject.Name.InvaderColumn, BoxSprite.Name.InvaderColumnBox);
                break;

            case GameObject.Type.InvaderGrid:
                pGameObj = new InvaderGrid(GameObject.Name.InvaderGrid, BoxSprite.Name.InvaderGridBox);
                break;

            default:
                // something is wrong
                Debug.Assert(false, "GameObject type not supported by this factory");
                break;
            }

            if (pGOComposite != null)
            {
                // add to grouping
                pGOComposite.Add(pGameObj);
            }

            return(pGameObj);
        }
Exemple #6
0
        public override void VisitInvaderColumn(InvaderColumn pColumn)
        {
            GameObject pGameObj = (GameObject)pColumn.GetFirstChild();

            ColPair.FwdCollide(this, pGameObj);
        }
Exemple #7
0
 public virtual void VisitInvaderColumn(InvaderColumn pColumn)
 {
     // no differed to subcass
     Debug.WriteLine("Visit by InvaderColumn not implemented");
     Debug.Assert(false);
 }