Esempio n. 1
0
        // create 5 * 11 alien grid for given player at given location
        public static GameObject CreateAlienGrid(SpriteBatch.Name sbName, float x, float y)
        {
            // squid
            // crab
            // octopus
            GameSprite alienGridSprite = GameSpriteFactory.CreateCompositeSprite(GameObject.Category.AlienGrid, GameObject.CompositeType.Grid
                                                                                 , x, y, Image.Name.Nothing);

            Image explosionImage = ImageManager.getInstance().FindImageByName(Image.Name.AlienExplosion);


            GlobalPlayerStats.playerstats pStats;

            if (sbName == SpriteBatch.Name.Player1)
            {
                pStats = GlobalPlayerStats.Player1;
            }
            else
            {
                pStats = GlobalPlayerStats.Player2;
            }

            GameObject alienGrid = alienGridSprite.pGameObject;

            // 11 columns
            for (int i = 0; i < 11; i++)
            {
                GameSprite.Name gName;
                Image.Name      imgName;
                Image.Name      altImgName;

                GameSprite       gs;
                SwapImgAnimation swapAni;

                GameSprite alienCol = GameSpriteFactory.CreateCompositeSprite(GameObject.Category.AlienCol, GameObject.CompositeType.Column
                                                                              , x, y, Image.Name.Nothing);

                // 5 rows
                for (int j = 0; j < 5; j++)
                {
                    if (j == 0)
                    {
                        gName      = GameSprite.Name.Squid;
                        imgName    = Image.Name.Squid_1;
                        altImgName = Image.Name.Squid_2;
                    }
                    else if (j < 3)
                    {
                        gName      = GameSprite.Name.Crab;
                        imgName    = Image.Name.Crab_1;
                        altImgName = Image.Name.Crab_2;
                    }
                    else
                    {
                        gName      = GameSprite.Name.Octopus;
                        imgName    = Image.Name.Octopus_1;
                        altImgName = Image.Name.Octopus_2;
                    }

                    gs = CreateGameSprite(GameObject.Category.Alien, gName, sbName, x + i * 60f, y - j * 55f, 40.0f, 40.0f, imgName);
                    gs.addImage(altImgName);
                    gs.pExplosionImage = explosionImage;

                    // Add SwapImage animations
                    swapAni = new SwapImgAnimation(gs.pGameObject, 1.0f - 0.05f * pStats.currentLevel);
                    TimerManager.getInstance().Add(TimerEvent.Name.SwapImageAnimation, swapAni, 1.0f - 0.05f * pStats.currentLevel);

                    // Add Sprite to column
                    alienCol.pGameObject.AddChild(gs.pGameObject);
                }

                // Set Bomb Dropping logic
                alienCol.pGameObject.dropID = i;
                BombDropCommand dropCmd = new BombDropCommand(alienCol.pGameObject, pStats.currentLevel);
                TimerManager.getInstance().Add(TimerEvent.Name.DropBombCommand, dropCmd, 3.0f - 0.2f * pStats.currentLevel);

                // --add col to the batch
                SpriteBatchManager.getInstance().FindSpriteBatchByName(sbName).AddSprite(alienCol);

                alienGrid.AddChild(alienCol.pGameObject);
            }

            // Configure alien advance animation
            alienGrid.CompositeSetDelta(20.0f);
            AlienAdvanceAnimation alienAdv = new AlienAdvanceAnimation(alienGrid, 1.0f - 0.05f * pStats.currentLevel);

            TimerManager.getInstance().Add(TimerEvent.Name.AlienAdvanceAnimation, alienAdv, 1.0f - 0.1f * pStats.currentLevel);
            // -- add grid to the batch
            if (GlobalConfiguration.showCollisionRect)
            {
                SpriteBatchManager.getInstance().FindSpriteBatchByName(sbName).AddSprite(alienGrid.colliRect.box);
            }

            SpriteBatchManager.getInstance().FindSpriteBatchByName(sbName).AddSprite(alienGridSprite);

            return(alienGrid);
        }