示例#1
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);
            }
        }
        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);
        }
示例#3
0
        //called from column ( (GameObject)this.pParent );
        public override void DropBomb()
        {
            float bomb_startPosX = this.x;
            float bomb_startPosY = this.y;

            //Bomb pBomb = new Bomb(GameObject.Name.Bomb, GameSprite.Name.CrossAlienBomb, new FallStraight(), 0, bomb_startPosX, bomb_startPosY);
            //Debug.Assert(pBomb != null);
            Random r = new Random();
            int    randomBombType = r.Next(1, 4);

            Bomb pBomb = privCreateBomb(randomBombType, bomb_startPosX, bomb_startPosY);

            //get the root tree
            PCSTree rootGamObjTree = GameObjectManager.GetRootTree();

            Debug.Assert(rootGamObjTree != null);

            //find the bomb root
            GameObject pBombRoot = GameObjectManager.Find(GameObject.Name.BombRoot);

            Debug.Assert(pBombRoot != null);

            rootGamObjTree.Insert(pBomb, pBombRoot);

            //activate the sprites
            SpriteBatch pSB_GameSprites = SpriteBatchManager.Find(SpriteBatch.Name.GameSprites);
            SpriteBatch pSB_Boxes       = SpriteBatchManager.Find(SpriteBatch.Name.SpriteBoxes);

            pBomb.ActivateGameSprite(pSB_GameSprites);
            pBomb.ActivateCollisionSprite(pSB_Boxes);
        }
示例#4
0
        public static Bomb ActivateBomb(UFOCategory pUFO)
        {
            UFOMan pUFOMan = UFOMan.PrivInstance();

            Debug.Assert(pUFOMan != null);

            Bomb pBombObj = new Bomb(GameObject.Name.Bomb, GameSprite.Name.BombFork, new FallTuning(), pUFO.x, pUFO.y, pUFO);

            pUFOMan.pBomb = pBombObj;

            SpriteBatch pSB_Aliens = SpriteBatchMan.Find(SpriteBatch.Name.Aliens);
            SpriteBatch pSB_Box    = SpriteBatchMan.Find(SpriteBatch.Name.Boxes);

            pBombObj.ActivateCollisionSprite(pSB_Box);
            pBombObj.ActivateGameSprite(pSB_Aliens);

            // Attach the missile to the missile root
            GameObject pBombRoot = GameObjectMan.Find(GameObject.Name.BombRoot);

            Debug.Assert(pBombRoot != null);

            // Add to GameObject Tree - {update and collisions}
            pBombRoot.Add(pUFOMan.pBomb);

            return(pUFOMan.pBomb);
        }
示例#5
0
        public static void DropBomb()
        {
            UFOManager ufoMan  = UFOManager.GetInstance();
            UFO        ufo     = ufoMan.pUFO;
            PCSTree    pcsTree = GameObjectManager.GetRootTree();

            Debug.Assert(pcsTree != null);

            Bomb pBomb = new Bomb(GameObjectName.UFOBomb, SpriteBaseName.UFOBomb, new FallStraight(), ufo.x, ufo.y, 0);

            pBomb.pProxySprite.pSprite.SetColor(ColorFactory.Create(ColorName.Red).pAzulColor);
            ufoMan.pBomb = pBomb;

            SpriteBatch sbAliens = SpriteBatchManager.Find(SpriteBatchName.Aliens);
            SpriteBatch sbBoxes  = SpriteBatchManager.Find(SpriteBatchName.Boxes);

            pBomb.ActivateCollisionSprite(sbBoxes);
            pBomb.ActivateGameSprite(sbAliens);

            GameObject pBombRoot = GameObjectManager.Find(GameObjectName.BombRoot);

            Debug.Assert(pBombRoot != null);

            pcsTree.Insert(ufoMan.pBomb, pBombRoot);
            SetUFOBombActive(true);
            Debug.WriteLine("UFO Bomb dropped!");
        }
示例#6
0
        public static Bomb ActivateBomb(AlienCategory pAlien)
        {
            AlienMan pAlienMan = AlienMan.PrivInstance();

            Debug.Assert(pAlienMan != null);

            // copy over safe copy
            byte[] buffer = Guid.NewGuid().ToByteArray();
            int    iSeed  = BitConverter.ToInt32(buffer, 0);
            Random random = new Random(iSeed);

            Bomb pBombObj = null;
            int  randint  = random.Next(0, 4);

            switch (randint)
            {
            case 0:
                pBombObj = new Bomb(GameObject.Name.Bomb, GameSprite.Name.BombDagger, new FallDagger(), pAlien.x, pAlien.y, pAlien);
                break;

            case 1:
                pBombObj = new Bomb(GameObject.Name.Bomb, GameSprite.Name.BombRolling, new FallRolling(), pAlien.x, pAlien.y, pAlien);
                break;

            case 2:
                pBombObj = new Bomb(GameObject.Name.Bomb, GameSprite.Name.BombZigZag, new FallZigZag(), pAlien.x, pAlien.y, pAlien);
                break;

            case 3:
                pBombObj = new Bomb(GameObject.Name.Bomb, GameSprite.Name.BombStraight, new FallStraight(), pAlien.x, pAlien.y, pAlien);
                break;

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

            pAlienMan.pBomb = pBombObj;

            SpriteBatch pSB_Aliens = SpriteBatchMan.Find(SpriteBatch.Name.Aliens);
            SpriteBatch pSB_Box    = SpriteBatchMan.Find(SpriteBatch.Name.Boxes);

            pBombObj.ActivateCollisionSprite(pSB_Box);
            pBombObj.ActivateGameSprite(pSB_Aliens);

            // Attach the missile to the missile root
            GameObject pBombRoot = GameObjectMan.Find(GameObject.Name.BombRoot);

            Debug.Assert(pBombRoot != null);

            // Add to GameObject Tree - {update and collisions}
            pBombRoot.Add(pAlienMan.pBomb);

            return(pAlienMan.pBomb);
        }
示例#7
0
        public override void execute(float currentTime)
        {
            PCSTree pTree = GameObjectManager.GetRootTree();

            float value = pRandom.Next(100, 760);
            Bomb  pBomb = new Bomb(GameObjectName.Bomb, SpriteBaseName.BombStraight, new FallStraight(), value, 850.0f, 0);

            pBomb.ActivateCollisionSprite(this.sbBoxes);
            pBomb.ActivateGameSprite(this.sbAliens);
            pTree.Insert(pBomb, pBombRoot);
        }
示例#8
0
        public Bomb Create(float x, float y, FallType type)
        {
            Bomb pBomb = null;

            this.pBombRoot = new BombRoot(GameObjectName.BombRoot, SpriteBaseName.Null, 0.0f, 0.0f, 0);
            this.pTree.Insert(pBombRoot, null);
            pBombRoot.ActivateCollisionSprite(this.pSpriteBatch);
            pBomb = new Bomb(GameObjectName.Bomb, SpriteBaseName.BombStraight, new FallStraight(), x, y, 0);
            this.pTree.Insert(pBomb, pBombRoot);
            pBomb.ActivateCollisionSprite(this.pSpriteBatch);
            pBomb.ActivateGameSprite(this.pSpriteBatch);
            GameObjectManager.AttachTree(pBombRoot);
            return(pBomb);
        }
示例#9
0
        public override void Execute(float deltaTime)
        {
            Composite pAlienGrid = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.AlienGrid);

            // If Alien Grid has at least one column
            if (pAlienGrid.GetFirstChild() != null)
            {
                Composite pBombRoot = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.BombRoot);

                // Identify random Column + starting location
                int       randomColIndex         = r.Next(0, pAlienGrid.GetNumOfChildren());
                Composite pAlienCol              = pAlienGrid.GetChildByIndex(randomColIndex);
                Azul.Rect pAlienColCollisionRect = pAlienCol.GetCollisionObject().GetCollisionRect();

                float xPos = (pAlienColCollisionRect.x + (pAlienColCollisionRect.width / 2.0f));
                float yPos = (pAlienColCollisionRect.y - (pAlienColCollisionRect.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
                Bomb pBomb = new Bomb(GameObject.Name.Bomb, (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));
            }
        }
        public static Bomb CreateBomb(AlienColumn pOwner)
        {
            // each column owns one instance of a bomb that is reused.
            // create a null bomb
            Bomb pBomb = new Bomb(pOwner);

            SpriteBatch pSB_Aliens = SpriteBatchManager.Find(SpriteBatch.Name.Aliens);
            SpriteBatch pSB_Boxes  = SpriteBatchManager.Find(SpriteBatch.Name.Boxes);

            pBomb.ActivateCollisionSprite(pSB_Boxes);
            pBomb.ActivateGameSprite(pSB_Aliens);

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

            Debug.Assert(pBombRoot != null);

            // Add to GameObject Tree - {update and collisions}
            pBombRoot.Add(pBomb);

            return(pBomb);
        }
示例#11
0
        public override void Execute(float deltaTime, TimeEvent.Name name)
        {
            //if (Component.right > 896 || Component.left < 0.0f)
            //{
            //    Component.speed *= -1.0f;
            //    grid.MoveDown();
            //}
            //Component.right += Component.speed;
            //Component.left += Component.speed;
            grid.MoveGrid();

            IrrKlang.ISoundEngine pSndEngine = SpaceInvaders.GetInstance().sndEngine;
            pSndEngine.SoundVolume = 0.2f;
            if (counting % 4 == 0)
            {
                pSndEngine.Play2D("fastinvader1.wav");
            }
            else if (counting % 4 == 1)
            {
                pSndEngine.Play2D("fastinvader2.wav");
            }
            else if (counting % 4 == 2)
            {
                pSndEngine.Play2D("fastinvader3.wav");
            }
            else if (counting % 4 == 3)
            {
                pSndEngine.Play2D("fastinvader4.wav");
            }
            counting++;

            //1, using ForwardIterator
            ForwardIterator pIterator = new ForwardIterator(grid);
            Random          rnd       = new Random();
            int             num       = rnd.Next(0, 11);

            Debug.WriteLine("        random number generated: {0}", num);
            Component pColumn = null;
            bool      flag    = false;

            for (int i = 0; i <= num; i++)
            {
                if (pColumn == null && flag == true)
                {
                    break;
                }
                pColumn = pIterator.Next();
                flag    = true;
                if (pColumn == null)
                {
                    break;
                }
                while (pColumn.holder != Component.Container.COMPOSITE)
                {
                    pColumn = pIterator.Next();
                    if (pColumn == null)
                    {
                        break;
                    }
                }
            }



            //2, using Iterator
            //Component pColumn = Iterator.GetChild(grid);
            //pColumn = Iterator.GetSibling(pColumn);
            if (pColumn != null)
            {
                //Debug.WriteLine("  3,     child type: {0}", pColumn);
                Bomb pBomb = ((AlienColumn)pColumn).ActivateBomb(rnd);
                pBomb.ActivateGameSprite(this.pSpriteBatch);
                pBomb.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                pTree.Add(pBomb);
            }


            // Add itself back to timer
            TimerMan.Add(name, this, deltaTime - 0.003f);
        }