Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static GridState GetState(InvaderGridManager.State state)
        {
            InvaderGridManager pMan = InvaderGridManager.PrivGetInstance();

            Debug.Assert(pMan != null);

            GridState pGridState = null;

            switch (state)
            {
            case InvaderGridManager.State.NotCollingWithWall:
                pGridState = pMan.pNotCollingState;
                break;

            case InvaderGridManager.State.CollidingLeftWall:
                pGridState = pMan.pCollidingLeft;
                break;

            case InvaderGridManager.State.CollidingRightWall:
                pGridState = pMan.pCollidingRight;
                break;
            }

            return(pGridState);
        }
Ejemplo n.º 3
0
        private static InvaderGridManager PrivGetInstance()
        {
            if (pInstance == null)
            {
                pInstance = new InvaderGridManager();
            }
            Debug.Assert(pInstance != null);

            return(pInstance);
        }
Ejemplo n.º 4
0
 public void SetState(InvaderGridManager.State inState)
 {
     this.state = InvaderGridManager.GetState(inState);
 }
Ejemplo n.º 5
0
        public Bomb Create(Type type)
        {
            InvaderCategory pInvader = InvaderGridManager.GetRandomBombDropper(this.pInvaderGrid);
            Bomb            pBomb    = null;

            if (pInvader != null)
            {
                float posX = pInvader.x;
                float posY = pInvader.y;

                switch (type)
                {
                case Type.Plain:
                    pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombPlain, BoxSprite.Name.BombBox, posX, posY);
                    break;

                case Type.ZigZag:
                    pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombZigZag, BoxSprite.Name.BombBox, posX, posY);
                    break;

                case Type.Dagger:
                    pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombDagger, BoxSprite.Name.BombBox, posX, posY);
                    break;

                case Type.Rolling:
                    pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombRolling, BoxSprite.Name.BombBox, posX, posY);
                    break;

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

                // set pointer back to invader who dropped the bomb
                pBomb.pInvaderWhoDroppedMe = pInvader;
                pBomb.pInvaderWhoDroppedMe.canLaunchBomb = false; //block this invader from dropping another bomb until curren bomb dies

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

                // Attached to Batches
                this.pBoxSpriteBatch.Attach(pBomb.poColObj.pColSprite);
                this.pSpriteBatch.Attach(pBomb.pProxySprite);

                // Add Collision Pairs and Observers
                ColPair pMissile_BombColPair = ColPairManager.Add(ColPair.Name.Missile_Bomb, pBomb, ShipManager.GetMissile());
                Debug.Assert(pMissile_BombColPair != null);

                ColPair pBomb_FloorColPair = ColPairManager.Add(ColPair.Name.Bomb_Floor, pBomb, pWallMan.GetFloor());
                Debug.Assert(pBomb_FloorColPair != null);

                ColPair pBomb_ShipColPair = ColPairManager.Add(ColPair.Name.Bomb_Ship, pBomb, ShipManager.GetShip());
                Debug.Assert(pBomb_ShipColPair != null);

                // Observers for Bomb vs Missile
                pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair));
                pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair));
                pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair));
                pMissile_BombColPair.Attach(new ShipMissileReadyObserver());
                pMissile_BombColPair.Attach(new ShipRemoveMissileObserver());
                pMissile_BombColPair.Attach(new RemoveBombObserver());

                //// Observers for Bomb vs Floor
                pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair));
                pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair));
                pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair));
                pBomb_FloorColPair.Attach(new RemoveBombObserver());

                // Observers for Bomb vs Ship
                pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair));
                pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair));
                pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair));
                pBomb_ShipColPair.Attach(new RemoveShipObserver());
                pBomb_ShipColPair.Attach(new RemoveBombObserver());


                GameObject pShieldZone = GameObjectManager.UnsafeFind(GameObject.Name.ShieldZone);
                if (pShieldZone != null)
                {
                    // Add Collision pair for Bomb vs Shields
                    ColPair pBomb_ShieldColPair = ColPairManager.Add(ColPair.Name.Bomb_Shield, pBomb, pShieldZone);
                    Debug.Assert(pBomb_ShieldColPair != null);

                    // Added observers to previous shield pairs to remove the bomb vs shield col pair
                    pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair));
                    pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair));
                    pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair));

                    // Observers for Bomb vs Shield
                    pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair));
                    pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair));
                    pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair));
                    pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair));
                    pBomb_ShieldColPair.Attach(new RemoveBombObserver());
                    pBomb_ShieldColPair.Attach(new RemoveShieldBrickObserver());
                }
            }

            return(pBomb);
        }
Ejemplo n.º 6
0
        protected virtual void PlayerTwoInit(GameManager pGameManager)
        {
            float levelSpeed = 0.75f / pGameManager.pActivePlayer.level;

            pGameManager.poPlayer2.pGrid = InvaderGridManager.GenerateGrid(pGameManager.pActivePlayer.level);
            //Debug.WriteLine("Generated Grid ({0}) for P2", pGameManager.poPlayer2.pGrid.GetHashCode());

            pGameManager.poPlayer2.pShieldZone = ShieldBuilder.CreateShieldZone(175, 300, 150, 4);

            //---------------------------------------------------------------------------------------------------------
            // Create GameSpace and Wall Objects
            //---------------------------------------------------------------------------------------------------------
            WallManager pWallMan = new WallManager();

            //Debug.WriteLine("WallLeft Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.leftWallXPos, Constants.leftWallYPos, Constants.leftWallWidth, Constants.leftWallHeight);
            //Debug.WriteLine("WallRight Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.rightWallXPos, Constants.rightWallYPos, Constants.rightWallWidth, Constants.rightWallHeight);
            //Debug.WriteLine("Ceiling Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.ceilingXPos, Constants.ceilingYPos, Constants.ceilingWidth, Constants.ceilingHeight);
            //Debug.WriteLine("Floor Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.floorXPos, Constants.floorYPos, Constants.floorWidth, Constants.floorHeight);

            //---------------------------------------------------------------------------------------------------------
            // Set up Sprite Animations
            //---------------------------------------------------------------------------------------------------------
            // Set up animations for the 3 basic Invaders
            AnimationSprite pSmInvaderAnim = new AnimationSprite(Sprite.Name.SmallInvader);

            pSmInvaderAnim.Attach(Image.Name.SmallInvader1);
            pSmInvaderAnim.Attach(Image.Name.SmallInvader2);

            AnimationSprite pMedInvaderAnim = new AnimationSprite(Sprite.Name.MediumInvader);

            pMedInvaderAnim.Attach(Image.Name.MediumInvader1);
            pMedInvaderAnim.Attach(Image.Name.MediumInvader2);

            AnimationSprite pLgInvaderAnim = new AnimationSprite(Sprite.Name.LargeInvader);

            pLgInvaderAnim.Attach(Image.Name.LargeInvader1);
            pLgInvaderAnim.Attach(Image.Name.LargeInvader2);

            // Add the Invader animations as timed events to the TimerManager
            TimerManager.Add(TimeEvent.Name.SmInvaderMarchAnimation, pSmInvaderAnim, levelSpeed);
            TimerManager.Add(TimeEvent.Name.MedInvaderMarchAnimation, pMedInvaderAnim, levelSpeed);
            TimerManager.Add(TimeEvent.Name.LgInvaderMarchAnimation, pLgInvaderAnim, levelSpeed);

            // Set up bomb animations
            AnimationSprite pBombZigZagAnim = new AnimationSprite(Sprite.Name.BombZigZag);

            pBombZigZagAnim.Attach(Image.Name.BombZigZag1);
            pBombZigZagAnim.Attach(Image.Name.BombZigZag2);
            pBombZigZagAnim.Attach(Image.Name.BombZigZag3);
            pBombZigZagAnim.Attach(Image.Name.BombZigZag4);

            AnimationSprite pBombDaggerAnim = new AnimationSprite(Sprite.Name.BombDagger);

            pBombDaggerAnim.Attach(Image.Name.BombDagger1);
            pBombDaggerAnim.Attach(Image.Name.BombDagger2);
            pBombDaggerAnim.Attach(Image.Name.BombDagger3);
            pBombDaggerAnim.Attach(Image.Name.BombDagger4);

            AnimationSprite pBombRollingAnim = new AnimationSprite(Sprite.Name.BombRolling);

            pBombRollingAnim.Attach(Image.Name.BombRolling1);
            pBombRollingAnim.Attach(Image.Name.BombRolling2);

            // Add the bomb animations as timed events to the TimerManager
            TimerManager.Add(TimeEvent.Name.BombAnimation, pBombZigZagAnim, 0.25f);
            TimerManager.Add(TimeEvent.Name.BombAnimation, pBombDaggerAnim, 0.25f);
            TimerManager.Add(TimeEvent.Name.BombAnimation, pBombRollingAnim, 0.25f);


            //---------------------------------------------------------------------------------------------------------
            // Set up TimedSoundEffects
            //---------------------------------------------------------------------------------------------------------
            TimedSoundEffects pGridMarchingSounds = new TimedSoundEffects();

            pGridMarchingSounds.Attach(Sound.Name.InvaderMarch4);
            pGridMarchingSounds.Attach(Sound.Name.InvaderMarch3);
            pGridMarchingSounds.Attach(Sound.Name.InvaderMarch2);
            pGridMarchingSounds.Attach(Sound.Name.InvaderMarch1);

            TimerManager.Add(TimeEvent.Name.GridMarchSoundEffects, pGridMarchingSounds, levelSpeed);

            //---------------------------------------------------------------------------------------------------------
            // Setting up the collisions for the player ship and missile
            //---------------------------------------------------------------------------------------------------------
            Ship    pShip    = ShipManager.ActivateShip();
            Missile pMissile = ShipManager.GetMissile();

            //---------------------------------------------------------------------------------------------------------
            // Add Collision Pairs and their Observers
            //---------------------------------------------------------------------------------------------------------
            // Applies to both players
            // ship vs left wall
            ColPair pShip_WallLeftColPair = ColPairManager.Add(ColPair.Name.Ship_WallLeft, pShip, pWallMan.GetWallLeft());

            Debug.Assert(pShip_WallLeftColPair != null);
            pShip_WallLeftColPair.Attach(new Ship_WallLeftObserver());
            // ship vs Right wall
            ColPair pShip_WallRightColPair = ColPairManager.Add(ColPair.Name.Ship_WallRight, pShip, pWallMan.GetWallRight());

            Debug.Assert(pShip_WallRightColPair != null);
            pShip_WallRightColPair.Attach(new Ship_WallRightObserver());
            // Missile vs Ceiling
            ColPair pMissile_CeilingColPair = ColPairManager.Add(ColPair.Name.Missile_Ceiling, pMissile, pWallMan.GetCeiling());

            Debug.Assert(pMissile_CeilingColPair != null);
            pMissile_CeilingColPair.Attach(new ShipMissileReadyObserver());
            pMissile_CeilingColPair.Attach(new ShipRemoveMissileObserver());

            //---------------------------------------------------------------------------------------------------------
            // Set up Random UFO Spawns
            //---------------------------------------------------------------------------------------------------------
            RandomlySpawnUFO pRandomUfoEvent = new RandomlySpawnUFO(30.0f, pMissile, pWallMan);

            TimerManager.Add(TimeEvent.Name.RandomlySpawnUFO, pRandomUfoEvent, 10.0f);


            //---------------------------------------------------------------------------------------------------------
            // Create Alien Grid and random bomb drops
            //---------------------------------------------------------------------------------------------------------
            BombFactory       pBombFactory     = new BombFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, pGameManager.poPlayer2.pGrid, pWallMan);
            RandomlySpawnBomb pRandomBombEvent = new RandomlySpawnBomb(2.0f, pBombFactory);

            TimerManager.Add(TimeEvent.Name.RandomBombSpawn, pRandomBombEvent, 2.0f);

            // Applies to players seperately
            // Set up timing for Grid and UFO motion
            TimeBasedMover pGridMover = new TimeBasedMover(pGameManager.poPlayer2.pGrid);

            TimerManager.Add(TimeEvent.Name.TimedGridMover, pGridMover, levelSpeed);

            //---------------------------------------------------------------------------------------------------------
            // Create the Shields
            //---------------------------------------------------------------------------------------------------------

            // Applies to each player seperately
            // grid vs leftwall
            ColPair pGrid_WallLeftColPair = ColPairManager.Add(ColPair.Name.Grid_WallLeft, pGameManager.poPlayer2.pGrid, pWallMan.GetWallLeft());

            Debug.Assert(pGrid_WallLeftColPair != null);
            pGrid_WallLeftColPair.Attach(new Grid_WallLeftObserver());
            // Grid vs rightwall
            ColPair pGrid_WallRightcolPair = ColPairManager.Add(ColPair.Name.Grid_WallRight, pGameManager.poPlayer2.pGrid, pWallMan.GetWallRight());

            Debug.Assert(pGrid_WallRightcolPair != null);
            pGrid_WallRightcolPair.Attach(new Grid_WallRightObserver());
            // Grid vs ship
            ColPair pShip_GridColPair = ColPairManager.Add(ColPair.Name.Ship_Grid, pShip, pGameManager.poPlayer2.pGrid);

            Debug.Assert(pShip_GridColPair != null);
            pShip_GridColPair.Attach(new RemoveShipObserver());
            // Grid vs Missile
            ColPair pMissile_GridColPair = ColPairManager.Add(ColPair.Name.Missile_Grid, pMissile, pGameManager.poPlayer2.pGrid);

            Debug.Assert(pMissile_GridColPair != null);
            pMissile_GridColPair.Attach(new ShipRemoveMissileObserver());
            pMissile_GridColPair.Attach(new ShipMissileReadyObserver());
            pMissile_GridColPair.Attach(new RemoveInvaderObserver());
            pMissile_GridColPair.Attach(new AwardPointsObserver());
            // Grid vs Shields
            ColPair pGrid_ShieldZoneColPair = ColPairManager.Add(ColPair.Name.Grid_ShieldZone, pGameManager.poPlayer2.pGrid, pGameManager.poPlayer2.pShieldZone);

            pGrid_ShieldZoneColPair.Attach(new RemoveShieldBrickObserver());

            // Missile vs Shields
            ColPair pMissile_ShieldZoneColPair = ColPairManager.Add(ColPair.Name.Missile_ShieldZone, pMissile, pGameManager.poPlayer2.pShieldZone);

            pMissile_ShieldZoneColPair.Attach(new ShipMissileReadyObserver());
            pMissile_ShieldZoneColPair.Attach(new ShipRemoveMissileObserver());
            pMissile_ShieldZoneColPair.Attach(new RemoveShieldBrickObserver());


            // STORE Current State of managers into manager mementos
            pGameManager.poPlayer2.ArchiveManagerStates(pGameManager.pGame.GetTime());
        }