示例#1
0
        public override void Initialize()
        {
            this.poGameObjectManager = new GameObjectManager(3, 1);
            GameObjectManager.SetActive(this.poGameObjectManager);

            this.poTimerManager = new TimerManager(3, 1);
            TimerManager.SetActive(this.poTimerManager);

            this.poCollisionPairManager = new CollisionPairManager(3, 1);
            CollisionPairManager.SetActive(this.poCollisionPairManager);

            //---------------------------------------------------------------------------------------------------------
            // Create SpriteBatch
            //---------------------------------------------------------------------------------------------------------
            this.poSpriteBatchManager = new SpriteBatchManager(3, 1);
            SpriteBatchManager.SetActive(this.poSpriteBatchManager);

            SpriteBatch pAliensBatch  = SpriteBatchManager.Add(SpriteBatch.Name.Aliens, 1);
            SpriteBatch pBoxBatch     = SpriteBatchManager.Add(SpriteBatch.Name.Boxes, 2);
            SpriteBatch pShieldsBatch = SpriteBatchManager.Add(SpriteBatch.Name.Shields, 3);
            SpriteBatch pNullBatch    = SpriteBatchManager.Add(SpriteBatch.Name.NullObjects, 4);
            SpriteBatch pTexts        = SpriteBatchManager.Add(SpriteBatch.Name.Texts, 5);

            pBoxBatch.SetDrawBool(false);

            //---------------------------------------------------------------------------------------------------------
            // Input
            //---------------------------------------------------------------------------------------------------------
            this.poInputManager = new InputManager();
            InputManager.SetActive(this.poInputManager);

            InputSubject pInputSubject;

            pInputSubject = InputManager.GetArrowRightSubject();
            pInputSubject.Attach(new MoveRightObserver());

            pInputSubject = InputManager.GetArrowLeftSubject();
            pInputSubject.Attach(new MoveLeftObserver());

            pInputSubject = InputManager.GetSpaceSubject();
            pInputSubject.Attach(new ShootObserver());
            pInputSubject.Attach(new ShootSoundObserver());

            pInputSubject = InputManager.GetCKeySubject();
            pInputSubject.Attach(new ToggleCollisionBoxObserver());

            Simulation.SetState(Simulation.State.Realtime);
            //---------------------------------------------------------------------------------------------------------
            // Create Texts
            //---------------------------------------------------------------------------------------------------------

            this.poFontManager = new FontManager(3, 1);
            FontManager.SetActive(this.poFontManager);

            FontManager.Add(Font.Name.Header, SpriteBatch.Name.Texts, "SCORE<1>       HI-SCORE       SCORE<2>", 20f, SpaceInvaders.ScreenHeight - 20f, 15f, 25f);
            FontManager.Add(Font.Name.Player1Score, SpriteBatch.Name.Texts, "0000", 65f, SpaceInvaders.ScreenHeight - 70f, 15f, 25f);
            FontManager.Add(Font.Name.Player2Score, SpriteBatch.Name.Texts, "0000", SpaceInvaders.ScreenWidth - 156f, SpaceInvaders.ScreenHeight - 70f, 15f, 25f);
            FontManager.Add(Font.Name.HiScore, SpriteBatch.Name.Texts, "0000", 380f, SpaceInvaders.ScreenHeight - 70f, 15f, 25f);
            FontManager.Add(Font.Name.Lives, SpriteBatch.Name.Texts, "3", 40f, 40f, 15f, 25f);


            //---------------------------------------------------------------------------------------------------------
            // Create Walls
            //---------------------------------------------------------------------------------------------------------

            // Wall Root
            WallGroup pWallGroup = new WallGroup(GameObject.Name.WallGroup, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pWallGroup.ActivateGameSprite(pAliensBatch);//even need this?
            pWallGroup.ActivateCollisionSprite(pBoxBatch);

            WallRight pWallRight = new WallRight(GameObject.Name.WallRight, GameSprite.Name.NullObject, SpaceInvaders.ScreenWidth - 15, SpaceInvaders.ScreenHeight / 2, 20, SpaceInvaders.ScreenHeight - 110);

            pWallRight.ActivateCollisionSprite(pBoxBatch);

            WallLeft pWallLeft = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.NullObject, 20, SpaceInvaders.ScreenHeight / 2, 20, SpaceInvaders.ScreenHeight - 110);

            pWallLeft.ActivateCollisionSprite(pBoxBatch);

            WallTop pWallTop = new WallTop(GameObject.Name.WallTop, GameSprite.Name.NullObject, 450, SpaceInvaders.ScreenHeight - 70, SpaceInvaders.ScreenWidth - 10, 30);

            pWallTop.ActivateCollisionSprite(pBoxBatch);

            WallBottom pWallBottom = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.Ground, 450, 60, SpaceInvaders.ScreenWidth - 10, 5);

            pWallBottom.ActivateGameSprite(pAliensBatch);
            pWallBottom.ActivateCollisionSprite(pBoxBatch);

            // Add to the composite the children
            pWallGroup.Add(pWallRight);
            pWallGroup.Add(pWallLeft);
            pWallGroup.Add(pWallTop);
            pWallGroup.Add(pWallBottom);

            GameObjectManager.Attach(pWallGroup);

            //---------------------------------------------------------------------------------------------------------
            // Create Bomb Root
            //---------------------------------------------------------------------------------------------------------

            BombRoot pBombRoot = new BombRoot(GameObject.Name.BombRoot, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pBombRoot.ActivateGameSprite(pAliensBatch);//change? even need this?
            pBombRoot.ActivateCollisionSprite(pBoxBatch);

            GameObjectManager.Attach(pBombRoot);

            DropBombEvent pBombEvent = new DropBombEvent();

            TimerManager.Add(TimeEvent.Name.DropBomb, pBombEvent, 3.0f);

            //---------------------------------------------------------------------------------------------------------
            // Create Missile Root
            //---------------------------------------------------------------------------------------------------------

            // Missile Root
            MissileGroup pMissileGroup = new MissileGroup(GameObject.Name.MissileGroup, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pMissileGroup.ActivateGameSprite(pAliensBatch);//change? even need this?
            pMissileGroup.ActivateCollisionSprite(pBoxBatch);

            GameObjectManager.Attach(pMissileGroup);

            //---------------------------------------------------------------------------------------------------------
            // Create Ship Root
            //---------------------------------------------------------------------------------------------------------

            ShipRoot pShipRoot = new ShipRoot(GameObject.Name.ShipRoot, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pShipRoot.ActivateGameSprite(pAliensBatch);//change? even need this?
            pShipRoot.ActivateCollisionSprite(pBoxBatch);

            GameObjectManager.Attach(pShipRoot);

            ShipManager.ActivateShip();
            ShipManager.ActivateMissile();

            //---------------------------------------------------------------------------------------------------------
            // Create UFO and UFO Root
            //---------------------------------------------------------------------------------------------------------
            UFORoot pUFORoot = new UFORoot(GameObject.Name.UFORoot, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pUFORoot.ActivateGameSprite(pAliensBatch);//change? even need this?
            pUFORoot.ActivateCollisionSprite(pBoxBatch);

            GameObjectManager.Attach(pUFORoot);

            OrangeSaucer pUFO = new OrangeSaucer(GameObject.Name.OrangeSaucer, GameSprite.Name.OrangeSaucer, 20f, SpaceInvaders.ScreenHeight - 110f);

            pUFO.ActivateGameSprite(pAliensBatch);//change? even need this?
            pUFO.ActivateCollisionSprite(pBoxBatch);

            pUFORoot.Add(pUFO);
            pUFO.Remove();


            SpawnUFOEvent pUFOEvent = new SpawnUFOEvent();

            TimerManager.Add(TimeEvent.Name.UFOSpawn, pUFOEvent, RandomManager.RandomInt(15, 45));

            //---------------------------------------------------------------------------------------------------------
            // Create Aliens
            //---------------------------------------------------------------------------------------------------------

            AlienFactory AF         = new AlienFactory(SpriteBatch.Name.Aliens, SpriteBatch.Name.Boxes);
            AlienGrid    pAlienGrid = (AlienGrid)AF.Create(GameObject.Name.AlienGrid);


            for (int i = 0; i < 11; i++)
            {
                GameObject pCol = AF.Create(GameObject.Name.AlienColumn);
                GameObject pGameObject;
                pGameObject = AF.Create(GameObject.Name.PurpleOctopus, 50.0f + 66 * i, SpaceInvaders.ScreenHeight - 364f);
                pCol.Add(pGameObject);

                pGameObject = AF.Create(GameObject.Name.PurpleOctopus, 50.0f + 66 * i, SpaceInvaders.ScreenHeight - 298f);
                pCol.Add(pGameObject);

                pGameObject = AF.Create(GameObject.Name.BlueCrab, 50.0f + 66 * i, SpaceInvaders.ScreenHeight - 232f);
                pCol.Add(pGameObject);

                pGameObject = AF.Create(GameObject.Name.BlueCrab, 50.0f + 66 * i, SpaceInvaders.ScreenHeight - 166f);
                pCol.Add(pGameObject);

                pGameObject = AF.Create(GameObject.Name.GreenSquid, 50.0f + 66 * i, SpaceInvaders.ScreenHeight - 100f);
                pCol.Add(pGameObject);

                pAlienGrid.Add(pCol);
            }
            GameObjectManager.Attach(pAlienGrid);

            pAlienGrid.Attach(new MoveAlienSoundObserver());
            pAlienGrid.Attach(new MoveAlienGridObserver());

            AlienGridMoveEvent pGridMoveEvent = new AlienGridMoveEvent();

            TimerManager.Add(TimeEvent.Name.MoveAlienGrid, pGridMoveEvent, pAlienGrid.GetMoveRate());

            //---------------------------------------------------------------------------------------------------------
            // Timer Animations
            //---------------------------------------------------------------------------------------------------------

            // Create an animation sprite
            AnimationSprite pAnimOctopus = new AnimationSprite(GameSprite.Name.PurpleOctopus);
            AnimationSprite pAnimCrab    = new AnimationSprite(GameSprite.Name.BlueCrab);
            AnimationSprite pAnimSquid   = new AnimationSprite(GameSprite.Name.GreenSquid);

            // attach several images to cycle

            pAnimOctopus.Attach(Image.Name.OctopusA);
            pAnimOctopus.Attach(Image.Name.OctopusB);

            pAnimCrab.Attach(Image.Name.AlienA);
            pAnimCrab.Attach(Image.Name.AlienB);

            pAnimSquid.Attach(Image.Name.SquidA);
            pAnimSquid.Attach(Image.Name.SquidB);

            // add AnimationSprite to timer
            TimerManager.Add(TimeEvent.Name.SpriteAnimation, pAnimOctopus, pAlienGrid.GetMoveRate());
            TimerManager.Add(TimeEvent.Name.SpriteAnimation, pAnimCrab, pAlienGrid.GetMoveRate());
            TimerManager.Add(TimeEvent.Name.SpriteAnimation, pAnimSquid, pAlienGrid.GetMoveRate());

            //---------------------------------------------------------------------------------------------------------
            // Shield
            //---------------------------------------------------------------------------------------------------------

            // Create the factory
            Composite pShieldRoot = (Composite) new ShieldRoot(GameObject.Name.ShieldRoot, GameSprite.Name.NullObject, 0.0f, 0.0f);

            GameObjectManager.Attach(pShieldRoot);
            ShieldFactory SF = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Boxes, pShieldRoot);

            float start_x = 160.0f;
            float start_y = 200.0f;
            float off_x;
            float brickWidth  = 12.0f;
            float brickHeight = 7.0f;

            GameObject pShieldGrid;
            GameObject pShieldCol;

            for (int i = 0; i < 4; i++)
            {
                off_x = 0;
                SF.SetParent(pShieldRoot);
                pShieldGrid = SF.Create(GameObject.Name.ShieldGrid);

                //------Col1
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + 2 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick_LeftTop1, start_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick_LeftTop0, start_x, start_y + 9 * brickHeight);

                //-------Col2
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                off_x += brickWidth;
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

                //-------Col3
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                off_x += brickWidth;
                SF.Create(GameObject.Name.ShieldBrick_LeftBottom, start_x + off_x, start_y + 2 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

                //-------Col4
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                off_x += brickWidth;
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

                //-------Col5
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                off_x += brickWidth;
                SF.Create(GameObject.Name.ShieldBrick_RightBottom, start_x + off_x, start_y + 2 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

                //-------Col6
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                off_x += brickWidth;
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 0 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 1 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

                //-------Col7
                SF.SetParent(pShieldGrid);
                pShieldCol = SF.Create(GameObject.Name.ShieldColumn);
                SF.SetParent(pShieldCol);

                off_x += brickWidth;
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 0 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 1 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 3 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 4 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 5 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 6 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick, start_x + off_x, start_y + 7 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick_RightTop1, start_x + off_x, start_y + 8 * brickHeight);
                SF.Create(GameObject.Name.ShieldBrick_RightTop0, start_x + off_x, start_y + 9 * brickHeight);

                start_x += 170;
            }


            //---------------------------------------------------------------------------------------------------------
            // Create Null Ship Lives
            //---------------------------------------------------------------------------------------------------------

            ScenePlay.ShipLives = 3;

            PlayerLivesComposite pNullObjs = new PlayerLivesComposite();

            Ship pNullShip1 = new Ship(GameObject.Name.Null_Object, GameSprite.Name.Ship, 120.0f, 40.0f);

            pNullShip1.ActivateGameSprite(pNullBatch);
            pNullObjs.Add(pNullShip1);

            Ship pNullShip2 = new Ship(GameObject.Name.Null_Object, GameSprite.Name.Ship, 180.0f, 40.0f);

            pNullShip2.ActivateGameSprite(pNullBatch);
            pNullObjs.Add(pNullShip2);

            GameObjectManager.Attach(pNullObjs);

            //---------------------------------------------------------------------------------------------------------
            // Create CollisionPairs
            //---------------------------------------------------------------------------------------------------------

            //Why does the order that left/right wall are added matter??????? reverse order breaks game
            CollisionPair pShipWallRightPair = CollisionPairManager.Add(CollisionPair.Name.Ship_Wall_Right, pShipRoot, pWallRight);

            Debug.Assert(pShipWallRightPair != null);

            CollisionPair pShipWallLeftPair = CollisionPairManager.Add(CollisionPair.Name.Ship_Wall_Left, pShipRoot, pWallLeft);

            Debug.Assert(pShipWallLeftPair != null);

            CollisionPair pAlienMissilePair = CollisionPairManager.Add(CollisionPair.Name.Alien_Missile, pMissileGroup, pAlienGrid);

            Debug.Assert(pAlienMissilePair != null);

            CollisionPair pMissileWallPair = CollisionPairManager.Add(CollisionPair.Name.Missile_Wall_Top, pMissileGroup, pWallTop);

            Debug.Assert(pMissileWallPair != null);

            CollisionPair pAlienWallPair = CollisionPairManager.Add(CollisionPair.Name.Alien_Wall, pAlienGrid, pWallGroup);

            Debug.Assert(pAlienWallPair != null);

            CollisionPair pAlienWallBottomPair = CollisionPairManager.Add(CollisionPair.Name.Alien_WallBottom, pAlienGrid, pWallBottom);

            Debug.Assert(pAlienWallBottomPair != null);

            CollisionPair pBombWallPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Wall_Bottom, pBombRoot, pWallBottom);

            Debug.Assert(pBombWallPair != null);

            CollisionPair pBombShieldPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Shield, pBombRoot, pShieldRoot);

            Debug.Assert(pBombShieldPair != null);

            CollisionPair pMissileShieldPair = CollisionPairManager.Add(CollisionPair.Name.Missile_Shield, pMissileGroup, pShieldRoot);

            Debug.Assert(pMissileShieldPair != null);

            CollisionPair pBombShipPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Ship, pBombRoot, ShipManager.GetShip());

            Debug.Assert(pBombShipPair != null);

            CollisionPair pBombMissilePair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Missile, pBombRoot, ShipManager.GetMissile());

            Debug.Assert(pBombMissilePair != null);

            CollisionPair pAlienShieldPair = CollisionPairManager.Add(CollisionPair.Name.Alien_Shield, pShieldRoot, pAlienGrid);

            Debug.Assert(pAlienShieldPair != null);

            CollisionPair pUFOMissilePair = CollisionPairManager.Add(CollisionPair.Name.UFO_Missile, pMissileGroup, pUFORoot);

            Debug.Assert(pUFOMissilePair != null);

            //TODO consolidate these news
            pShipWallLeftPair.Attach(new ShipStopLeftObserver());
            pShipWallRightPair.Attach(new ShipStopRightObserver());

            pMissileWallPair.Attach(new ShipRemoveMissileObserver());

            pAlienMissilePair.Attach(new ShipRemoveMissileObserver());
            pAlienMissilePair.Attach(new RemoveAlienObserver());
            pAlienMissilePair.Attach(new DeadAlienSoundObserver());
            pAlienMissilePair.Attach(new AddP1PointsObserver());
            pAlienMissilePair.Attach(new IncreaseAlienSpeedObserver());

            pAlienWallPair.Attach(new GridObserver());

            pBombWallPair.Attach(new RemoveBombObserver());

            pBombShieldPair.Attach(new RemoveBombObserver());
            pBombShieldPair.Attach(new RemoveBrickObserver());

            pMissileShieldPair.Attach(new ShipRemoveMissileObserver());
            pMissileShieldPair.Attach(new RemoveBrickObserver());

            pBombShipPair.Attach(new RemoveBombObserver());
            pBombShipPair.Attach(new RemoveShipObserver());
            pBombShipPair.Attach(new DeadShipSoundObserver());
            pBombShipPair.Attach(new RemoveLifeObserver());
            pBombShipPair.Attach(new ChangeStateObserver());

            pBombMissilePair.Attach(new RemoveBombObserver());
            pBombMissilePair.Attach(new ShipRemoveMissileObserverAltPair());

            pAlienShieldPair.Attach(new RemoveBrickObserver());

            pUFOMissilePair.Attach(new RemoveUFOObserver());
            pUFOMissilePair.Attach(new ShipRemoveMissileObserver());
            pUFOMissilePair.Attach(new AddP1PointsObserver());
            pUFOMissilePair.Attach(new DeadUFOSoundObserver());

            pAlienWallBottomPair.Attach(new DeadShipSoundObserver());
            pAlienWallBottomPair.Attach(new RemoveAllP1LivesObserver());
        }
        //-----------------------------------------------------------------------------
        // Game::LoadContent()
        //		Allows you to load all content needed for your engine,
        //	    such as objects, graphics, etc.
        //-----------------------------------------------------------------------------
        public override void LoadContent()
        {
            // Set to current state for initialization
            GameStateManager.GetGame().SetGameState(GameStateManager.GameState.Player1);

            //---------------------------------------------------------------------------------------------------------
            // Initialize State-Scoped Managers
            //---------------------------------------------------------------------------------------------------------

            this.pSpriteBatchManager     = new SpriteBatchManager(3, 1);
            this.pGameObjectManager      = new GameObjectManager(300, 10);
            this.pDelayedObjectManager   = new DelayedObjectManager();
            this.pQueuedTimeEventManager = new QueuedTimeEventManager(50, 5);
            this.pGhostManager           = new GhostManager(50, 5);
            this.pCompositeManager       = new CompositeManager(20, 2);


            //---------------------------------------------------------------------------------------------------------
            // Create Colors
            //---------------------------------------------------------------------------------------------------------

            pGreenColor = new Azul.Color(0.1137f, 0.8196f, 0.2667f, 1.0f);

            //---------------------------------------------------------------------------------------------------------
            // Create SpriteBatches
            //---------------------------------------------------------------------------------------------------------
            pCollisionBox_SpriteBatch = this.pSpriteBatchManager.Add(SpriteBatch.Name.CollisionBox);
            pCollisionBox_SpriteBatch.SetDraw(false);

            pWall_SpriteBatch         = this.pSpriteBatchManager.Add(SpriteBatch.Name.Wall);
            pAlien_SpriteBatch        = this.pSpriteBatchManager.Add(SpriteBatch.Name.Alien);
            pCoreCannon_SpriteBatch   = this.pSpriteBatchManager.Add(SpriteBatch.Name.CoreCannon);
            pMissile_SpriteBatch      = this.pSpriteBatchManager.Add(SpriteBatch.Name.Missile);
            pBomb_SpriteBatch         = this.pSpriteBatchManager.Add(SpriteBatch.Name.Bomb);
            pShield_SpriteBatch       = this.pSpriteBatchManager.Add(SpriteBatch.Name.Shield);
            pFlyingSaucer_SpriteBatch = this.pSpriteBatchManager.Add(SpriteBatch.Name.FlyingSaucer);
            pTexts_SpriteBatch        = this.pSpriteBatchManager.Add(SpriteBatch.Name.Player1Texts);

            //---------------------------------------------------------------------------------------------------------
            // Flying Saucer
            //---------------------------------------------------------------------------------------------------------

            FlyingSaucerRoot pFlyingSaucerRoot = new FlyingSaucerRoot(Composite.CompositeName.FlyingSaucerRoot, 0.0f, 0.0f);

            pFlyingSaucerRoot.ActivateSprite(pFlyingSaucer_SpriteBatch);
            pFlyingSaucerRoot.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            this.pGameObjectManager.Attach(pFlyingSaucerRoot);
            this.pCompositeManager.Attach(pFlyingSaucerRoot);

            DeployFlyingSaucerCommand pDeployFlyingSaucer = new DeployFlyingSaucerCommand();

            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.DeployFlyingSaucer, pDeployFlyingSaucer, r.Next(30, 46));

            //---------------------------------------------------------------------------------------------------------
            // Core Cannon
            //---------------------------------------------------------------------------------------------------------

            CoreCannonGroup pCoreCannonGroup = new CoreCannonGroup(Composite.CompositeName.CoreCannonGroup, 0.0f, 0.0f);

            this.pGameObjectManager.Attach(pCoreCannonGroup);
            this.pCompositeManager.Attach(pCoreCannonGroup);
            this.pCoreCannonManager = new CoreCannonManager();
            this.pCoreCannonManager.ActivateCoreCannon();

            //---------------------------------------------------------------------------------------------------------
            // Sprite Animations
            //---------------------------------------------------------------------------------------------------------

            // Squid Alien
            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.SpriteAnimation, SpriteAnimationManager.Find(SpriteAnimation.Name.SquidAlien), 0.8f);

            // Crab Alien
            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.SpriteAnimation, SpriteAnimationManager.Find(SpriteAnimation.Name.CrabAlien), 0.8f);

            // JellyFish Alien
            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.SpriteAnimation, SpriteAnimationManager.Find(SpriteAnimation.Name.JellyfishAlien), 0.8f);

            //---------------------------------------------------------------------------------------------------------
            // Bomb
            //---------------------------------------------------------------------------------------------------------

            BombRoot pBombRoot = new BombRoot(Composite.CompositeName.BombRoot, 0.0f, 0.0f);

            pBombRoot.ActivateSprite(pBomb_SpriteBatch);
            //pBombRoot.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            this.pCompositeManager.Attach(pBombRoot);
            this.pGameObjectManager.Attach(pBombRoot);

            // Add initial drop bomb events
            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.DropBomb, new DropBombCommand(), 1.0f);
            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.DropBomb, new DropBombCommand(), 3.0f);

            //---------------------------------------------------------------------------------------------------------
            // Missile
            //---------------------------------------------------------------------------------------------------------

            MissileGroup pMissileGroup = new MissileGroup(Composite.CompositeName.MissileGroup, 0.0f, 0.0f);

            pMissileGroup.ActivateSprite(pMissile_SpriteBatch);
            pMissileGroup.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            this.pGameObjectManager.Attach(pMissileGroup);
            this.pCompositeManager.Attach(pMissileGroup);

            //---------------------------------------------------------------------------------------------------------
            // Create Walls
            //---------------------------------------------------------------------------------------------------------

            // Wall Root
            pWallGroup = new WallGroup(GameObject.Name.ShieldGroup, Sprite.Name.NullSprite, 0.0f, 0.0f);
            pWallGroup.ActivateSprite(pWall_SpriteBatch);
            pWallGroup.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            LeftWall pLeftWall = new LeftWall(GameObject.Name.LeftWall, Sprite.Name.NullSprite, 20, 425, 15, 800);

            pLeftWall.ActivateSprite(pWall_SpriteBatch);
            pLeftWall.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            RightWall pRightWall = new RightWall(GameObject.Name.RightWall, Sprite.Name.NullSprite, 875, 425, 15, 800);

            pRightWall.ActivateSprite(pWall_SpriteBatch);
            pRightWall.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            TopWall pTopWall = new TopWall(GameObject.Name.TopWall, Sprite.Name.NullSprite, 450, 825, 870, 15);

            pTopWall.ActivateSprite(pWall_SpriteBatch);
            pTopWall.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            BottomWall pBottomWall = new BottomWall(GameObject.Name.BottomWall, Sprite.Name.NullSprite, 450, 55, 870, 15);

            pBottomWall.ActivateSprite(pWall_SpriteBatch);
            pBottomWall.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            LeftBumper pLeftBumper = new LeftBumper(GameObject.Name.LeftBumper, Sprite.Name.NullSprite, 45, 100, 30, 50);

            pLeftBumper.ActivateSprite(pWall_SpriteBatch);
            pLeftBumper.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            RightBumper pRightBumper = new RightBumper(GameObject.Name.RightBumper, Sprite.Name.NullSprite, 850, 100, 30, 50);

            pRightBumper.ActivateSprite(pWall_SpriteBatch);
            pRightBumper.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            pWallGroup.Add(pLeftWall);
            pWallGroup.Add(pRightWall);
            pWallGroup.Add(pTopWall);
            pWallGroup.Add(pBottomWall);
            pWallGroup.Add(pLeftBumper);
            pWallGroup.Add(pRightBumper);

            this.pCompositeManager.Attach(pWallGroup);
            this.pGameObjectManager.Attach(pWallGroup);
            this.pGameObjectManager.Attach(pLeftWall);
            this.pGameObjectManager.Attach(pRightWall);
            this.pGameObjectManager.Attach(pTopWall);
            this.pGameObjectManager.Attach(pBottomWall);
            this.pGameObjectManager.Attach(pLeftBumper);
            this.pGameObjectManager.Attach(pRightBumper);

            //---------------------------------------------------------------------------------------------------------
            // Shield
            //---------------------------------------------------------------------------------------------------------

            //Shield Root
            ShieldGroup pShieldGroup = new ShieldGroup(Composite.CompositeName.ShieldGroup, 0.0f, 0.0f);

            pShieldGroup.ActivateSprite(pShield_SpriteBatch);
            pShieldGroup.ActivateCollisionSprite(pCollisionBox_SpriteBatch);

            GameObject pShield;

            pShield = ShieldFactory.CreateShield(110, 150);
            pShieldGroup.Add(pShield);
            pShield = ShieldFactory.CreateShield(310, 150);
            pShieldGroup.Add(pShield);
            pShield = ShieldFactory.CreateShield(510, 150);
            pShieldGroup.Add(pShield);
            pShield = ShieldFactory.CreateShield(710, 150);
            pShieldGroup.Add(pShield);

            this.pGameObjectManager.Attach(pShieldGroup);
            this.pCompositeManager.Attach(pShieldGroup);


            //---------------------------------------------------------------------------------------------------------
            // Create Alien Grid Composite
            //---------------------------------------------------------------------------------------------------------

            this.levelInitialAlienGridSpeed = SpaceInvadersGameState.gameInitialAlienGridSpeed;
            this.currAlienGridSpeed         = SpaceInvadersGameState.gameInitialAlienGridSpeed;

            this.currLevelInitialAlienGridY = SpaceInvadersGameState.gameInitialAlienGridY;

            pAlienGrid = (Composite)AlienFactory.CreateAlienGrid(SpaceInvadersGameState.gameInitialAlienGridX, currLevelInitialAlienGridY);

            // Add Initial AlienGridMovementSound Event
            AlienGridMovementSound pAlienGridMovementSound = new AlienGridMovementSound();

            this.pQueuedTimeEventManager.Enqueue(TimeEvent.Name.AlienGridMovementSound, pAlienGridMovementSound, levelInitialAlienGridSpeed);

            //---------------------------------------------------------------------------------------------------------
            // Associate Collision Pairs
            //---------------------------------------------------------------------------------------------------------

            // Alien vs Missile
            CollisionPair pAlienMissileColPair = CollisionPairManager.Add(CollisionPair.Name.Alien_Missile, pAlienGrid, pMissileGroup);

            Debug.Assert(pAlienMissileColPair != null);
            pAlienMissileColPair.Attach(new ShipReadyObserver());
            pAlienMissileColPair.Attach(new RemoveMissileObserver());
            pAlienMissileColPair.Attach(new RemoveAlienObserver());
            pAlienMissileColPair.Attach(new AddPlayerPointsObserver(Player.Name.Player1));
            pAlienMissileColPair.Attach(new InvaderKilledSoundObserver());

            // FlyingSaucer vs Missile
            CollisionPair pFlyingSaucerMissileColPair = CollisionPairManager.Add(CollisionPair.Name.FlyingSaucer_Missile, pFlyingSaucerRoot, pMissileGroup);

            Debug.Assert(pFlyingSaucerMissileColPair != null);
            pFlyingSaucerMissileColPair.Attach(new ShipReadyObserver());
            pFlyingSaucerMissileColPair.Attach(new RemoveMissileObserver());
            pFlyingSaucerMissileColPair.Attach(new RemoveFlyingSaucerObserver());
            pFlyingSaucerMissileColPair.Attach(new ExplosionSoundObserver());

            // FlyingSaucer vs Wall
            CollisionPair pFlyingSaucerWallColPair = CollisionPairManager.Add(CollisionPair.Name.FlyingSaucer_Wall, pFlyingSaucerRoot, pWallGroup);

            Debug.Assert(pFlyingSaucerWallColPair != null);
            pFlyingSaucerWallColPair.Attach(new RemoveFlyingSaucerObserver());

            // Alien vs Wall
            CollisionPair pAlienWallColPair = CollisionPairManager.Add(CollisionPair.Name.Alien_Wall, pAlienGrid, pWallGroup);

            Debug.Assert(pAlienWallColPair != null);
            pAlienWallColPair.Attach(new GridWallCollisionObserver());

            // Alien vs Shield
            CollisionPair pAlienShieldColPair = CollisionPairManager.Add(CollisionPair.Name.Alien_Shield, pAlienGrid, pShieldGroup);

            Debug.Assert(pAlienShieldColPair != null);
            pAlienShieldColPair.Attach(new RemoveShieldBrickObserver());

            // Missile vs Wall
            CollisionPair pMissileWallColPair = CollisionPairManager.Add(CollisionPair.Name.Missile_Wall, pMissileGroup, pWallGroup);

            Debug.Assert(pMissileWallColPair != null);
            pMissileWallColPair.Attach(new ShipReadyObserver());
            pMissileWallColPair.Attach(new RemoveMissileObserver());

            // Missile vs Shield
            CollisionPair pMissileShieldColPair = CollisionPairManager.Add(CollisionPair.Name.Missile_Shield, pMissileGroup, pShieldGroup);

            Debug.Assert(pMissileShieldColPair != null);
            pMissileShieldColPair.Attach(new ShipReadyObserver());
            pMissileShieldColPair.Attach(new RemoveMissileObserver());
            pMissileShieldColPair.Attach(new RemoveShieldBrickObserver());

            // Bomb vs Shield
            CollisionPair pBombShieldColPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Shield, pBombRoot, pShieldGroup);

            Debug.Assert(pBombShieldColPair != null);
            pBombShieldColPair.Attach(new RemoveBombObserver());
            pBombShieldColPair.Attach(new RemoveShieldBrickObserver());

            // Bomb vs Wall
            CollisionPair pBombWallColPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Wall, pBombRoot, pWallGroup);

            Debug.Assert(pBombWallColPair != null);
            pBombWallColPair.Attach(new RemoveBombObserver());

            // CoreCannon vs Bumpers
            CollisionPair pCoreCannonWallColPair = CollisionPairManager.Add(CollisionPair.Name.CoreCannon_Wall, pCoreCannonGroup, pWallGroup);

            Debug.Assert(pCoreCannonWallColPair != null);
            pCoreCannonWallColPair.Attach(new CoreCannonBumperCollisionObserver());

            // Bomb vs Missile
            CollisionPair pBombMissileColPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Missile, pBombRoot, pMissileGroup);

            Debug.Assert(pBombMissileColPair != null);
            pBombMissileColPair.Attach(new ShipReadyObserver());
            pBombMissileColPair.Attach(new RemoveBombObserver());
            pBombMissileColPair.Attach(new RemoveMissileObserver());

            // Bomb vs CoreCannon
            CollisionPair pBombShipColPair = CollisionPairManager.Add(CollisionPair.Name.Bomb_Ship, pBombRoot, pCoreCannonGroup);

            Debug.Assert(pBombShipColPair != null);
            pBombShipColPair.Attach(new PlayerDeathObserver(Player.Name.Player1));
            pBombShipColPair.Attach(new RemoveBombObserver());
            pBombShipColPair.Attach(new ExplosionSoundObserver());

            //---------------------------------------------------------------------------------------------------------
            // Fonts
            //---------------------------------------------------------------------------------------------------------
            FontManager.Add(Font.Name.Player1Lives, pTexts_SpriteBatch, "LIVES " + GameStateManager.GetGame().GetPlayer(Player.Name.Player1).GetNumLives().ToString(), Glyph.Name.Consolas36pt, 50, 50);
        }