GAM456-SpaceInvaders / SpaceInvaders / 7_GameState / State_Play2.cs
State_Play2.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class State_Play2 : State
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        //these change based on player 1 vs 2
        TimerEventMan poTimerMan;
        SpriteBatchMan poSpriteBatchMan;
        ObjectNodeMan poObjNodeMan;
        GhostMan poGhostMan;
        CollisionPairMan poCollisionMan;
        FontMan poFontMan;

        State nextState;

        SpriteBatch pBoxBatch;

        
        // Alien Grid Info
        const float initialDelta = 0.5f;
        float currDelta = initialDelta;

        Random rand = new Random();


        //-------------------------------------------------------------------
        //  CONSTRUCTION
        //-------------------------------------------------------------------

        public State_Play2() : base()
        {
            Debug.Assert(State.pContext != null);
        }


        //-------------------------------------------------------------------
        //  PUBLIC METHODS
        //-------------------------------------------------------------------

        public override void Init()
        {
            //---------------------------------------------------------------
            // LOAD MANAGERS
            //---------------------------------------------------------------

            // Player Dependent Managers
            this.poSpriteBatchMan = new SpriteBatchMan();
            Debug.Assert(poSpriteBatchMan != null);
            SpriteBatchMan.SetActiveMan(this.poSpriteBatchMan);

            this.poObjNodeMan = new ObjectNodeMan();
            Debug.Assert(this.poObjNodeMan != null);
            ObjectNodeMan.SetActiveMan(this.poObjNodeMan);

            this.poGhostMan = new GhostMan();
            Debug.Assert(this.poGhostMan != null);
            GhostMan.SetActiveMan(this.poGhostMan);

            this.poTimerMan = new TimerEventMan();
            Debug.Assert(this.poTimerMan != null);

            TimerEventMan.SetActiveMan(this.poTimerMan);
            TimerEventMan.PauseAllEvents();

            this.poCollisionMan = new CollisionPairMan();
            Debug.Assert(this.poCollisionMan != null);
            CollisionPairMan.SetActiveMan(this.poCollisionMan);

            this.poFontMan = new FontMan();
            Debug.Assert(this.poFontMan != null);
            FontMan.SetActiveMan(this.poFontMan);


            //---------------------------------------------------------------
            // LOAD SPRITE BATCH
            //---------------------------------------------------------------

            SpriteBatch pUFOBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.UFO, 5);
            SpriteBatch pAlienBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Aliens, 1);
            SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Bombs, 2);

            SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Ships, 1);
            SpriteBatch pMissileBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Missles, 3);
            SpriteBatch pShieldBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Shields, 2);

            SpriteBatch pWallBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Walls, 4);
            SpriteBatch pBumperBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Bumpers, 4);

            SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Text_UI, 5);
            pBoxBatch = SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Boxes, 0);


            //---------------------------------------------------------------
            // LOAD TEXT
            //---------------------------------------------------------------

            FontMan.AddFont(Font.FontName.P1_Score_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "SCORE<1>", 40, 980, 3.9f, 4.4f, 1.35f);
            FontMan.AddFont(Font.FontName.P1_Score, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "0000", 90, 930, 3.9f, 4.4f, 1.35f);

            FontMan.AddFont(Font.FontName.P2_Score_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "SCORE<2>", 620, 980, 3.9f, 4.4f, 1.35f);
            if(State.pContext.GetPlayMode())
            {
                FontMan.AddFont(Font.FontName.P2_Score, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "0000", 680, 930, 3.9f, 4.4f, 1.35f);
            }

            FontMan.AddFont(Font.FontName.HighScore_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "HI-SCORE", 330, 980, 3.9f, 4.4f, 1.35f);
            FontMan.AddFont(Font.FontName.HighScore, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "0000", 380, 930, 3.9f, 4.4f, 1.35f);

            FontMan.AddFont(Font.FontName.GameCredits, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "CREDIT 00", 570, 40, 3.9f, 4.4f, 1.35f);
            FontMan.AddFont(Font.FontName.PlayerLife, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "3", 70, 40, 3.9f, 4.4f, 1.35f);


            //---------------------------------------------------------------
            // LOAD WALLS & BUMPERS
            //---------------------------------------------------------------

            // Walls
            WallGroup pWallGroup = new WallGroup(GameObject.ObjectName.WallGroup, Sprite.SpriteName.NullObject, 0.0f, 0.0f);
            pWallGroup.ActivateSprite(pWallBatch);

            TopWall pTop = new TopWall(GameObject.ObjectName.Top_Wall, Sprite.SpriteName.NullObject, 450, 930, 870, 30);
            pTop.ActivateSprite(pWallBatch);
            pTop.ActivateCollisionSprite(pBoxBatch);

            BottomWall pBottom = new BottomWall(GameObject.ObjectName.Bottom_Wall, Sprite.SpriteName.NullObject, 448, 40, 870, 30);
            pBottom.ActivateSprite(pWallBatch);
            pBottom.ActivateCollisionSprite(pBoxBatch);

            LeftWall pLeft = new LeftWall(GameObject.ObjectName.Left_Wall, Sprite.SpriteName.NullObject, 15, 525, 10, 950);
            pLeft.ActivateSprite(pWallBatch);
            pLeft.ActivateCollisionSprite(pBoxBatch);

            RightWall pRight = new RightWall(GameObject.ObjectName.Right_Wall, Sprite.SpriteName.NullObject, 880, 525, 10, 950);
            pRight.ActivateSprite(pWallBatch);
            pRight.ActivateCollisionSprite(pBoxBatch);

            pWallGroup.AddComponent(pTop);
            pWallGroup.AddComponent(pBottom);
            pWallGroup.AddComponent(pLeft);
            pWallGroup.AddComponent(pRight);
            ObjectNodeMan.AttachObject(pWallGroup);

            // Bumpers
            BumperRoot pBumperRoot = new BumperRoot(GameObject.ObjectName.Bumpers, Sprite.SpriteName.NullObject, 0.0f, 0.0f);
            pWallGroup.ActivateSprite(pBumperBatch);

            LeftBumper pLeftBumper = new LeftBumper(GameObject.ObjectName.LeftBumper, Sprite.SpriteName.NullObject, 40.0f, 100.0f, 20.0f, 100.0f);
            pLeftBumper.ActivateCollisionSprite(pBoxBatch);

            RightBumper pRightBumper = new RightBumper(GameObject.ObjectName.RightBumper, Sprite.SpriteName.NullObject, 855.0f, 100.0f, 20.0f, 100.0f);
            pRightBumper.ActivateCollisionSprite(pBoxBatch);

            pBumperRoot.AddComponent(pLeftBumper);
            pBumperRoot.AddComponent(pRightBumper);
            ObjectNodeMan.AttachObject(pBumperRoot);


            //---------------------------------------------------------------
            // LOAD SHIELDS
            //---------------------------------------------------------------

            ShieldGrid pShieldGrid = new ShieldGrid(GameObject.ObjectName.ShieldGrids, Sprite.SpriteName.NullObject, 0, 0);
            pShieldGrid.ActivateSprite(pShieldBatch);
            pShieldGrid.ActivateCollisionSprite(pBoxBatch);

            GameObject pShield;
            pShield = ShieldFactory.CreateShield(120.0f, 150.0f);
            pShield.ActivateSprite(pShieldBatch);
            pShield.ActivateCollisionSprite(pBoxBatch);
            pShieldGrid.AddComponent(pShield);

            pShield = ShieldFactory.CreateShield(300.0f, 150.0f);
            pShield.ActivateSprite(pShieldBatch);
            pShield.ActivateCollisionSprite(pBoxBatch);
            pShieldGrid.AddComponent(pShield);

            pShield = ShieldFactory.CreateShield(480.0f, 150.0f);
            pShield.ActivateSprite(pShieldBatch);
            pShield.ActivateCollisionSprite(pBoxBatch);
            pShieldGrid.AddComponent(pShield);

            pShield = ShieldFactory.CreateShield(660.0f, 150.0f);
            pShield.ActivateSprite(pShieldBatch);
            pShield.ActivateCollisionSprite(pBoxBatch);
            pShieldGrid.AddComponent(pShield);

            ObjectNodeMan.AttachObject(pShieldGrid);


            //---------------------------------------------------------------
            // LOAD ALIENS
            //---------------------------------------------------------------

            GameObject pAlienGrid = AlienFactory.CreateGrid(110.0f, 750.0f);
            pAlienGrid.ActivateSprite(pAlienBatch);
            pAlienGrid.ActivateCollisionSprite(pBoxBatch);

            UFOAlienRoot pUFORoot = new UFOAlienRoot(GameObject.ObjectName.UFORoot, Sprite.SpriteName.NullObject, 0.0f, 0.0f);
            pUFORoot.ActivateSprite(pUFOBatch);
            ObjectNodeMan.AttachObject(pUFORoot);


            //---------------------------------------------------------------
            // LOAD SHIP
            //---------------------------------------------------------------

            ShipRoot pShipRoot = new ShipRoot(GameObject.ObjectName.ShipRoot, Sprite.SpriteName.NullObject, 0.0f, 0.0f);
            ObjectNodeMan.AttachObject(pShipRoot);

            ShipMan.Create();


            //---------------------------------------------------------------
            // LOAD MISSILES
            //---------------------------------------------------------------

            MissileGroup pMissileGroup = new MissileGroup();
            pMissileGroup.ActivateSprite(pMissileBatch);
            pMissileGroup.ActivateCollisionSprite(pBoxBatch);

            ObjectNodeMan.AttachObject(pMissileGroup);


            //---------------------------------------------------------------
            // LOAD BOMBS
            //---------------------------------------------------------------

            BombRoot pBombRoot = new BombRoot(GameObject.ObjectName.BombRoot, Sprite.SpriteName.NullObject, 0.0f, 0.0f);
            ObjectNodeMan.AttachObject(pBombRoot);


            //---------------------------------------------------------------
            // LOAD ANIMATIONS
            //---------------------------------------------------------------

            AnimateSprite pAnimateOctopus = new AnimateSprite(Sprite.SpriteName.Octopus);
            pAnimateOctopus.Attach(Image.ImageName.Octopus_Open);
            pAnimateOctopus.Attach(Image.ImageName.Octopus_Closed);

            AnimateSprite pAnimateCrab = new AnimateSprite(Sprite.SpriteName.Crab);
            pAnimateCrab.Attach(Image.ImageName.Crab_Open);
            pAnimateCrab.Attach(Image.ImageName.Crab_Closed);

            AnimateSprite pAnimateSquid = new AnimateSprite(Sprite.SpriteName.Squid);
            pAnimateSquid.Attach(Image.ImageName.Squid_Open);
            pAnimateSquid.Attach(Image.ImageName.Squid_Closed);

            TimerEventMan.AddEvent(TimerEvent.EventName.DeployUFO, new DeployUFO(), rand.Next(7, 30));

            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateOctopus, pAnimateOctopus, 0.5f);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateCrab, pAnimateCrab, 0.5f);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSquid, pAnimateSquid, 0.5f);

            AnimateGrid pMoveGrid = new AnimateGrid(pAlienGrid, 7.0f);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateGrid, pMoveGrid, initialDelta);

            PlayAlienSounds pPlaySound = new PlayAlienSounds();
            TimerEventMan.AddEvent(TimerEvent.EventName.PlayGridSound, pPlaySound, 0.6f);

            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), 1.0f);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), 3.0f);


            //---------------------------------------------------------------
            // LOAD COLLISION PAIRS
            //---------------------------------------------------------------

            CollisionPair pPair;

            //ship vs bumpers -- works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Ship_Bumper, pBumperRoot, pShipRoot);
            pPair.AttachListener(new ShipMoveObserver());

            //ship vs bomb -- works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Ship_Bomb, pShipRoot, pBombRoot);
            pPair.AttachListener(new RemoveBombObserver());
            pPair.AttachListener(new ShipDeathObserver());
            pPair.AttachListener(new ShipExplosionObserver());

            //alien vs left/right wall--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Grid_Wall, pAlienGrid, pWallGroup);
            pPair.AttachListener(new AlienGridObserver());

            //alien vs shield
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Alien_Shield, pAlienGrid, pShieldGrid);
            pPair.AttachListener(new RemoveBrickObserver());

            //Bomb vs Bottom Wall -- works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Bomb_Wall, pWallGroup, pBombRoot);
            pPair.AttachListener(new RemoveBombObserver());

            //Bomb vs Shield--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Bomb_Shield, pShieldGrid, pBombRoot);
            pPair.AttachListener(new RemoveBombObserver());
            pPair.AttachListener(new RemoveBrickObserver());

            //bomb vs missile -- works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Missile_Bomb, pBombRoot, pMissileGroup);
            pPair.AttachListener(new RemoveBombObserver());
            pPair.AttachListener(new RemoveMissileObserver());
            pPair.AttachListener(new ShipReadyObserver());

            //missile vs top wall--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Missile_Wall, pMissileGroup, pWallGroup);
            pPair.AttachListener(new ShipReadyObserver());
            pPair.AttachListener(new RemoveMissileObserver());

            //missile vs shield--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Missile_Shield, pMissileGroup, pShieldGrid);
            pPair.AttachListener(new RemoveMissileObserver());
            pPair.AttachListener(new RemoveBrickObserver());
            pPair.AttachListener(new ShipReadyObserver());

            //missile vs alien--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Missile_Alien, pMissileGroup, pAlienGrid);
            pPair.AttachListener(new RemoveMissileObserver());
            pPair.AttachListener(new ShipReadyObserver());
            pPair.AttachListener(new RemoveAlienObserver());
            pPair.AttachListener(new InvaderDeathObserver());
            pPair.AttachListener(new PlayerPointsObserver());

            //missile vs UFO--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.Missile_UFO, pUFORoot, pMissileGroup);
            pPair.AttachListener(new RemoveMissileObserver());
            pPair.AttachListener(new ShipReadyObserver());
            pPair.AttachListener(new RemoveUFOObserver());
            pPair.AttachListener(new InvaderDeathObserver());
            pPair.AttachListener(new PlayerPointsObserver());

            //UFO vs left/right Wall--works
            pPair = CollisionPairMan.AddPair(CollisionPair.CollideObjs.UFO_Wall, pUFORoot, pWallGroup);
            pPair.AttachListener(new RemoveUFOObserver());

        }

        public override void OnEnter()
        {
            //set context
            TimerEventMan.SetActiveMan(this.poTimerMan);
            SpriteBatchMan.SetActiveMan(this.poSpriteBatchMan);
            ObjectNodeMan.SetActiveMan(this.poObjNodeMan);
            GhostMan.SetActiveMan(this.poGhostMan);

            FontMan.SetActiveMan(this.poFontMan);
            CollisionPairMan.SetActiveMan(this.poCollisionMan);

            InputSubject pSubject = InputMan.GetLeftArrow();
            pSubject.Attach(new MoveLeftObserver());

            pSubject = InputMan.GetRightArrow();
            pSubject.Attach(new MoveRightObserver());

            pSubject = InputMan.GetSpace();
            pSubject.Attach(new ShootObserver());

            pSubject = InputMan.GetKeyT();
            pSubject.Attach(new ToggleObserver(pBoxBatch));

            //update timer
            TimerEventMan.UnpauseEvents();

            Simulation.SetSimState(Simulation.SimState.Realtime);
        }

        public override void Update(float sysTime)
        {
            InputMan.Update();
            Simulation.Update(sysTime);

            if (Simulation.GetTimestep() > 0.0f)
            {
                TimerEventMan.ProcessEvent(Simulation.GetTotalTime());
                ObjectNodeMan.UpdateObject();
                CollisionPairMan.ProcessCollision();
                DelayObjectMan.ProcessDelay();
            }
        }

        public override void Draw()
        {
            SpriteBatchMan.DrawBatch();
        }

        public override void OnExit()
        {
            // Unattach Inputs
            InputSubject pInput = InputMan.GetLeftArrow();
            pInput.DetachInputs();

            pInput = InputMan.GetRightArrow();
            pInput.DetachInputs();

            pInput = InputMan.GetSpace();
            pInput.DetachInputs();

            pInput = InputMan.GetKeyT();
            pInput.DetachInputs();


            TimerEventMan.PauseAllEvents();

            SpriteBatchMan.UnactivateMan();
            ObjectNodeMan.UnactivateMan();
            FontMan.UnactivateMan();
            TimerEventMan.UnactivateMan();
            CollisionPairMan.UnactivateMan();
            GhostMan.UnactivateMan();
        }

        public override void Handle()
        {
            TimerEventMan.PauseAllEvents();

            Player pPlayer = PlayerMan.GetActivePlayer();
            Debug.Assert(pPlayer != null);

            // Update high score
            pContext.UpdateHighScore(pPlayer.GetPoints());

            // Go to player 2 or end state
            if(pContext.GetPlayMode())
            {
                Player pPlayer2 = PlayerMan.GetPlayer(Player.PlayerType.Player2);
                if (pPlayer2.GetLives() > 0)
                {
                    pContext.ChangeState(nextState);
                }
                else
                {
                    pContext.ChangeState(new State_End());
                }
            }
        }

        public void ResetLevel()
        {
            // Set player managers active (just in case)
            FontMan.SetActiveMan(this.poFontMan);
            ObjectNodeMan.SetActiveMan(this.poObjNodeMan);
            GhostMan.SetActiveMan(this.poGhostMan);
            SpriteBatchMan.SetActiveMan(this.poSpriteBatchMan);
            TimerEventMan.SetActiveMan(this.poTimerMan);

            // Update UI
            if(pContext.GetPlayMode())
            {
                // Two player mode
                // Grab Players
                Player pPlayer1 = PlayerMan.GetPlayer(Player.PlayerType.Player1);
                Player pPlayer2 = PlayerMan.GetPlayer(Player.PlayerType.Player2);

                // Player 1 score
                Font pFont = FontMan.FindFont(Font.FontName.P1_Score);
                pFont.UpdateMessage(pPlayer1.GetPoints().ToString("D4"));

                // Player 2 score
                pFont = FontMan.FindFont(Font.FontName.P2_Score);
                pFont.UpdateMessage(pPlayer2.GetPoints().ToString("D4"));

                // Current player life
                pFont = FontMan.FindFont(Font.FontName.PlayerLife);
                pFont.UpdateMessage(pPlayer1.GetLives().ToString());

                // HIgh score
                pFont = FontMan.FindFont(Font.FontName.HighScore);
                pFont.UpdateMessage(pContext.GetHighScore().ToString("D4"));
            }
            else
            {
                // Single player mode
                Player pPlayer1 = PlayerMan.GetPlayer(Player.PlayerType.Player1);

                // Player 1 score
                Font pFont = FontMan.FindFont(Font.FontName.P1_Score);
                pFont.UpdateMessage(pPlayer1.GetPoints().ToString("D4"));

                // Current player life
                pFont = FontMan.FindFont(Font.FontName.PlayerLife);
                pFont.UpdateMessage(pPlayer1.GetLives().ToString());

                // HIgh score
                pFont = FontMan.FindFont(Font.FontName.HighScore);
                pFont.UpdateMessage(pContext.GetHighScore().ToString("D4"));
            }

            // Clear previous resources
            ShieldGrid pShieldGrid = (ShieldGrid)ObjectNodeMan.FindObject(GameObject.ObjectName.ShieldGrids);
            ShieldFactory.GhostShields(pShieldGrid);

            AlienGrid pAlienGrid = (AlienGrid)ObjectNodeMan.FindObject(GameObject.ObjectName.AlienGrid);
            AlienFactory.GhostGrid(pAlienGrid);

            TimerEventMan.DetachEvents();

            // Recreate resources
            ShipMan.ActivateShip();

            GameObject pShield = ShieldFactory.CreateShield(120.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);
            pShield = ShieldFactory.CreateShield(300.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);
            pShield = ShieldFactory.CreateShield(480.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);
            pShield = ShieldFactory.CreateShield(660.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);

            pAlienGrid = (AlienGrid)AlienFactory.CreateGrid(110.0f, 750.0f);

            this.currDelta = initialDelta;
            AnimateSprite pAnimateSprite = new AnimateSprite(Sprite.SpriteName.Octopus);
            pAnimateSprite.Attach(Image.ImageName.Octopus_Open);
            pAnimateSprite.Attach(Image.ImageName.Octopus_Closed);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSprite, pAnimateSprite, initialDelta);

            pAnimateSprite = new AnimateSprite(Sprite.SpriteName.Crab);
            pAnimateSprite.Attach(Image.ImageName.Crab_Open);
            pAnimateSprite.Attach(Image.ImageName.Crab_Closed);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSprite, pAnimateSprite, initialDelta);

            pAnimateSprite = new AnimateSprite(Sprite.SpriteName.Squid);
            pAnimateSprite.Attach(Image.ImageName.Squid_Open);
            pAnimateSprite.Attach(Image.ImageName.Squid_Closed);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSprite, pAnimateSprite, initialDelta);

            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateGrid, new AnimateGrid(pAlienGrid, 7.0f), initialDelta);
            TimerEventMan.AddEvent(TimerEvent.EventName.PlayGridSound, new PlayAlienSounds(), 0.6f);

            TimerEventMan.AddEvent(TimerEvent.EventName.DeployUFO, new DeployUFO(), rand.Next(7, 30));

            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), 1.0f);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), 3.0f);


            // Update Collision references...
            CollisionPair pair = CollisionPairMan.FindPair(CollisionPair.CollideObjs.Grid_Wall);
            pair.treeA = pAlienGrid;

            pair = CollisionPairMan.FindPair(CollisionPair.CollideObjs.Missile_Alien);
            pair.treeB = pAlienGrid;

            pair = CollisionPairMan.FindPair(CollisionPair.CollideObjs.Alien_Shield);
            pair.treeA = pAlienGrid;
        }

        public void Reset()
        {
            // Set player managers active
            FontMan.SetActiveMan(this.poFontMan);
            ObjectNodeMan.SetActiveMan(this.poObjNodeMan);
            GhostMan.SetActiveMan(this.poGhostMan);
            SpriteBatchMan.SetActiveMan(this.poSpriteBatchMan);
            TimerEventMan.SetActiveMan(this.poTimerMan);
            CollisionPairMan.SetActiveMan(this.poCollisionMan);

            // Reset Score board (TODO: pull UI out)
            if (pContext.GetPlayMode())
            {
                Font pFont = FontMan.FindFont(Font.FontName.P1_Score);
                pFont.UpdateMessage("0000");

                pFont = FontMan.FindFont(Font.FontName.P2_Score);
                pFont.UpdateMessage("0000");

                pFont = FontMan.FindFont(Font.FontName.PlayerLife);
                pFont.UpdateMessage("3");

                pFont = FontMan.FindFont(Font.FontName.HighScore);
                pFont.UpdateMessage(pContext.GetHighScore().ToString("D4"));
            }
            else
            {
                Font pFont = FontMan.FindFont(Font.FontName.P1_Score);
                pFont.UpdateMessage("0000");

                pFont = FontMan.FindFont(Font.FontName.PlayerLife);
                pFont.UpdateMessage("3");

                pFont = FontMan.FindFont(Font.FontName.HighScore);
                pFont.UpdateMessage(pContext.GetHighScore().ToString("D4"));
            }

            // Clear previous resources
            ShieldGrid pShieldGrid = (ShieldGrid)ObjectNodeMan.FindObject(GameObject.ObjectName.ShieldGrids);
            ShieldFactory.GhostShields(pShieldGrid);

            AlienGrid pAlienGrid = (AlienGrid)ObjectNodeMan.FindObject(GameObject.ObjectName.AlienGrid);
            AlienFactory.GhostGrid(pAlienGrid);

            UFOAlienRoot pUfoRoot = (UFOAlienRoot)ObjectNodeMan.FindObject(GameObject.ObjectName.UFORoot);
            Debug.Assert(pUfoRoot != null);
            AlienFactory.GhostUFOs(pUfoRoot);

            ShipMan.GhostShips();

            TimerEventMan.DetachEvents();

            // Recreate resources
            ShipMan.ActivateShip();

            GameObject pShield = ShieldFactory.CreateShield(120.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);
            pShield = ShieldFactory.CreateShield(300.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);
            pShield = ShieldFactory.CreateShield(480.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);
            pShield = ShieldFactory.CreateShield(660.0f, 150.0f);
            pShieldGrid.AddComponent(pShield);

            pAlienGrid = (AlienGrid)AlienFactory.CreateGrid(110.0f, 750.0f);

            this.currDelta = initialDelta;
            AnimateSprite pAnimateSprite = new AnimateSprite(Sprite.SpriteName.Octopus);
            pAnimateSprite.Attach(Image.ImageName.Octopus_Open);
            pAnimateSprite.Attach(Image.ImageName.Octopus_Closed);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSprite, pAnimateSprite, initialDelta);

            pAnimateSprite = new AnimateSprite(Sprite.SpriteName.Crab);
            pAnimateSprite.Attach(Image.ImageName.Crab_Open);
            pAnimateSprite.Attach(Image.ImageName.Crab_Closed);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSprite, pAnimateSprite, initialDelta);

            pAnimateSprite = new AnimateSprite(Sprite.SpriteName.Squid);
            pAnimateSprite.Attach(Image.ImageName.Squid_Open);
            pAnimateSprite.Attach(Image.ImageName.Squid_Closed);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateSprite, pAnimateSprite, initialDelta);

            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateGrid, new AnimateGrid(pAlienGrid, 7.0f), initialDelta);
            TimerEventMan.AddEvent(TimerEvent.EventName.PlayGridSound, new PlayAlienSounds(), 0.6f);

            TimerEventMan.AddEvent(TimerEvent.EventName.DeployUFO, new DeployUFO(), rand.Next(7, 30));

            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), 1.0f);
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateBombDrop, new AnimateBombDrop(), 3.0f);


            // Update Collision references...
            CollisionPair pair = CollisionPairMan.FindPair(CollisionPair.CollideObjs.Grid_Wall);
            pair.treeA = pAlienGrid;

            pair = CollisionPairMan.FindPair(CollisionPair.CollideObjs.Missile_Alien);
            pair.treeB = pAlienGrid;

            pair = CollisionPairMan.FindPair(CollisionPair.CollideObjs.Alien_Shield);
            pair.treeA = pAlienGrid;
        }

        public void SetPlayer1(State_Play pPlay1)
        {
            this.nextState = pPlay1;
        }

        public float GetCurrDelta()
        {
            return this.currDelta;
        }

        public void SetCurrDelta(float newDelta)
        {
            this.currDelta = newDelta;
        }

    }   // end class
}   // end namespace