Пример #1
0
        override public void Execute(float deltaTime)
        {
            int pFreq = pRandom.Next(1, 10) / this.nCurrLevel;

            AlienGrid     pGrid  = (AlienGrid)GameObjectMan.Find(GameObject.Name.AlienGrid);
            AlienCategory pAlien = pGrid.GetRandomAlien();

            // HACK don't crash pleease
            if (pAlien == null)
            {
                TimerMan.Add(TimeEvent.Name.BombSpawn, this, pFreq);
                return;
            }

            int          type          = pRandom.Next(0, 2);
            FallStrategy pFallStrategy = null;

            switch (type)
            {
            case (0):
                pFallStrategy = new FallZigZag();
                break;

            case (1):
                pFallStrategy = new FallDagger();
                break;

            case (2):
                pFallStrategy = new FallStraight();
                break;
            }
            type = pRandom.Next(0, 2);
            GameSprite.Name pGameSpriteName = GameSprite.Name.Uninitialized;
            switch (type)
            {
            case (0):
                pGameSpriteName = GameSprite.Name.BombZigZag;
                break;

            case (1):
                pGameSpriteName = GameSprite.Name.BombDagger;
                break;

            case (2):
                pGameSpriteName = GameSprite.Name.BombStraight;
                break;
            }

            Bomb pBomb = new Bomb(GameObject.Name.Bomb, pGameSpriteName, pFallStrategy, pAlien.x, pAlien.y);

            pBomb.ActivateCollisionSprite(this.pSB_Boxes);
            pBomb.ActivateGameSprite(this.pSB_Bombs);

            GameObject pBombRoot = GameObjectMan.Find(GameObject.Name.BombRoot);

            Debug.Assert(pBombRoot != null);

            pBombRoot.Add(pBomb);
            TimerMan.Add(TimeEvent.Name.BombSpawn, this, pFreq);
        }
Пример #2
0
        private void SpawnBomb()
        {
            int    random  = this.pGrid.pRandom.Next(0, pGrid.colCount);
            Column pColumn = pGrid.GetColumn(random);

            //Debug.WriteLine("Firing from Column{0}", random);
            if (pColumn != null)
            {
                PCSTree        pTree  = GameObjectManager.GetRootTree();
                SpriteBaseName sName  = SpriteBaseName.Null;
                FallStrategy   pStrat = null;
                switch (pGrid.pRandom.Next(0, 3))
                {
                case 0:
                    sName  = SpriteBaseName.BombStraight;
                    pStrat = new FallStraight();
                    break;

                case 1:
                    sName  = SpriteBaseName.BombDagger;
                    pStrat = new FallDagger();
                    break;

                case 2:
                default:
                    sName  = SpriteBaseName.BombZigZag;
                    pStrat = new FallZigZag();
                    break;
                }
                Bomb pBomb = new Bomb(GameObjectName.Bomb, sName, pStrat, pColumn.x, pColumn.pCollisionObject.pCollisionRect.minY, 0);
                pBomb.ActivateCollisionSprite(this.sbBoxes);
                pBomb.ActivateGameSprite(this.sbAliens);
                pTree.Insert(pBomb, this.pBombRoot);
            }
        }
Пример #3
0
        private FallStrategy chooseFallStrategy(GameSprite.Name spriteName)
        {
            FallStrategy pFallStrategy = null;

            switch (spriteName)
            {
            case GameSprite.Name.BombDagger:
                pFallStrategy = new FallDagger();
                break;

            case GameSprite.Name.BombStraight:
                pFallStrategy = new FallStraight();
                break;

            case GameSprite.Name.BombZigZag:
                pFallStrategy = new FallZigZag();
                break;

            default:
                Debug.Assert(false);
                break;
            }

            return(pFallStrategy);
        }
Пример #4
0
        public override void Execute(float deltaTime)
        {
            Composite pFlyingSaucerRoot = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.FlyingSaucerRoot);

            // If Flying Saucer is on screen
            if (pFlyingSaucerRoot.GetFirstChild() != null)
            {
                Composite pBombRoot = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.BombRoot);

                // Identify random Column + starting location
                int          randomColIndex = r.Next(0, pFlyingSaucerRoot.GetNumOfChildren());
                FlyingSaucer pFlyingSaucer  = (FlyingSaucer)pFlyingSaucerRoot.GetFirstChild();
                Azul.Rect    pFlyingSaucerColCollisionRect = pFlyingSaucer.GetCollisionObject().GetCollisionRect();

                float xPos = (pFlyingSaucerColCollisionRect.x + (pFlyingSaucerColCollisionRect.width / 2.0f));
                float yPos = (pFlyingSaucerColCollisionRect.y - (pFlyingSaucerColCollisionRect.height / 2.0f));

                // Identify random Bomb Type and create bomb
                FallStrategy bombStrategy = null;
                int          bombType     = r.Next(0, 3);

                if (bombType == 0)
                {
                    bombType     = (int)Sprite.Name.BombStraight;
                    bombStrategy = new FallStraight();
                }
                else if (bombType == 1)
                {
                    bombType     = (int)Sprite.Name.BombZigZag;
                    bombStrategy = new FallZigZag();
                }
                else
                {
                    bombType     = (int)Sprite.Name.BombCross;
                    bombStrategy = new FallDagger();
                }

                // TODO refactor to use Object Pool
                FlyingSaucerBomb pBomb = new FlyingSaucerBomb(GameObject.Name.FlyingSaucerBomb, (Sprite.Name)bombType, bombStrategy, xPos, yPos);

                // Attach to BombRoot, SpriteBatches, and any related managers
                GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.BombRoot).Add(pBomb);
                GameStateManager.GetGame().GetStateGameObjectManager().Attach(pBomb);
                pBomb.ActivateCollisionSprite(GameStateManager.GetGame().GetStateSpriteBatchManager().Find(SpriteBatch.Name.CollisionBox));
                pBomb.ActivateSprite(GameStateManager.GetGame().GetStateSpriteBatchManager().Find(SpriteBatch.Name.Bomb));
            }
        }