Esempio n. 1
0
        public override void VisitWallRight(WallRight r)
        {
            ColPair pColPair = ColPairMan.GetActiveColPair();

            pColPair.SetCollision(r, this);
            pColPair.NotifyListeners();
        }
Esempio n. 2
0
        public WallManager()
        {
            WallFactory gameSpaceFactory = new WallFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes);

            this.pGameSpace = (GameSpace)gameSpaceFactory.Create(GameObject.Type.GameSpace, 0, 0, 0, 0);
            Debug.Assert(this.pGameSpace != null);

            WallFactory wallFactory = new WallFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, this.pGameSpace);

            this.pWallLeft = (WallLeft)wallFactory.Create(GameObject.Type.WallLeft, Constants.leftWallXPos, Constants.leftWallYPos,
                                                          Constants.leftWallWidth, Constants.leftWallHeight);
            Debug.Assert(this.pWallLeft != null);

            this.pWallRight = (WallRight)wallFactory.Create(GameObject.Type.WallRight, Constants.rightWallXPos, Constants.rightWallYPos,
                                                            Constants.rightWallWidth, Constants.rightWallHeight);
            Debug.Assert(this.pWallRight != null);

            this.pCeiling = (Ceiling)wallFactory.Create(GameObject.Type.Ceiling, Constants.ceilingXPos, Constants.ceilingYPos,
                                                        Constants.ceilingWidth, Constants.ceilingHeight);
            Debug.Assert(this.pCeiling != null);

            this.pFloor = (Floor)wallFactory.Create(GameObject.Type.Floor, Constants.floorXPos, Constants.floorYPos,
                                                    Constants.floorWidth, Constants.floorHeight);
            Debug.Assert(this.pFloor != null);
        }
Esempio n. 3
0
        public override void VisitWallRight(WallRight wr)
        {
            CollisionPair pColPair = CollisionPairManager.GetCurrentCollisionPair();

            pColPair.SetObserverSubject(this, wr);
            pColPair.NotifyListeners();
        }
Esempio n. 4
0
        public override void VisitRightWall(WallRight r)
        {
            // AliensGrid vs Missile
            Debug.WriteLine("         collide:  {0} <-> {1}", r.GetName(), this.GetName());

            // AliensCol vs Missile
            Nums.AliensSpeedX = -2.0f;
        }
Esempio n. 5
0
        public override void VisitWallRight(WallRight pWallRight)
        {
            //Debug.WriteLine("   --->DONE<----");
            ColPair pColPair = ColPairManager.GetActiveColPair();

            Debug.Assert(pColPair != null);
            pColPair.SetCollision(pWallRight, this);
            pColPair.NotifyListeners();
        }
        public override void VisitWallRight(WallRight w)
        {
            Debug.WriteLine("CannonShip WallRight");
            CollisionPair currColPair = CollisionPairManager.getCurrentColPair();

            Debug.Assert(currColPair != null);
            currColPair.setSubject(this, w);
            currColPair.notifyObserver();
        }
Esempio n. 7
0
        public override void VisitWallRight(WallRight w)
        {
            Debug.WriteLine("AlienUFO WallRight");
            Debug.WriteLine("Both tress finished to roots");

            CollisionPair colpair = CollisionPairManager.getCurrentColPair();

            colpair.setSubject(this, w);
            colpair.notifyObserver();
        }
Esempio n. 8
0
        public override void visitWallRight(WallRight wallRight)
        {
            // WallRight vs UFO
            CollisionPair pColPair = CollisionPairMan.GetActiveColPair();

            Debug.Assert(pColPair != null);

            pColPair.setCollision(wallRight, this);
            pColPair.notifyListeners();
        }
Esempio n. 9
0
        //----------------------------------------------------------------------------------
        // Methods
        //----------------------------------------------------------------------------------

        public GameObject Create(GameObject.Name theName, WallCategory.Type type)
        {
            GameObject pGameObj = null;

            switch (type)
            {
            case WallCategory.Type.WallGroup:
                pGameObj = new WallGroup(theName, GameSprite.Name.NullObject, 0.0f, 0.0f);
                pGameObj.ActivateGameSprite(this.pSpriteBatch);
                pGameObj.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;


            case WallCategory.Type.Left:
                pGameObj = new WallLeft(theName, GameSprite.Name.NullObject, 30.0f, 500.0f, 35.0f, 1000.0f);
                pGameObj.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;

            case WallCategory.Type.Right:
                pGameObj = new WallRight(theName, GameSprite.Name.NullObject, 870.0f, 500.0f, 35.0f, 1000.0f);
                pGameObj.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;

            case WallCategory.Type.Top:
                pGameObj = new WallTop(theName, GameSprite.Name.NullObject, 448, 950, 890, 50);
                pGameObj.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;

            case WallCategory.Type.Bottom:
                pGameObj = new WallBottom(theName, GameSprite.Name.Wall, 448, 80, 890, 10);
                pGameObj.ActivateGameSprite(this.pSpriteBatch);
                pGameObj.ActivateCollisionSprite(this.pCollisionSpriteBatch);
                break;

            default:
                Debug.WriteLine("Choose the Wall you want by name.");
                Debug.Assert(false);
                break;
            }

            // add it to the Game Object Manager
            Debug.Assert(pGameObj != null);

            // Should only attach root elements to the GameObjectManager in the Scene

            // attach to the group in the switch statments because not all of them attach the same


            return(pGameObj);
        }
Esempio n. 10
0
        public SpawnUFOCommand(Random pRandom, WallLeft pWallLeft, WallRight pWallRight)
        {
            this.pUFO = GameObjectMan.Find(GameObject.Name.UFO);
            Debug.Assert(this.pUFO != null);

            this.pSB_Aliens = SpriteBatchMan.Find(SpriteBatch.Name.Aliens);
            Debug.Assert(this.pSB_Aliens != null);

            this.pSB_Boxes = SpriteBatchMan.Find(SpriteBatch.Name.Boxes);
            Debug.Assert(this.pSB_Boxes != null);

            this.pRandom    = pRandom;
            this.pWallLeft  = pWallLeft;
            this.pWallRight = pWallRight;
        }
Esempio n. 11
0
        public GameObject Create(GameObject.Type type, float posX, float posY, float width, float height)
        {
            GameObject pGameObj = null;

            switch (type)
            {
            case GameObject.Type.GameSpace:
                pGameObj = new GameSpace(GameObject.Name.GameSpace, BoxSprite.Name.GameSpaceBox);
                break;

            case GameObject.Type.WallRight:
                pGameObj = new WallRight(GameObject.Name.WallRight, Sprite.Name.NullObject, BoxSprite.Name.WallBox, posX, posY, width, height);
                break;

            case GameObject.Type.WallLeft:
                pGameObj = new WallLeft(GameObject.Name.WallLeft, Sprite.Name.NullObject, BoxSprite.Name.WallBox, posX, posY, width, height);
                break;

            case GameObject.Type.Ceiling:
                pGameObj = new Ceiling(GameObject.Name.Ceiling, Sprite.Name.NullObject, BoxSprite.Name.WallBox, posX, posY, width, height);
                break;

            case GameObject.Type.Floor:
                pGameObj = new Floor(GameObject.Name.Floor, Sprite.Name.NullObject, BoxSprite.Name.WallBox, posX, posY, width, height);
                break;

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

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

            if (pGOComposite != null)
            {
                // add to grid
                pGOComposite.Add(pGameObj);
            }

            // Attached to Batches
            this.pBoxSpriteBatch.Attach(pGameObj.poColObj.pColSprite);
            this.pSpriteBatch.Attach(pGameObj.pProxySprite);
            return(pGameObj);
        }
Esempio n. 12
0
        public GameObject Create(GameObject.Name name, WallCategory.Type type, float posX = 0.0f, float posY = 0.0f, float width = 0, float height = 0)
        {
            GameObject pGameObj = null;

            switch (type)
            {
            case WallCategory.Type.Wall_Left:
                pGameObj = new WallLeft(GameSprite.Name.Sprite_NullObject, name, posX, posY, width, height);
                break;

            case WallCategory.Type.Wall_Right:
                pGameObj = new WallRight(GameSprite.Name.Sprite_NullObject, name, posX, posY, width, height);
                break;

            case WallCategory.Type.Wall_Top:
                pGameObj = new WallTop(GameSprite.Name.Sprite_NullObject, name, posX, posY, width, height);
                break;

            case WallCategory.Type.Wall_Bottom:
                pGameObj = new WallBottom(GameSprite.Name.Sprite_NullObject, name, posX, posY, width, height);
                break;

            case WallCategory.Type.Wall_Grid:
                pGameObj = new WallGrid(name);
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }

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

            // Attached to Group
            //pGameObj.ActivateGameSprite(this.pSpriteBatch);
            pGameObj.ActivateCollisionSprite(this.pBoxBatch);

            return(pGameObj);
        }
        //~WallFactory()
        //{
        //    this.pSpriteBatch = null;
        //}

        public GameObject Create(WallCategory.Type type, GameObject.Name gameName, float posX = 0.0f, float posY = 0.0f, float width = 0.0f, float height = 0.0f)
        {
            GameObject pWall = null;

            switch (type)
            {
            case WallCategory.Type.Bottom:
                pWall = new WallBottom(gameName, GameSprite.Name.WallHorizontal, posX, posY, width, height);
                break;

            case WallCategory.Type.Top:
                pWall = new WallTop(gameName, GameSprite.Name.WallHorizontal, posX, posY, width, height);
                break;

            case WallCategory.Type.Left:
                pWall = new WallLeft(gameName, GameSprite.Name.WallVertical, posX, posY, width, height);
                break;

            case WallCategory.Type.Right:
                pWall = new WallRight(gameName, GameSprite.Name.WallVertical, posX, posY, width, height);
                break;

            case WallCategory.Type.WallGroup:
                pWall = new WallGroup(gameName, GameSprite.Name.NullObject, posX, posY);
                break;

            default:
                // something is wrong
                Debug.Assert(false);
                break;
            }

            // add to the tree
            this.pTree.Add(pWall);

            // Attached to Group
            pWall.ActivateGameSprite(this.pSpriteBatch);
            pWall.ActivateCollisionSprite(this.pCollisionSpriteBatch);

            return(pWall);
        }
Esempio n. 14
0
        public Wall createWall(Wall.WallType mWallType, GameObject.GameObjectName gameName, int index = 0, float x = 0.0f, float y = 0.0f, float width = 0.0f, float height = 0.0f)
        {
            Wall wall = null;

            switch (mWallType)
            {
            case Wall.WallType.WallTop:
                wall = new WallTop(gameName, index, Sprite.SpriteName.NullObject, x, y, width, height, Wall.WallType.WallTop);
                break;

            case Wall.WallType.WallDown:
                wall = new WallDown(gameName, index, Sprite.SpriteName.NullObject, x, y, width, height, Wall.WallType.WallDown);
                break;

            case Wall.WallType.WallLeft:
                wall = new WallLeft(gameName, index, Sprite.SpriteName.NullObject, x, y, width, height, Wall.WallType.WallLeft);
                break;

            case Wall.WallType.WallRight:
                wall = new WallRight(gameName, index, Sprite.SpriteName.NullObject, x, y, width, height, Wall.WallType.WallRight);
                break;

            case Wall.WallType.WallRoot:
                wall = new WallRoot(gameName, index, Sprite.SpriteName.NullObject, Wall.WallType.WallRoot);
                GameObjectNodeManager.add(wall, cPCSTree);
                break;

            case Wall.WallType.Uninitilized:
                Debug.WriteLine("Wall Type is Uninitilized");
                break;
            }

            this.cPCSTree.Insert(wall, this.cParent);

            wall.addSpriteToBatch(this.cSpriteBatch);
            wall.addCollisionToBatch(SpriteBatchManager.find(SpriteBatch.SpriteBatchName.Boxes));
            return(wall);
        }
Esempio n. 15
0
        //-------------------------------------------------------------------------------
        // Method
        //-------------------------------------------------------------------------------
        public GameObject create(GameObject.Name objectName, WallCategory.Type wallType, float posX = 0.0f, float posY = 0.0f, float width = 0.0f, float height = 0.0f)
        {
            GameObject pGameObject = null;

            switch (wallType)
            {
            case WallCategory.Type.WallGroup:
                pGameObject = new WallGroup(GameObject.Name.WallGroup, GameSprite.Name.NullObject, 0.0f, 0.0f);
                break;

            case WallCategory.Type.Left:
                pGameObject = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.NullObject, posX, posY, width, height);
                break;

            case WallCategory.Type.Right:
                pGameObject = new WallRight(GameObject.Name.WallRight, GameSprite.Name.NullObject, posX, posY, width, height);
                break;

            case WallCategory.Type.Top:
                pGameObject = new WallTop(GameObject.Name.WallTop, GameSprite.Name.NullObject, posX, posY, width, height);
                break;

            case WallCategory.Type.Bottom:
                pGameObject = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.NullObject, posX, posY, width, height);
                break;

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

            Debug.Assert(pGameObject != null);

            pGameObject.activateGameSprite(this.pSpriteBatch);
            pGameObject.activateCollisionSprite(this.pBoxSpriteBatch);

            return(pGameObject);
        }
Esempio n. 16
0
        private GameObject CreateWalls(SpriteNodeBatch activateGame, SpriteNodeBatch activateCollision)
        {
            // Called above : CreateWalls(pBatch_TheSwarm, pBatch_Boxes);

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

            pWallGroup.ActivateGameSprite(activateGame);
            pWallGroup.ActivateCollisionSprite(activateCollision);

            WallRight pWallRight = new WallRight(GameObject.Name.WallRight, GameSprite.Name.NullObject, 870.0f, 500.0f, 35.0f, 1000.0f);

            pWallRight.ActivateCollisionSprite(activateCollision);

            WallLeft pWallLeft = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.NullObject, 30.0f, 500.0f, 35.0f, 1000.0f);

            pWallLeft.ActivateCollisionSprite(activateCollision);

            WallTop pWallTop = new WallTop(GameObject.Name.WallTop, GameSprite.Name.NullObject, 448, 950, 890, 50);

            pWallTop.ActivateCollisionSprite(activateCollision);

            WallBottom pWallBottom = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.Wall, 448, 80, 890, 10);

            pWallBottom.ActivateCollisionSprite(activateCollision);
            pWallBottom.ActivateGameSprite(activateGame);

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

            GameObjectManager.Attach(pWallGroup);

            return((GameObject)pWallGroup);
        }
Esempio n. 17
0
 public override void VisitWallRight(WallRight pWallRight)
 {
     //Debug.WriteLine("Hit right wall!");
 }
Esempio n. 18
0
        //-----------------------------------------------------------------------------
        // Game::LoadContent()
        //		Allows you to load all content needed for your engine,
        //	    such as objects, graphics, etc.
        //-----------------------------------------------------------------------------

        public override void LoadContent()
        {
            Debug.WriteLine("----------------------------------");
            Debug.WriteLine("Load Content");
            Debug.WriteLine("----------------------------------\n");


            //-----------------------------------------------
            //Create Game Simulation instance
            Simulation.Create();

            //-----------------------------------------------
            //Manager Load
            //------------------------------
            //Texture Manager Create
            TextureManager.Create();
            //------------------------------
            //Image Manager Create
            ImageManager.Create();
            //------------------------------
            //Game/Box Sprite Manager Create
            GameSpriteManager.Create(5, 2);
            BoxSpriteManager.Create();
            //------------------------------
            //SpriteBatch Manager Create
            SpriteBatchManager.Create();
            //------------------------------
            //ProxySprite Manager Create
            ProxySpriteManager.Create(10, 1);
            //------------------------------
            //GameObject Manager Create
            GameObjectManager.Create();
            //------------------------------
            //CollisionPair Manager Create
            ColPairManager.Create();
            //------------------------------
            //TimerEvent Manager Create
            TimerEventManager.Create();
            //------------------------------
            //Glyph/Font Manager Create/Load
            GlyphManager.Create();
            FontManager.Create();

            //------------------------------
            //Death/Ghost Manager Create
            DeathManager.Create(1, 1);
            GhostManager.Create(1, 1);
            //-----------------------------------------------
            // Input Manager - Key Observer Load
            InputManager.LoadKeyInputObservers();

            //-----------------------------------------------
            //Print some initial stats
            TextureManager.DumpStats();
            ImageManager.DumpStats();
            GameSpriteManager.DumpStats();
            BoxSpriteManager.DumpStats();
            SpriteBatchManager.DumpStats();
            ProxySpriteManager.DumpStats();
            TimerEventManager.DumpStats();
            GameObjectManager.DumpStats();
            DeathManager.DumpStats();
            GhostManager.DumpStats();
            ColPairManager.DumpStats();
            GlyphManager.DumpStats();

            //------------------------------
            //Asset Loading

            //Texture/Image/Font Load
            TextureManager.LoadTextures();
            ImageManager.LoadImages();
            FontManager.LoadFonts();

            //-----------------------------------------------
            //Sprite Batch /Sprite Load
            SpriteBatch pSB_GameSprites = SpriteBatchManager.Add(SpriteBatch.Name.GameSprites);
            SpriteBatch pShields        = SpriteBatchManager.Add(SpriteBatch.Name.Shields);
            SpriteBatch pSB_Boxes       = SpriteBatchManager.Add(SpriteBatch.Name.SpriteBoxes);
            SpriteBatch pSB_Texts       = SpriteBatchManager.Add(SpriteBatch.Name.TextLetters);


            //-----------------------------------------------
            //Sprites/BoxSprites Load
            //NOTE that the following coordinates will not matter
            //once proxy sprites are used!

            //35w x 35h for all sprites;
            float const_AlienSpriteSize = 30.0f;


            //render dimensions/coordinates
            float squid_sX = 400.0f;
            float squid_sY = 400.0f;

            float crab_sX = 400.0f;
            float crab_sY = 350.0f;

            float octo_sX = 400.0f;
            float octo_sY = 300.0f;

            float missileSpriteWidth  = 4.0f;
            float missileSpriteHeight = 8.0f;

            float alienBombSpriteWidth  = 6.0f;
            float alienBombSpriteHeight = 12.0f;

            float shipSpriteWidth  = 55.0f;
            float shipSpriteHeight = 25.0f;

            float verticalWallWidth  = 678.0f;
            float verticalWallHeight = 10.0f;

            float horizontalWallWidth  = 678.0f;
            float horizontalWallHeight = 10.0f;

            //----------------------
            //aliens (initial sprites only)

            //note that the alien grid and alien column are game sprites for box sprite rendering,
            //but will pass a null image since they don't have anything to render
            GameSpriteManager.Add(GameSprite.Name.AlienGrid, Image.Name.NullObject, 0, 0, 0, 0);
            GameSpriteManager.Add(GameSprite.Name.AlienColumn, Image.Name.NullObject, 0, 0, 0, 0);

            //squid game sprite
            GameSpriteManager.Add(GameSprite.Name.Squid, Image.Name.SquidOpen, squid_sX, squid_sY, const_AlienSpriteSize, const_AlienSpriteSize);
            //crab game sprite
            GameSpriteManager.Add(GameSprite.Name.Crab, Image.Name.CrabOpen, crab_sX, crab_sY, const_AlienSpriteSize, const_AlienSpriteSize);
            //octopus game sprite
            GameSpriteManager.Add(GameSprite.Name.Octopus, Image.Name.OctopusOpen, octo_sX, octo_sY, const_AlienSpriteSize, const_AlienSpriteSize);

            //alien explosion (for explosion animation after alien is destroyed)
            GameSpriteManager.Add(GameSprite.Name.AlienExplosion, Image.Name.AlienExplosionPop, 0, 0, const_AlienSpriteSize, const_AlienSpriteSize);



            //----------------------
            //alien bombs (initial sprites only)

            //zigzag bomb
            GameSpriteManager.Add(GameSprite.Name.ZigZagAlienBomb, Image.Name.AlienBombZigZag_One, 0, 0, alienBombSpriteWidth, alienBombSpriteHeight);
            //cross bomb
            GameSpriteManager.Add(GameSprite.Name.CrossAlienBomb, Image.Name.AlienBombCross_One, 0, 0, alienBombSpriteWidth, alienBombSpriteHeight);
            //rolling bomb
            GameSpriteManager.Add(GameSprite.Name.RollingAlienBomb, Image.Name.AlienBombRolling_Two, 0, 0, alienBombSpriteWidth, alienBombSpriteHeight);

            //----------------------
            //hero ship
            GameSpriteManager.Add(GameSprite.Name.Ship, Image.Name.Ship, 640.0f, 440.0f, shipSpriteWidth, shipSpriteHeight);
            //hero missile
            GameSpriteManager.Add(GameSprite.Name.Missile, Image.Name.Missile, 0, 0, missileSpriteWidth, missileSpriteHeight);

            //----------------------
            //walls (2: top/bottom, left/right)
            //note screen w = 672px wide by 768px
            GameSpriteManager.Add(GameSprite.Name.VerticalWall, Image.Name.NullObject, 0, 0, verticalWallWidth, verticalWallHeight);
            GameSpriteManager.Add(GameSprite.Name.HorizontalWall, Image.Name.NullObject, 0, 0, horizontalWallWidth, horizontalWallHeight);


            //----------------------
            //shield bricks (6)

            float brickSpriteWidth  = 15.0f;
            float brickSpriteHeight = 10.0f;

            GameSpriteManager.Add(GameSprite.Name.ShieldBrick, Image.Name.ShieldBrick, 0.0f, 0.0f, brickSpriteWidth, brickSpriteHeight);
            GameSpriteManager.Add(GameSprite.Name.ShieldBrickLeft_Top, Image.Name.ShieldBrickLeft_Top, 0.0f, 0.0f, brickSpriteWidth, brickSpriteHeight);
            GameSpriteManager.Add(GameSprite.Name.ShieldBrickRight_Top, Image.Name.ShieldBrickRight_Top, 0, 0, brickSpriteWidth, brickSpriteHeight);
            GameSpriteManager.Add(GameSprite.Name.ShieldBrickMidLeft_Bottom, Image.Name.ShieldBrickMidLeft_Bottom, 0, 0, brickSpriteWidth, brickSpriteHeight);
            GameSpriteManager.Add(GameSprite.Name.ShieldBrickMid_Bottom, Image.Name.ShieldBrickMid_Bottom, 0, 0, brickSpriteWidth, brickSpriteHeight);
            GameSpriteManager.Add(GameSprite.Name.ShieldBrickMidRight_Bottom, Image.Name.ShieldBrickMidRight_Bottom, 0, 0, brickSpriteWidth, brickSpriteHeight);


            //----------------------
            //alien UFO ship
            float ufoSpriteWidth  = 30.0f;
            float ufoSpriteHeight = 10.0f;

            GameSpriteManager.Add(GameSprite.Name.AlienUFO, Image.Name.AlienUFO, 0, 0, ufoSpriteWidth, ufoSpriteHeight);

            //----------------------
            //BoxSprites are added in the CollisionObject constructor depending on the sprite!



            //-----------------------------------------------
            //Load the Animations (TimerEvents)

            TimerEventManager.LoadAlienAnimations();
            TimerEventManager.LoadBombAnimations();



            //-----------------------------------------------
            //Set the Game Simulation State;

            Simulation.SetState(Simulation.State.Realtime);



            //-----------------------------------------------
            //GameObject Load (Factory)

            //get the PCSRootTree that was created by GameObjectManager
            PCSTree rootGamObjTree = GameObjectManager.GetRootTree();

            //make sure root tree and root have been created;
            Debug.Assert(rootGamObjTree != null);
            Debug.Assert(rootGamObjTree.GetRoot() != null);

            //check the tree
            rootGamObjTree.DumpTree();

            //------------------------------------------------
            // Create Missile Tree

            MissileRoot pMissileRoot = new MissileRoot(GameObject.Name.MissileRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);

            rootGamObjTree.Insert(pMissileRoot, null);
            //pMissileRoot.ActivateCollisionSprite(pSB_Boxes);

            //GameObjectManager.AttachTree(pMissileRoot, rootGamObjTree);
            GameObjectManager.AttachTree(pMissileRoot);

            //TEST------------------
            //PCSTree missileTree = new PCSTree();

            //MissileRoot pMissileRoot = new MissileRoot(GameObject.Name.MissileRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);

            //missileTree.Insert(pMissileRoot, null);
            //pMissileRoot.ActivateCollisionSprite(pSB_Boxes);

            //GameObjectManager.AttachTree(pMissileRoot, rootGamObjTree);
            //rootGamObjTree.Insert(pMissileRoot, rootGamObjTree.GetRoot());

            //------------------------------------------------
            // Create Ship Tree

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

            DeathManager.Attach(shipRoot);


            //check the tree
            rootGamObjTree.DumpTree();

            //attach the shipRoot to the rootGameObjTree, with the gamObjRoot as parent
            rootGamObjTree.Insert(shipRoot, null);

            //check the tree
            rootGamObjTree.DumpTree();

            //attach the shipRoot to the root game object tree
            //GameObjectManager.AttachTree(shipRoot, rootGamObjTree);
            GameObjectManager.AttachTree(shipRoot);

            //create the ship manager that handles all the ship's states
            ShipManager.CreateShipManager();

            //check the tree
            rootGamObjTree.DumpTree();



            //------------------------------------------------
            // Create an Alien Tree

            //AlienRoot alienRoot = new AlienRoot(GameObject.Name.AlienRoot, GameSprite.SpriteName.Null_Object, 0, 0.0f, 0.0f);

            //create the PCS tree that will hold all alien game objects
            PCSTree pAlienTree = new PCSTree();

            DeathManager.Attach(pAlienTree);

            //create the alien game object factory with pAlienTree as the factory's tree
            //factory will attach all alien game objects to pAlienTree
            AlienFactory pAlienFactory = new AlienFactory(SpriteBatch.Name.GameSprites, pAlienTree);

            DeathManager.Attach(pAlienFactory);

            //attach grid as a child of game object root; grid will be parent of all alien game objects
            Grid pGrid = (Grid)pAlienFactory.Create(AlienType.Type.AlienGrid, GameObject.Name.Grid);

            // set the grid as the root parent to attach all aliens to;
            pAlienFactory.SetParent(pGrid);

            //Build the grid (builder pattern)
            int numberOfColumns = 11;

            //numberOfColumns = 1;
            AlienFactory.BuildAlienGrid(pAlienFactory, pGrid, numberOfColumns);

            //check the tree
            rootGamObjTree.DumpTree();

            //GameObjectManager.AttachTree(pGrid, rootGamObjTree);
            GameObjectManager.AttachTree(pGrid);

            //------------------------------------------------
            // Create Alien Bomb tree

            //create the root
            BombRoot pBombRoot = new BombRoot(GameObject.Name.BombRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);

            //insert root into the bomb tree
            rootGamObjTree.Insert(pBombRoot, null);
            //pBombRoot.ActivateCollisionSprite(pSB_Boxes);

            //add the bombtree to the root tree
            //GameObjectManager.AttachTree(pBombRoot, rootGamObjTree);
            GameObjectManager.AttachTree(pBombRoot);

            //check the tree
            rootGamObjTree.DumpTree();



            //------------------------------------------------
            // Associate and Create Walls
            //note screen = 672px wide by 768px

            WallRoot pWallRoot = new WallRoot(GameObject.Name.WallRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);

            rootGamObjTree.Insert(pWallRoot, null);

            WallTop pWallTop = new WallTop(GameObject.Name.WallTop, GameSprite.Name.HorizontalWall, 0, 336.0f, 728.0f, 612.0f, 10.0f);

            rootGamObjTree.Insert(pWallTop, pWallRoot);
            pWallTop.ActivateCollisionSprite(pSB_Boxes);

            WallBottom pWallBottom = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.HorizontalWall, 0, 336.0f, 40.0f, 612.0f, 10.0f);

            rootGamObjTree.Insert(pWallBottom, pWallRoot);
            pWallBottom.ActivateCollisionSprite(pSB_Boxes);

            WallRight pWallRight = new WallRight(GameObject.Name.WallRight, GameSprite.Name.HorizontalWall, 0, 652.0f, 384.0f, 10.0f, 693.0f);

            rootGamObjTree.Insert(pWallRight, pWallRoot);
            pWallRight.ActivateCollisionSprite(pSB_Boxes);

            WallLeft pWallLeft = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.HorizontalWall, 0, 20.0f, 384.0f, 10.0f, 693.0f);

            rootGamObjTree.Insert(pWallLeft, pWallRoot);
            pWallLeft.ActivateCollisionSprite(pSB_Boxes);

            //now that it's fully created, attach the newly created wall tree to the main game object tree
            //GameObjectManager.AttachTree(pWallRoot, rootGamObjTree);
            GameObjectManager.AttachTree(pWallRoot);

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

            //create the root
            ShieldRoot pShieldRoot = new ShieldRoot(GameObject.Name.ShieldRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);

            rootGamObjTree.Insert(pShieldRoot, null);

            //attach to game object tree
            GameObjectManager.AttachTree(pShieldRoot);

            // create the factory
            ShieldFactory shieldFactory = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Shields, rootGamObjTree);

            // set the parent for hierarchy inside the factory, grid is root, so parent is null
            //shieldFactory.setParent(pShieldRoot);

            // create and attach grid to Root
            //ShieldGrid pShieldGrid = (ShieldGrid)shieldFactory.Create(ShieldCategory.Type.ShieldGrid, GameObject.Name.ShieldGrid);


            float startPos_X = 50.0f;
            float startPos_y = 100.0f;

            //shield 1 - far left
            shieldFactory.BuildShield(pShieldRoot, startPos_X, startPos_y, brickSpriteWidth, brickSpriteHeight);

            //move to the right
            startPos_X = 210.0f;
            shieldFactory.BuildShield(pShieldRoot, startPos_X, startPos_y, brickSpriteWidth, brickSpriteHeight);

            //move to the right
            startPos_X = 370.0f;
            shieldFactory.BuildShield(pShieldRoot, startPos_X, startPos_y, brickSpriteWidth, brickSpriteHeight);


            //move to the right
            startPos_X = 520.0f;
            shieldFactory.BuildShield(pShieldRoot, startPos_X, startPos_y, brickSpriteWidth, brickSpriteHeight);


            //check the tree
            rootGamObjTree.DumpTree();



            //------------------------------------------------
            // Associate and Create Collision Pairs
            ColPair pColPair = null;

            // IMPORTANT: At LEAST two steps when establishing the collision pairs
            // 1) associate object roots in a collision pair,
            // 2) then attach all relevent Observer objects that will execute their specified response to collision
            //todo create an observerObject manager that pools all of these observer objects!

            //---------------------------------------------------------------------------------------------
            //Missile CollisionPairs

            //Missile vs Wall (Top) Collision

            // associate object roots in a collision pair
            pColPair = ColPairManager.Add(ColPair.Name.Missile_Wall, pMissileRoot, pWallRoot);
            //attach all observers that will react to collision
            pColPair.Attach(new ShipReadyObserver());
            pColPair.Attach(new ShipRemoveMissileObserver());

            //--------------------
            // Missile vs Shield collision

            // associate object roots in a collision pair
            pColPair = ColPairManager.Add(ColPair.Name.Misslie_Shield, pMissileRoot, pShieldRoot);
            //attach all observers that will react to this collision
            pColPair.Attach(new RemoveMissileObserver());
            //pColPair.Attach(new DegradeBrickSpriteObserver());
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new ShipReadyObserver());


            //--------------------
            //Missile vs AlienGrid collision

            // associate object roots in a collision pair
            pColPair = ColPairManager.Add(ColPair.Name.Alien_Missile, pMissileRoot, pGrid);
            //attach all observers that will react to collision
            pColPair.Attach(new RemoveMissileObserver());
            //todo alien explosion animation isn't working
            pColPair.Attach(new AnimateAlienExplosionObserver());
            pColPair.Attach(new RemoveAlienObserver());
            //pColPair.Attach(new AlienDeathSoundObserver());
            //pColPair.Attach(new AlienScoreUpdateObserver());
            pColPair.Attach(new ShipReadyObserver());

            //---------------------------------------------------------------------------------------------
            //Bomb CollisionPairs


            //Bomb vs Wall (Bottom) Collision

            // associate object roots in a collision pair
            pColPair = ColPairManager.Add(ColPair.Name.Bomb_Wall, pBombRoot, pWallRoot);
            //attach all observers that will react to collision
            //pColPair.Attach(new BombObserver());
            pColPair.Attach(new RemoveBombObserver());


            //todo broken collision - fix
            //--------------------
            //Bomb vs Shield Collision

            // associate object roots in a collision pair
            pColPair = ColPairManager.Add(ColPair.Name.Bomb_Shield, pBombRoot, pShieldRoot);
            //attach all observers that will react to collision
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new RemoveBrickObserver());

            //todo need to implement collision reaction for bomb v ship
            ////--------------------
            ////Bomb vs Ship Collision

            //// associate object roots in a collision pair
            //pColPair = ColPairManager.Add(ColPair.Name.Bomb_Ship, pBombRoot, shipRoot);
            ////attach all observers that will react to collision
            //pColPair.Attach(new RemoveBombObserver());
            ////pColPair.Attach(new ShipExplosionSoundObserver());
            ////pColPair.Attach(new TriggerGameOverStateObserver());


            //todo need to implement collision reaction for grid v wall, grid vs shield;
            //---------------------------------------------------------------------------------------------
            //AlienGrid/Column CollisionPairs

            ////AlienGrid vs Walls

            //// associate object roots in a collision pair
            //pColPair = ColPairManager.Add(ColPair.Name.Alien_Wall, pGrid, pWallRoot);
            ////attach all observers that will react to collision
            //pColPair.Attach(new AlienGridPivotObserver());

            //--------------------
            //AlienColumn vs Shield Collision

            //// associate object roots in a collision pair
            //pColPair = ColPairManager.Add(ColPair.Name.Alien_Shield, pGrid, pShieldRoot);
            ////attach all observers that will react to collision
            //pColPair.Attach(new RemoveShieldBrickObserver());


            //---------------------------------------------------------------------------------------------
            //Ship CollisionPairs



            Debug.WriteLine("\n\n\n\n\n");
            GameObjectManager.DumpAll();



            Debug.WriteLine("\n\nLoad Content Complete\n----------------------------------\n");

            //-----------------------------------------------
            //Data Dump;

            TextureManager.DumpStats();
            ImageManager.DumpStats();
            GameSpriteManager.DumpStats();
            BoxSpriteManager.DumpStats();
            SpriteBatchManager.DumpStats();
            ProxySpriteManager.DumpStats();
            TimerEventManager.DumpStats();
            GameObjectManager.DumpStats();
            DeathManager.DumpStats();
            GhostManager.DumpStats();
            ColPairManager.DumpStats();
            GlyphManager.DumpStats();

            //TextureManager.DumpLists();
            //ImageManager.DumpLists();
            //GameSpriteManager.DumpLists();
            BoxSpriteManager.DumpLists();
            //SpriteBatchManager.DumpLists();
            //ProxySpriteManager.DumpLists();
            //TimerEventManager.DumpLists();
            //GameObjectManager.DumpLists();
            //DeathManager.DumpLists();
            //GhostManager.DumpLists();
            //ColPairManager.DumpLists();
            //GlyphManager.DumpLists();

            //TextureManager.DumpAll();
            //ImageManager.DumpAll();
            //GameSpriteManager.DumpAll();
            //BoxSpriteManager.DumpAll();
            //SpriteBatchManager.DumpAll();
            //ProxySpriteManager.DumpAll();
            //TimerEventManager.DumpAll();
            //GameObjectManager.DumpAll();
            //DeathManager.DumpAll();
            //GhostManager.DumpAll();
            //ColPairManager.DumpAll();
            //GlyphManager.DumpAll();
        }
Esempio n. 19
0
 public virtual void VisitWallRight(WallRight pWallRight)
 {
     // no differed to subcass
     Debug.WriteLine("Visit by WallRight not implemented");
     Debug.Assert(false);
 }
Esempio n. 20
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());
        }
Esempio n. 21
0
        public Game(bool isFirstRound, bool areCollisionBoxesActive)
        {   // Active Game
            this.SetState(GameStateEnum.Active);
            SpriteBatch sbBoxes      = SpriteBatchManager.Find(SpriteBatchName.Boxes);
            SpriteBatch sbAliens     = SpriteBatchManager.Find(SpriteBatchName.Aliens);
            PCSTree     pRootTree    = GameObjectManager.GetRootTree();
            WallRoot    pWallRoot    = (WallRoot)GameObjectManager.Find(GameObjectName.WallRoot);
            BombRoot    pBombRoot    = (BombRoot)GameObjectManager.Find(GameObjectName.BombRoot);
            MissileRoot pMissileRoot = (MissileRoot)GameObjectManager.Find(GameObjectName.MissileRoot);
            ShipRoot    pShipRoot    = (ShipRoot)GameObjectManager.Find(GameObjectName.ShipRoot);
            UFORoot     pUFORoot     = (UFORoot)GameObjectManager.Find(GameObjectName.UFORoot);
            ShieldRoot  pShieldRoot1 = (ShieldRoot)GameObjectManager.Find(GameObjectName.ShieldRoot, 1);
            ShieldRoot  pShieldRoot2 = (ShieldRoot)GameObjectManager.Find(GameObjectName.ShieldRoot, 2);
            ShieldRoot  pShieldRoot3 = (ShieldRoot)GameObjectManager.Find(GameObjectName.ShieldRoot, 3);
            ShieldRoot  pShieldRoot4 = (ShieldRoot)GameObjectManager.Find(GameObjectName.ShieldRoot, 4);

            if (isFirstRound)
            {
                // Create Walls
                pWallRoot = new WallRoot(GameObjectName.WallRoot, SpriteBaseName.Null, 0.0f, 0.0f, 0);
                pRootTree.Insert(pWallRoot, null);
                if (areCollisionBoxesActive)
                {
                    pWallRoot.ActivateCollisionSprite(sbBoxes);
                }
                WallTop pWallTop = new WallTop(GameObjectName.WallTop, SpriteBaseName.Null, 448.0f, 950.0f, 850.0f, 30.0f, 0);
                pRootTree.Insert(pWallTop, pWallRoot);
                if (areCollisionBoxesActive)
                {
                    pWallTop.ActivateCollisionSprite(sbBoxes);
                }
                pWallTop.ActivateGameSprite(sbAliens);

                WallRight pWallRight = new WallRight(GameObjectName.WallRight, SpriteBaseName.Null, 896.0f, 500.0f, 50.0f, 900.0f, 0);
                pRootTree.Insert(pWallRight, pWallRoot);
                if (areCollisionBoxesActive)
                {
                    pWallRight.ActivateCollisionSprite(sbBoxes);
                }
                pWallRight.ActivateGameSprite(sbAliens);

                WallLeft pWallLeft = new WallLeft(GameObjectName.WallLeft, SpriteBaseName.Null, 0.0f, 500.0f, 50.0f, 900.0f, 0);
                pRootTree.Insert(pWallLeft, pWallRoot);
                if (areCollisionBoxesActive)
                {
                    pWallLeft.ActivateCollisionSprite(sbBoxes);
                }
                pWallLeft.ActivateGameSprite(sbAliens);

                WallBottom pWallBottom = new WallBottom(GameObjectName.WallBottom, SpriteBaseName.Null, 448.0f, 50.0f, 850.0f, 30.0f, 0);
                pRootTree.Insert(pWallBottom, pWallRoot);
                if (areCollisionBoxesActive)
                {
                    pWallBottom.ActivateCollisionSprite(sbBoxes);
                }
                pWallBottom.ActivateGameSprite(sbAliens);
                GameObjectManager.AttachTree(pWallRoot);

                // Create ShipRoot and MissileRoot
                pMissileRoot = new MissileRoot(GameObjectName.MissileRoot, SpriteBaseName.Null, 0.0f, 0.0f, 0);
                pRootTree.Insert(pMissileRoot, null);
                if (areCollisionBoxesActive)
                {
                    pMissileRoot.ActivateCollisionSprite(sbBoxes);
                }
                GameObjectManager.AttachTree(pMissileRoot);
                pShipRoot = new ShipRoot(GameObjectName.ShipRoot, SpriteBaseName.Null, 0.0f, 0.0f);
                pRootTree.Insert(pShipRoot, null);
                if (areCollisionBoxesActive)
                {
                    pShipRoot.ActivateCollisionSprite(sbBoxes);
                }
                pShipRoot.ActivateGameSprite(sbAliens);
                GameObjectManager.AttachTree(pShipRoot);
                ShipManager.Create(areCollisionBoxesActive);

                // Create BombRoot
                pBombRoot = new BombRoot(GameObjectName.BombRoot, SpriteBaseName.Null, 0.0f, 0.0f, 0);
                pRootTree.Insert(pBombRoot, null);
                if (areCollisionBoxesActive)
                {
                    pBombRoot.ActivateCollisionSprite(sbBoxes);
                }
                GameObjectManager.AttachTree(pBombRoot);

                // Create UFORoot
                pUFORoot = new UFORoot(GameObjectName.UFORoot, SpriteBaseName.Null, 0.0f, 0.0f);
                pRootTree.Insert(pUFORoot, null);
                if (areCollisionBoxesActive)
                {
                    pUFORoot.ActivateCollisionSprite(sbBoxes);
                }
                pUFORoot.ActivateGameSprite(sbAliens);
                GameObjectManager.AttachTree(pUFORoot);
                UFOManager.Create(areCollisionBoxesActive);

                // Create Shields
                pShieldRoot1 = GenerateShield(pRootTree, 100.0f, 200.0f, 1);
                pShieldRoot2 = GenerateShield(pRootTree, 100.0f + 1 * 200, 200.0f, 2);
                pShieldRoot3 = GenerateShield(pRootTree, 100.0f + 2 * 200, 200.0f, 3);
                pShieldRoot4 = GenerateShield(pRootTree, 100.0f + 3 * 200, 200.0f, 4);
            }
            else
            {
                _gridStartingHeight -= 100.0f;
            }

            PopulateAlienGrid(_gridStartingHeight);
            Alien pGridRoot = (Alien)GameObjectManager.Find(GameObjectName.Grid);

            // Create CollisionPairs
            CollisionPair cpMissileWall = CollisionPairManager.Add(CollisionPairName.MissilevTop, pMissileRoot, pWallRoot);

            Debug.Assert(cpMissileWall != null);
            cpMissileWall.subject.RegisterObserver(new RemoveMissileObserver());
            cpMissileWall.subject.RegisterObserver(new ShipReadyObserver());

            CollisionPair cpBombWall = CollisionPairManager.Add(CollisionPairName.BombsvBottom, pBombRoot, pWallRoot);

            Debug.Assert(cpBombWall != null);
            cpBombWall.subject.RegisterObserver(new RemoveBombObserver());

            CollisionPair cpMissilevGrid = CollisionPairManager.Add(CollisionPairName.MissilevGrid, pMissileRoot, pGridRoot);

            Debug.Assert(cpMissilevGrid != null);
            cpMissilevGrid.subject.RegisterObserver(new RemoveMissileObserver());
            cpMissilevGrid.subject.RegisterObserver(new RemoveAlienObserver());
            cpMissilevGrid.subject.RegisterObserver(new ShipReadyObserver());
            cpMissilevGrid.subject.RegisterObserver(new AlienDeathSoundObserver());
            cpMissilevGrid.subject.RegisterObserver(new SplatObserver());
            cpMissilevGrid.subject.RegisterObserver(new UpdateScoreObserver());

            CollisionPair cpUFOMissile = CollisionPairManager.Add(CollisionPairName.MissilevUFO, pMissileRoot, pUFORoot);

            cpUFOMissile.subject.RegisterObserver(new RemoveMissileObserver());
            cpUFOMissile.subject.RegisterObserver(new RemoveUFOObserver());
            cpUFOMissile.subject.RegisterObserver(new ShipReadyObserver());
            cpUFOMissile.subject.RegisterObserver(new AlienDeathSoundObserver());
            cpUFOMissile.subject.RegisterObserver(new SplatObserver());
            cpUFOMissile.subject.RegisterObserver(new UpdateScoreObserver());
            cpUFOMissile.subject.RegisterObserver(new UFODeathSoundObserver());

            CollisionPair cpUFOWalls = CollisionPairManager.Add(CollisionPairName.UFOvWalls, pUFORoot, pWallRoot);

            cpUFOWalls.subject.RegisterObserver(new UFOWallObserver());

            CollisionPair cpGridvWalls = CollisionPairManager.Add(CollisionPairName.GridvWalls, pGridRoot, pWallRoot);

            Debug.Assert(cpGridvWalls != null);
            cpGridvWalls.subject.RegisterObserver(new GridXObserver());
            cpGridvWalls.subject.RegisterObserver(new GridYObserver());

            CollisionPair cpGridvShip = CollisionPairManager.Add(CollisionPairName.GridvShip, pGridRoot, pShipRoot);

            cpGridvShip.subject.RegisterObserver(new GameOverObserver());
            cpGridvShip.subject.RegisterObserver(new ShipDeathSoundObserver());

            CollisionPair cpMissileShield1 = CollisionPairManager.Add(CollisionPairName.MissilevShields, pMissileRoot, pShieldRoot1);

            cpMissileShield1.subject.RegisterObserver(new RemoveMissileObserver());
            cpMissileShield1.subject.RegisterObserver(new RemoveBrickObserver());
            cpMissileShield1.subject.RegisterObserver(new ShipReadyObserver());
            CollisionPair cpBombShield1 = CollisionPairManager.Add(CollisionPairName.BombsvShields, pBombRoot, pShieldRoot1);

            cpBombShield1.subject.RegisterObserver(new RemoveBombObserver());
            cpBombShield1.subject.RegisterObserver(new RemoveBrickObserver());

            CollisionPair cpMissileShield2 = CollisionPairManager.Add(CollisionPairName.MissilevShields, pMissileRoot, pShieldRoot2);

            cpMissileShield2.subject.RegisterObserver(new RemoveMissileObserver());
            cpMissileShield2.subject.RegisterObserver(new RemoveBrickObserver());
            cpMissileShield2.subject.RegisterObserver(new ShipReadyObserver());
            CollisionPair cpBombShield2 = CollisionPairManager.Add(CollisionPairName.BombsvShields, pBombRoot, pShieldRoot2);

            cpBombShield2.subject.RegisterObserver(new RemoveBombObserver());
            cpBombShield2.subject.RegisterObserver(new RemoveBrickObserver());

            CollisionPair cpBombShield3 = CollisionPairManager.Add(CollisionPairName.BombsvShields, pBombRoot, pShieldRoot3);

            cpBombShield3.subject.RegisterObserver(new RemoveBombObserver());
            cpBombShield3.subject.RegisterObserver(new RemoveBrickObserver());
            CollisionPair cpMissileShield3 = CollisionPairManager.Add(CollisionPairName.MissilevShields, pMissileRoot, pShieldRoot3);

            cpMissileShield3.subject.RegisterObserver(new RemoveMissileObserver());
            cpMissileShield3.subject.RegisterObserver(new RemoveBrickObserver());
            cpMissileShield3.subject.RegisterObserver(new ShipReadyObserver());

            CollisionPair cpBombShield4 = CollisionPairManager.Add(CollisionPairName.BombsvShields, pBombRoot, pShieldRoot4);

            cpBombShield4.subject.RegisterObserver(new RemoveBombObserver());
            cpBombShield4.subject.RegisterObserver(new RemoveBrickObserver());
            CollisionPair cpMissileShield4 = CollisionPairManager.Add(CollisionPairName.MissilevShields, pMissileRoot, pShieldRoot4);

            cpMissileShield4.subject.RegisterObserver(new RemoveMissileObserver());
            cpMissileShield4.subject.RegisterObserver(new RemoveBrickObserver());
            cpMissileShield4.subject.RegisterObserver(new ShipReadyObserver());

            CollisionPair cpBombMissile = CollisionPairManager.Add(CollisionPairName.BombsvMissile, pBombRoot, pMissileRoot);

            cpBombMissile.subject.RegisterObserver(new RemoveBombObserver());
            cpBombMissile.subject.RegisterObserver(new RemoveMissileObserver());
            cpBombMissile.subject.RegisterObserver(new ShipReadyObserver());
            cpBombMissile.subject.RegisterObserver(new SplatObserver());

            CollisionPair cpBombShip = CollisionPairManager.Add(CollisionPairName.BombsvShip, pBombRoot, pShipRoot);

            cpBombShip.subject.RegisterObserver(new RemoveBombObserver());
            cpBombShip.subject.RegisterObserver(new RemoveShipObserver());
            cpBombShip.subject.RegisterObserver(new ShipDeathSoundObserver());
            cpBombShip.subject.RegisterObserver(new ShipEndObserver());

            //TimerManager.ClearTimerManager();
        }
Esempio n. 22
0
        public override void Initialize()
        {
            //this.name = SceneContext.Scene.Play;

            this.numLives = 3;
            this.isDead   = false;

            //---------------------------------------------------------------------------------------------------------
            // Unique Managers
            //---------------------------------------------------------------------------------------------------------

            this.poSpriteBatchMan = new SpriteBatchMan(3, 1);
            SpriteBatchMan.SetActive(this.poSpriteBatchMan);

            this.poGameObjectMan = new GameObjectMan(3, 1);
            GameObjectMan.SetActive(this.poGameObjectMan);

            this.poTimerMan = new TimerMan(3, 1);
            TimerMan.SetActive(this.poTimerMan);

            this.poDelayedObjectMan = new DelayedObjectMan();
            DelayedObjectMan.SetActive(this.poDelayedObjectMan);

            //---------------------------------------------------------------------------------------------------------
            // Initialize Input Keys
            //---------------------------------------------------------------------------------------------------------

            this.poInputMan = new InputMan();
            InputMan.SetActive(this.poInputMan);

            InputSubject pInputSubject;

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

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

            pInputSubject = InputMan.GetSpaceSubject();
            pInputSubject.Attach(new ShootObserver());

            pInputSubject = InputMan.GetKey_B_Subject();
            pInputSubject.Attach(new Key_B_Observer());

            pInputSubject = InputMan.GetKey_1_Subject();
            pInputSubject.Attach(new Key_1_Observer());

            pInputSubject = InputMan.GetKey_2_Subject();
            pInputSubject.Attach(new Key_2_Observer());

            pInputSubject = InputMan.GetKey_Q_Subject();
            pInputSubject.Attach(new Key_Q_Observer());

            //---------------------------------------------------------------------------------------------------------
            // Sound
            //---------------------------------------------------------------------------------------------------------

            // start up the engine
            SoundEngineMan.Add(SoundEngine.Name.AlienA, "fastinvader1.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.AlienB, "fastinvader2.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.AlienC, "fastinvader3.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.AlienD, "fastinvader4.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.Shoot, "shoot.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.Invaderkilled, "invaderkilled.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.Explosion, "explosion.wav", 0.2f);
            SoundEngineMan.Add(SoundEngine.Name.UFO_HighPitch, "ufo_highpitch.wav", 0.5f);
            SoundEngineMan.Add(SoundEngine.Name.UFO_LowPitch, "ufo_lowpitch.wav", 0.2f);

            //---------------------------------------------------------------------------------------------------------
            // Font
            //---------------------------------------------------------------------------------------------------------

            Texture pTexture = TextureMan.Add(Texture.Name.Consolas36pt, "Consolas36pt.tga");

            GlyphMan.AddXml(Glyph.Name.Consolas36pt, "Consolas36pt.xml", Texture.Name.Consolas36pt);

            //---------------------------------------------------------------------------------------------------------
            // Create Sprites
            //---------------------------------------------------------------------------------------------------------
            this.poGameSpriteMan = new GameSpriteMan(3, 1);
            GameSpriteMan.SetActive(this.poGameSpriteMan);

            // ----- Aliens -----
            GameSpriteMan.Add(GameSprite.Name.SquidOpen, Image.Name.SquidOpen, 50, 550, 22, 22);
            GameSpriteMan.Add(GameSprite.Name.CrabOpen, Image.Name.CrabOpen, 50, 510, 25, 25);
            GameSpriteMan.Add(GameSprite.Name.OctopusOpen, Image.Name.OctopusOpen, 50, 430, 28, 28);

            // ----- UFO -----
            GameSpriteMan.Add(GameSprite.Name.UFO, Image.Name.UFO, 0, 500, 40, 18);

            // ----- Missile -----
            GameSpriteMan.Add(GameSprite.Name.Missile, Image.Name.Missile, 50, 430, 4, 15);

            // ----- Ship -----
            GameSpriteMan.Add(GameSprite.Name.Ship, Image.Name.Ship, 50, 430, 50, 25);

            // ----- Splats -----
            GameSpriteMan.Add(GameSprite.Name.SplatAlien, Image.Name.AlienSplat, 100, 100, 22, 22);
            GameSpriteMan.Add(GameSprite.Name.SplatBomb, Image.Name.BombSplat, 100, 100, 7, 17);
            GameSpriteMan.Add(GameSprite.Name.SplatMissile, Image.Name.MissleSplat, 100, 100, 20, 15);
            GameSpriteMan.Add(GameSprite.Name.SplatUFO, Image.Name.UFOSplat, 100, 100, 40, 18);
            GameSpriteMan.Add(GameSprite.Name.SplatShip, Image.Name.ShipSplat, 100, 100, 50, 25);

            // ----- Bombs -----
            GameSpriteMan.Add(GameSprite.Name.BombDragger, Image.Name.BombDragger, 100, 100, 7, 17);
            GameSpriteMan.Add(GameSprite.Name.BombZigZag, Image.Name.BombZigZag, 100, 100, 7, 17);
            GameSpriteMan.Add(GameSprite.Name.BombRolling, Image.Name.BombRolling, 100, 100, 7, 17);
            GameSpriteMan.Add(GameSprite.Name.BombStraight, Image.Name.BombStraight, 100, 100, 5, 17);

            // ----- Shields -----
            float brick_W = 15.0f;
            float brick_H = 6.0f;

            GameSpriteMan.Add(GameSprite.Name.Brick, Image.Name.Brick, 50, 25, brick_W, brick_H);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftTop0, Image.Name.BrickLeft_Top0, 50, 25, brick_W, brick_H);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftTop1, Image.Name.BrickLeft_Top1, 50, 25, brick_W, brick_H);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftBottom, Image.Name.BrickLeft_Bottom, 50, 25, brick_W, brick_H);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightTop0, Image.Name.BrickRight_Top0, 50, 25, brick_W, brick_H);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightTop1, Image.Name.BrickRight_Top1, 50, 25, brick_W, brick_H);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightBottom, Image.Name.BrickRight_Bottom, 50, 25, brick_W, brick_H);

            //---------------------------------------------------------------------------------------------------------
            // Create SpriteBatch
            //---------------------------------------------------------------------------------------------------------

            SpriteBatch pSB_Aliens  = this.poSpriteBatchMan.Add(SpriteBatch.Name.Aliens, 100);
            SpriteBatch pSB_Shields = this.poSpriteBatchMan.Add(SpriteBatch.Name.Shields, 200);
            SpriteBatch pSB_Texts   = this.poSpriteBatchMan.Add(SpriteBatch.Name.Texts, 300);
            SpriteBatch pSB_Box     = this.poSpriteBatchMan.Add(SpriteBatch.Name.Boxes, 400);

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

            // Create the Aliens factory
            AlienFactory AF = new AlienFactory(SpriteBatch.Name.Aliens, SpriteBatch.Name.Boxes);

            // Initialize Grid
            AlienGrid pGrid = (AlienGrid)AF.Create(GameObject.Name.AlienGrid, AlienCategory.Type.Grid);

            // Generate Aliens
            pGrid.GenerateAlien(this.poGameObjectMan);

            MoveCommand pMoveGrid = new MoveCommand(pGrid);

            TimerMan.Add(TimeEvent.Name.MoveGrid, pMoveGrid, 0.5f);

            //---------------------------------------------------------------------------------------------------------
            // Timer
            //---------------------------------------------------------------------------------------------------------

            // Create animation for Squid sprite
            AnimationSprite pAnimSquid = new AnimationSprite(GameSprite.Name.SquidOpen);

            // Attach Squid images to cycle
            pAnimSquid.Attach(Image.Name.SquidOpen);
            pAnimSquid.Attach(Image.Name.SquidClosed);


            // Create animation for Crab sprite
            AnimationSprite pAnimCrab = new AnimationSprite(GameSprite.Name.CrabOpen);

            // Attach Crab images to cycle
            pAnimCrab.Attach(Image.Name.CrabOpen);
            pAnimCrab.Attach(Image.Name.CrabClosed);


            // Create animation for Octopus sprite
            AnimationSprite pAnimOctopus = new AnimationSprite(GameSprite.Name.OctopusOpen);

            // Attach Octopus images to cycle
            pAnimOctopus.Attach(Image.Name.OctopusOpen);
            pAnimOctopus.Attach(Image.Name.OctopusClosed);


            // Add AnimationSprite to timer
            TimerMan.Add(TimeEvent.Name.SwapAliens, pAnimSquid, 0.5f);
            TimerMan.Add(TimeEvent.Name.SwapAliens, pAnimCrab, 0.5f);
            TimerMan.Add(TimeEvent.Name.SwapAliens, pAnimOctopus, 0.5f);

            // Add Grid Tempo
            GridSoundTempoEvent pGridTempo = new GridSoundTempoEvent();

            pGridTempo.Attach(SoundEngine.Name.AlienA);
            pGridTempo.Attach(SoundEngine.Name.AlienB);
            pGridTempo.Attach(SoundEngine.Name.AlienC);
            pGridTempo.Attach(SoundEngine.Name.AlienD);

            TimerMan.Add(TimeEvent.Name.GridSoundTempo, pGridTempo, 0.5f);

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

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

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

            GameObjectMan.Attach(pMissileGroup);

            //---------------------------------------------------------------------------------------------------------
            // Splat Root
            //---------------------------------------------------------------------------------------------------------
            BombRoot pSplatRoot = new BombRoot(GameObject.Name.SplatRoot, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pSplatRoot.ActivateCollisionSprite(pSB_Box);

            GameObjectMan.Attach(pSplatRoot);

            //---------------------------------------------------------------------------------------------------------
            // Bomb Root
            //---------------------------------------------------------------------------------------------------------
            BombRoot pBombRoot = new BombRoot(GameObject.Name.BombRoot, GameSprite.Name.NullObject, 0.0f, 0.0f);

            pBombRoot.ActivateCollisionSprite(pSB_Box);

            GameObjectMan.Attach(pBombRoot);
            TimerMan.Add(TimeEvent.Name.BombRandom, new BombSpawnEvent(pRandom, pGrid), 1.0f);

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

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

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

            WallRight pWallRight = new WallRight(GameObject.Name.WallRight, GameSprite.Name.NullObject, 775, 290, 20, 500);

            pWallRight.ActivateCollisionSprite(pSB_Box);

            WallLeft pWallLeft = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.NullObject, 25, 290, 20, 500);

            pWallLeft.ActivateCollisionSprite(pSB_Box);

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

            GameObjectMan.Attach(pWallGroup);

            //---------------------------------------------------------------------------------------------------------
            // Create No Score Items
            //---------------------------------------------------------------------------------------------------------

            WallGroup pNoScoreGroup = new WallGroup(GameObject.Name.NoScoreGroup, GameSprite.Name.NullObject, 0.0f, 0.0f);

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

            WallTop pWallTop = new WallTop(GameObject.Name.WallTop, GameSprite.Name.NullObject, 400, 540, 700, 0);

            pWallTop.ActivateCollisionSprite(pSB_Aliens);

            WallBottom pWallBottom = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.NullObject, 400, 40, 730, 0);

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

            pNoScoreGroup.Add(pWallTop);
            pNoScoreGroup.Add(pWallBottom);

            GameObjectMan.Attach(pNoScoreGroup);

            //---------------------------------------------------------------------------------------------------------
            // Ship
            //---------------------------------------------------------------------------------------------------------

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

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

            GameObjectMan.Attach(pShipRoot);

            //ShipMan.Create();

            this.poShipMan = new ShipMan();
            ShipMan.SetActive(this.poShipMan);
            this.poShipMan.pShip = ShipMan.ActivateShip();
            this.poShipMan.pShip.SetState(ShipMan.State.Ready);


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

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

            GameObjectMan.Attach(pUFORoot);
            TimerMan.Add(TimeEvent.Name.UFORandom, new UFOSpawnEvent(pRandom), 5.0f);

            //---------------------------------------------------------------------------------------------------------
            // Shields
            //---------------------------------------------------------------------------------------------------------

            Composite pShieldRoot = ShieldsGroupFactory.Create(100, 130, this.poGameObjectMan);

            //---------------------------------------------------------------------------------------------------------
            // ColPair
            //---------------------------------------------------------------------------------------------------------

            // Grid vs Right Left Walls
            ColPair pColPair_GW = ColPairMan.Add(ColPair.Name.Alien_Wall, pGrid, pWallGroup);

            Debug.Assert(pColPair_GW != null);

            pColPair_GW.Attach(new GridDropObserver());

            // Ship vs Right Left Walls
            ColPair pColPair_SW = ColPairMan.Add(ColPair.Name.Ship_Wall, pShipRoot, pWallGroup);

            Debug.Assert(pColPair_SW != null);

            pColPair_SW.Attach(new StopShipMoveObserver());

            // Grid vs Shield
            ColPair pColPair_AS = ColPairMan.Add(ColPair.Name.Bomb_Shield, pGrid, pShieldRoot);

            Debug.Assert(pColPair_AS != null);

            pColPair_AS.Attach(new RemoveBrickObserver());

            // Missile vs Alien
            ColPair pColPair_MA = ColPairMan.Add(ColPair.Name.Missile_Alien, pMissileGroup, pGrid);

            Debug.Assert(pColPair_MA != null);

            pColPair_MA.Attach(new ShipReadyObserver());
            pColPair_MA.Attach(new RemoveAlienObserver(this));
            pColPair_MA.Attach(new ShipRemoveMissileObserver(false));
            pColPair_MA.Attach(new SndAlienHitObserver());
            pColPair_MA.Attach(new SpeedGridObserver());

            // Missile vs UFO
            ColPair pColPair_MU = ColPairMan.Add(ColPair.Name.Missile_UFO, pMissileGroup, pUFORoot);

            Debug.Assert(pColPair_MU != null);

            pColPair_MU.Attach(new ShipReadyObserver());
            pColPair_MU.Attach(new ShipRemoveMissileObserver(false));
            pColPair_MU.Attach(new RemoveUFOObserver());
            pColPair_MU.Attach(new SndAlienHitObserver());

            // Missle vs Bomb
            ColPair pColPair_MB = ColPairMan.Add(ColPair.Name.Missile_Bomb, pMissileGroup, pBombRoot);

            Debug.Assert(pColPair_MB != null);

            pColPair_MB.Attach(new ShipReadyObserver());
            pColPair_MB.Attach(new ShipRemoveMissileObserver(false));
            pColPair_MB.Attach(new BombObserver(true));

            // Missile vs Top Wall
            ColPair pColPair_MW = ColPairMan.Add(ColPair.Name.Missile_Wall, pMissileGroup, pNoScoreGroup);

            Debug.Assert(pColPair_MW != null);

            pColPair_MW.Attach(new ShipReadyObserver());
            pColPair_MW.Attach(new ShipRemoveMissileObserver(true));

            // Missile vs Shield
            ColPair pColPair_MS = ColPairMan.Add(ColPair.Name.Misslie_Shield, pMissileGroup, pShieldRoot);

            Debug.Assert(pColPair_MS != null);

            pColPair_MS.Attach(new ShipRemoveMissileObserver(false));
            pColPair_MS.Attach(new RemoveBrickObserver());
            pColPair_MS.Attach(new ShipReadyObserver());
            pColPair_MS.Attach(new SndAlienHitObserver());

            // Bomb vs Bottom Wall
            ColPair pColPair_BW = ColPairMan.Add(ColPair.Name.Bomb_Wall, pBombRoot, pNoScoreGroup);

            Debug.Assert(pColPair_BW != null);

            pColPair_BW.Attach(new BombObserver(true));

            // Bomb vs Shield
            ColPair pColPair_BS = ColPairMan.Add(ColPair.Name.Bomb_Shield, pBombRoot, pShieldRoot);

            Debug.Assert(pColPair_BS != null);

            pColPair_BS.Attach(new RemoveBombObserver(this));
            pColPair_BS.Attach(new RemoveBrickObserver());
            pColPair_BS.Attach(new SndAlienHitObserver());

            // Bomb vs Player's Ship
            ColPair pColPair_BP = ColPairMan.Add(ColPair.Name.Bomb_Ship, pBombRoot, pShipRoot);

            Debug.Assert(pColPair_BP != null);

            pColPair_BP.Attach(new RemoveShipObserver(this));
            pColPair_BP.Attach(new RemoveBombObserver(this));
            pColPair_BP.Attach(new SndShipHitObserver());
            pColPair_BP.Attach(new ReCreateShipObserver(this));

            //---------------------------------------------------------------------------------------------------------
            // Fonts
            //---------------------------------------------------------------------------------------------------------

            FontMan.Add(Font.Name.ScoreText, SpriteBatch.Name.Texts, "SCORE<1>", Glyph.Name.Consolas36pt, 60, 585);
            pFontScore1 = FontMan.Add(Font.Name.Score1, SpriteBatch.Name.Texts, "0000", Glyph.Name.Consolas36pt, 85, 558);

            FontMan.Add(Font.Name.ScoreText, SpriteBatch.Name.Texts, "HI-SCORE", Glyph.Name.Consolas36pt, 325, 585);
            pFontHighScore = FontMan.Add(Font.Name.HighScore, SpriteBatch.Name.Texts, "0000", Glyph.Name.Consolas36pt, 350, 558);

            FontMan.Add(Font.Name.ScoreText, SpriteBatch.Name.Texts, "SCORE<2>", Glyph.Name.Consolas36pt, 600, 585);
            pFontScore2 = FontMan.Add(Font.Name.Score2, SpriteBatch.Name.Texts, "0000", Glyph.Name.Consolas36pt, 625, 558);

            FontMan.Add(Font.Name.ScoreText, SpriteBatch.Name.Texts, "LIVES: ", Glyph.Name.Consolas36pt, 50, 25);
            pFontLives = FontMan.Add(Font.Name.Lives, SpriteBatch.Name.Texts, "3", Glyph.Name.Consolas36pt, 160, 25);
        }
Esempio n. 23
0
        // strategy()
        override public void LoadContent()
        {
            AlienGroup.ResetDirection();

            TextureMan.Create(2, 1);
            ImageMan.Create(5, 2);
            GameSpriteMan.Create(4, 2);
            BoxSpriteMan.Create(3, 1);
            SpriteBatchMan.Create(3, 1);
            TimerMan.Create(3, 1);
            ProxySpriteMan.Create(10, 1);
            GameObjectMan.Create(3, 1);
            ColPairMan.Create(1, 1);
            Simulation.Create();
            GlyphMan.Create(3, 1);
            FontMan.Create(1, 1);
            //GhostSpriteBatchMan.Create(2, 1);

            //---------------------------------------------------------------------------------------------------------
            // Sound Experiment
            //---------------------------------------------------------------------------------------------------------

            // start up the engine
            sndEngine = new IrrKlang.ISoundEngine();

            //---------------------------------------------------------------------------------------------------------
            // Load the Textures
            //---------------------------------------------------------------------------------------------------------

            TextureMan.Add(Texture.Name.Aliens, "newaliens.tga");
            TextureMan.Add(Texture.Name.Shields, "birds_N_shield.tga");
            Texture pTexture = TextureMan.Add(Texture.Name.Consolas20pt, "Consolas20pt.tga");

            FontMan.AddXml(Glyph.Name.Consolas20pt, "Consolas20pt.xml", Texture.Name.Consolas20pt);

            //---------------------------------------------------------------------------------------------------------
            // Load the Images
            //---------------------------------------------------------------------------------------------------------

            ImageMan.Add(Image.Name.SquidA, Texture.Name.Aliens, 547, 15, 250, 135);
            ImageMan.Add(Image.Name.CrabA, Texture.Name.Aliens, 281, 15, 250, 135);
            ImageMan.Add(Image.Name.OctopusA, Texture.Name.Aliens, 15, 15, 250, 135);

            ImageMan.Add(Image.Name.SquidB, Texture.Name.Aliens, 547, 170, 250, 135);
            ImageMan.Add(Image.Name.CrabB, Texture.Name.Aliens, 281, 170, 250, 135);
            ImageMan.Add(Image.Name.OctopusB, Texture.Name.Aliens, 15, 170, 250, 135);

            ImageMan.Add(Image.Name.MissileBombCol, Texture.Name.Aliens, 395, 480, 130, 130);
            ImageMan.Add(Image.Name.AlienDies, Texture.Name.Aliens, 550, 480, 220, 130);

            ImageMan.Add(Image.Name.UFO, Texture.Name.Aliens, 80, 500, 230, 100);
            ImageMan.Add(Image.Name.UFODies, Texture.Name.Aliens, 15, 630, 355, 140);

            ImageMan.Add(Image.Name.Missile, Texture.Name.Aliens, 370, 795, 30, 105);
            ImageMan.Add(Image.Name.MissileBombDies, Texture.Name.Aliens, 685, 790, 110, 130);
            ImageMan.Add(Image.Name.Ship, Texture.Name.Aliens, 50, 325, 190, 125);
            ImageMan.Add(Image.Name.ShipDiesA, Texture.Name.Aliens, 280, 325, 245, 130);
            ImageMan.Add(Image.Name.ShipDiesB, Texture.Name.Aliens, 545, 325, 245, 130);

            ImageMan.Add(Image.Name.BombRoll, Texture.Name.Aliens, 445, 795, 50, 105);
            ImageMan.Add(Image.Name.BombZigZag, Texture.Name.Aliens, 560, 630, 70, 140);
            ImageMan.Add(Image.Name.BombCross, Texture.Name.Aliens, 110, 790, 50, 100);
            ImageMan.Add(Image.Name.BombFork, Texture.Name.Aliens, 520, 790, 50, 100);
            ImageMan.Add(Image.Name.BombStraight, Texture.Name.Aliens, 370, 795, 30, 105);

            ImageMan.Add(Image.Name.Brick, Texture.Name.Shields, 20, 210, 10, 5);
            ImageMan.Add(Image.Name.BrickLeft_Top0, Texture.Name.Shields, 15, 180, 10, 5);
            ImageMan.Add(Image.Name.BrickLeft_Top1, Texture.Name.Shields, 15, 185, 10, 5);
            ImageMan.Add(Image.Name.BrickLeft_Bottom, Texture.Name.Shields, 35, 215, 10, 5);
            ImageMan.Add(Image.Name.BrickRight_Top0, Texture.Name.Shields, 75, 180, 10, 5);
            ImageMan.Add(Image.Name.BrickRight_Top1, Texture.Name.Shields, 75, 185, 10, 5);
            ImageMan.Add(Image.Name.BrickRight_Bottom, Texture.Name.Shields, 55, 215, 10, 5);

            //---------------------------------------------------------------------------------------------------------
            // Create Sprites
            //---------------------------------------------------------------------------------------------------------

            GameSpriteMan.Add(GameSprite.Name.Squid, Image.Name.SquidA, 100, 600, 35, 30, 255, 255, 255, 1);
            GameSpriteMan.Add(GameSprite.Name.Crab, Image.Name.CrabA, 100, 550, 35, 30, 255, 255, 255, 1);
            GameSpriteMan.Add(GameSprite.Name.Octopus, Image.Name.OctopusA, 100, 500, 35, 30, 255, 255, 255, 1);
            GameSpriteMan.Add(GameSprite.Name.AlienDies, Image.Name.AlienDies, 0, 0, 35, 30, 255, 255, 255, 1);
            GameSpriteMan.Add(GameSprite.Name.UFO, Image.Name.UFO, 100, 500, 35, 30, 255, 0, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.UFODies, Image.Name.UFODies, 0, 0, 35, 30, 255, 0, 0, 1);

            GameSpriteMan.Add(GameSprite.Name.Missile, Image.Name.Missile, 100, 200, 10, 20, 255, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.MissileDies, Image.Name.MissileBombDies, 0, 0, 10, 20, 255, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.MissileBombCol, Image.Name.MissileBombCol, 0, 0, 10, 20, 255, 255, 255, 1);
            GameSpriteMan.Add(GameSprite.Name.Ship, Image.Name.Ship, 300, 30, 40, 20, 255, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.ShipDies, Image.Name.ShipDiesA, 0, 0, 50, 25, 255, 255, 0, 1);

            GameSpriteMan.Add(GameSprite.Name.BombZigZag, Image.Name.BombZigZag, 0, 0, 10, 20, 255, 0, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.BombRolling, Image.Name.BombRoll, 0, 0, 10, 20, 255, 0, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.BombDagger, Image.Name.BombCross, 0, 0, 10, 20, 255, 0, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.BombStraight, Image.Name.BombStraight, 0, 0, 10, 20, 255, 0, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.BombFork, Image.Name.BombFork, 0, 0, 12, 24, 255, 0, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.BombDies, Image.Name.MissileBombDies, 0, 0, 10, 20, 255, 0, 0, 1);

            GameSpriteMan.Add(GameSprite.Name.Brick, Image.Name.Brick, 50, 25, 10, 5, 0, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftTop0, Image.Name.BrickLeft_Top0, 50, 25, 10, 5, 0, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftTop1, Image.Name.BrickLeft_Top1, 50, 25, 10, 5, 0, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftBottom, Image.Name.BrickLeft_Bottom, 50, 25, 10, 5, 0, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightTop0, Image.Name.BrickRight_Top0, 50, 25, 10, 5, 0, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightTop1, Image.Name.BrickRight_Top1, 50, 25, 10, 5, 0, 255, 0, 1);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightBottom, Image.Name.BrickRight_Bottom, 50, 25, 10, 5, 0, 255, 0, 1);

            SpriteBatch pSB_Aliens  = SpriteBatchMan.Add(SpriteBatch.Name.Aliens);
            SpriteBatch pSB_Box     = SpriteBatchMan.Add(SpriteBatch.Name.Boxes);
            SpriteBatch pSB_Shields = SpriteBatchMan.Add(SpriteBatch.Name.Shields);
            SpriteBatch pSB_Texts   = SpriteBatchMan.Add(SpriteBatch.Name.Texts);

            //SpriteBatch pSB_GhostAliens = GhostSpriteBatchMan.Add(SpriteBatch.Name.Aliens);
            //SpriteBatch pSB_GhostBox = GhostSpriteBatchMan.Add(SpriteBatch.Name.Boxes);
            //SpriteBatch pSB_GhostShields = GhostSpriteBatchMan.Add(SpriteBatch.Name.Shields);

            //---------------------------------------------------------------------------------------------------------
            // GameObject
            //---------------------------------------------------------------------------------------------------------

            AnimationSprite pAnimSpriteSquid   = new AnimationSprite(GameSprite.Name.Squid);
            AnimationSprite pAnimSpriteCrab    = new AnimationSprite(GameSprite.Name.Crab);
            AnimationSprite pAnimSpriteOctopus = new AnimationSprite(GameSprite.Name.Octopus);

            pAnimSpriteSquid.Attach(Image.Name.SquidB);
            pAnimSpriteSquid.Attach(Image.Name.SquidA);
            pAnimSpriteCrab.Attach(Image.Name.CrabB);
            pAnimSpriteCrab.Attach(Image.Name.CrabA);
            pAnimSpriteOctopus.Attach(Image.Name.OctopusB);
            pAnimSpriteOctopus.Attach(Image.Name.OctopusA);

            TimerMan.Add(TimerEvent.Name.SquidAnimation, pAnimSpriteSquid, pMoveRate);
            TimerMan.Add(TimerEvent.Name.CrabAnimation, pAnimSpriteCrab, pMoveRate);
            TimerMan.Add(TimerEvent.Name.OctopusAnimation, pAnimSpriteOctopus, pMoveRate);

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

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

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

            WallBottom pWallBottom = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.NullObject, 336, 35, 750, 10);

            pWallBottom.ActivateCollisionSprite(pSB_Box);
            pWallGroup.Add(pWallBottom);

            WallRight pWallRight = new WallRight(GameObject.Name.WallRight, GameSprite.Name.NullObject, 722, 384, 120, 765);

            pWallRight.ActivateCollisionSprite(pSB_Box);
            pWallGroup.Add(pWallRight);

            WallLeft pWallLeft = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.NullObject, -45, 384, 120, 765);

            pWallLeft.ActivateCollisionSprite(pSB_Box);
            pWallGroup.Add(pWallLeft);

            WallTop pWallTop = new WallTop(GameObject.Name.WallTop, GameSprite.Name.NullObject, 336, 685, 750, 10);

            pWallTop.ActivateCollisionSprite(pSB_Box);
            pWallGroup.Add(pWallTop);

            GameObjectMan.Attach(pWallGroup);

            //---------------------------------------------------------------------------------------------------------
            // Create Bumper
            //---------------------------------------------------------------------------------------------------------

            BumperGroup pBumperGroup = new BumperGroup(GameObject.Name.BumperGroup, GameSprite.Name.NullObject, 0.0f, 0.0f);

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

            BumperRight pBumperRight = new BumperRight(GameObject.Name.BumperRight, GameSprite.Name.NullObject, 650, 55, 15, 20);

            pBumperRight.ActivateCollisionSprite(pSB_Box);
            pBumperGroup.Add(pBumperRight);

            BumperLeft pBumperLeft = new BumperLeft(GameObject.Name.BumperLeft, GameSprite.Name.NullObject, 20, 55, 15, 20);

            pBumperLeft.ActivateCollisionSprite(pSB_Box);
            pBumperGroup.Add(pBumperLeft);

            GameObjectMan.Attach(pBumperGroup);

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

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

            pShipRoot.ActivateCollisionSprite(pSB_Box);
            GameObjectMan.Attach(pShipRoot);
            ShipMan.Create(new SndObserver(sndEngine, SndObserver.Name.ShootMissile));

            Ship pShip = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 50, 20, null);

            pShip.ActivateCollisionSprite(pSB_Box);
            pShip.ActivateGameSprite(pSB_Aliens);
            pShipRoot.Add(pShip);

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

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

            pBombRoot.ActivateCollisionSprite(pSB_Box);

            GameObjectMan.Attach(pBombRoot);

            //---------------------------------------------------------------------------------------------------------
            // Explosion
            //---------------------------------------------------------------------------------------------------------

            ExplosionFactory explosionFactory = new ExplosionFactory(SpriteBatch.Name.Aliens, SpriteBatch.Name.Boxes);
            ExplosionGroup   pExplosionGroup  = (ExplosionGroup)explosionFactory.Create(GameObject.Name.ExplosionGroup, GameSprite.Name.NullObject);

            GameObjectMan.Attach(pExplosionGroup);

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

            MissileGroup pMissileGroup = new MissileGroup(GameObject.Name.MissileGroup, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);

            pMissileGroup.ActivateGameSprite(pSB_Aliens);
            pMissileGroup.ActivateCollisionSprite(pSB_Box);
            GameObjectMan.Attach(pMissileGroup);

            //---------------------------------------------------------------------------------------------------------
            // Create Aliens
            //---------------------------------------------------------------------------------------------------------
            AlienGroup pAlienGroup;

            if (SceneStateGame.loadGhost == false)
            {
                GameObject pGameObj;
                AlienMan.Create();

                AlienFactory alienFactory = new AlienFactory(SpriteBatch.Name.Aliens, SpriteBatch.Name.Boxes);
                pAlienGroup = (AlienGroup)alienFactory.Create(GameObject.Name.AlienGroup, AlienCategory.Type.Group);

                for (int i = 0; i < 11; i++)
                {
                    float x = 100.0f + 35 * (i % 11);

                    GameObject pGameObjCol = alienFactory.Create(GameObject.Name.AlienColumn, AlienCategory.Type.Column, pAlienGroup);

                    pGameObj = alienFactory.Create(GameObject.Name.Squid, AlienCategory.Type.Squid, pGameObjCol, x, baseY);
                    pGameObj = alienFactory.Create(GameObject.Name.Crab, AlienCategory.Type.Crab, pGameObjCol, x, baseY - 30);
                    pGameObj = alienFactory.Create(GameObject.Name.Crab, AlienCategory.Type.Crab, pGameObjCol, x, baseY - 30 * 2);
                    pGameObj = alienFactory.Create(GameObject.Name.Octopus, AlienCategory.Type.Octopus, pGameObjCol, x, baseY - 30 * 3);
                    pGameObj = alienFactory.Create(GameObject.Name.Octopus, AlienCategory.Type.Octopus, pGameObjCol, x, baseY - 30 * 4);
                }
            }
            else
            {
                GameObjectNode pGhostGameObjNode = GhostGameObjectMan.Find(GameObject.Name.AlienGroup);

                pAlienGroup = (AlienGroup)pGhostGameObjNode.pGameObj;
                ForwardIterator pFor = new ForwardIterator(pAlienGroup);

                Component pNode = pFor.First();
                while (!pFor.IsDone())
                {
                    GameObject pGameObj = (GameObject)pNode;

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

                    pNode = pFor.Next();
                }
                GhostGameObjectMan.Remove(pGhostGameObjNode);
            }

            GameObjectMan.Attach(pAlienGroup);

            MovementSprite pMvSprite = new MovementSprite(pAlienGroup);

            pMvSprite.Attach(10.0f, 20.0f, new SndObserver(sndEngine, SndObserver.Name.AlienMove4, 0.5f));
            pMvSprite.Attach(10.0f, 20.0f, new SndObserver(sndEngine, SndObserver.Name.AlienMove3, 0.5f));
            pMvSprite.Attach(10.0f, 20.0f, new SndObserver(sndEngine, SndObserver.Name.AlienMove2, 0.5f));
            pMvSprite.Attach(10.0f, 20.0f, new SndObserver(sndEngine, SndObserver.Name.AlienMove1, 0.5f));
            TimerMan.Add(TimerEvent.Name.AlienMovement, pMvSprite, pMoveRate);

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

            pUFORoot.ActivateCollisionSprite(pSB_Box);
            GameObjectMan.Attach(pUFORoot);
            UFOMan.Create(new SndObserver(sndEngine, SndObserver.Name.UFOFlyHigh, 0.2f, true));

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

            ShieldFactory shieldFactory = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Boxes);
            ShieldRoot    pShieldRoot   = (ShieldRoot)shieldFactory.Create(ShieldCategory.Type.Root, GameObject.Name.NullObject);

            GameObjectMan.Attach(pShieldRoot);

            // load by column
            for (int i = 0; i < 4; i++)
            {
                int   j           = 0;
                float start_x     = 86.0f + i * 146;
                float start_y     = 100.0f;
                float off_x       = 0;
                float brickWidth  = 10.0f;
                float brickHeight = 5.0f;

                ShieldGrid pShieldGrid = (ShieldGrid)shieldFactory.Create(ShieldCategory.Type.Grid, GameObject.Name.NullObject, pShieldRoot);

                GameObject pColumn;
                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 2 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 3 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 4 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 5 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 6 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 7 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.LeftTop1, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 8 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.LeftTop0, GameObject.Name.ShieldBrick, pColumn, start_x, start_y + 9 * brickHeight);

                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

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

                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

                off_x += brickWidth;
                shieldFactory.Create(ShieldCategory.Type.LeftBottom, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 2 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 3 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 4 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 5 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 6 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 7 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 8 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 9 * brickHeight);

                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

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

                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

                off_x += brickWidth;
                shieldFactory.Create(ShieldCategory.Type.RightBottom, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 2 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 3 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 4 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 5 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 6 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 7 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 8 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 9 * brickHeight);

                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

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

                pColumn = shieldFactory.Create(ShieldCategory.Type.Column, GameObject.Name.ShieldColumn_0 + j++, pShieldGrid);

                off_x += brickWidth;
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 0 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 1 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 2 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 3 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 4 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 5 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 6 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.Brick, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 7 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.RightTop1, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 8 * brickHeight);
                shieldFactory.Create(ShieldCategory.Type.RightTop0, GameObject.Name.ShieldBrick, pColumn, start_x + off_x, start_y + 9 * brickHeight);
            }

            //---------------------------------------------------------------------------------------------------------
            // ColPair
            //---------------------------------------------------------------------------------------------------------

            // associate in a collision pair
            ColPair pColPair = ColPairMan.Add(ColPair.Name.Alien_Wall, pAlienGroup, pWallGroup);

            Debug.Assert(pColPair != null);
            pColPair.Attach(new GridObserver());
            //pColPair.Attach(new SndObserver(sndEngine, SndObserver.Name.Alien_Wall));

            // Missile vs Wall
            pColPair = ColPairMan.Add(ColPair.Name.Missile_Wall, pMissileGroup, pWallGroup);
            Debug.Assert(pColPair != null);
            pColPair.Attach(new ShipReadyObserver());
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.MissileDies, GameSprite.Name.MissileDies, pExplosionGroup, 1));


            // Bomb vs Bottom
            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Wall, pBombRoot, pWallGroup);
            pColPair.Attach(new BombObserver(1));
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.BombDies, GameSprite.Name.BombDies, pExplosionGroup, 1));

            // UFO vs Wall
            pColPair = ColPairMan.Add(ColPair.Name.UFO_Wall, pUFORoot, pWallGroup);
            Debug.Assert(pColPair != null);
            pColPair.Attach(new RemoveUFOObserver());
            pColPair.Attach(new UFOReadyObserver(sndEngine));

            // Missle vs UFO
            pColPair = ColPairMan.Add(ColPair.Name.Missile_UFO, pMissileGroup, pUFORoot);
            Debug.Assert(pColPair != null);
            pColPair.Attach(new SndObserver(sndEngine, SndObserver.Name.Missile_Shield));
            pColPair.Attach(new RemoveUFOObserver2());
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new UFOReadyObserver(sndEngine));
            pColPair.Attach(new ScoreObserver());
            pColPair.Attach(new ShipReadyObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.UFODies, GameSprite.Name.UFODies, pExplosionGroup, 2));

            // missile vs alien
            pColPair = ColPairMan.Add(ColPair.Name.Alien_Missile, pMissileGroup, pAlienGroup);
            pColPair.Attach(new ShipReadyObserver());
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new ScoreObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.AlienDies, GameSprite.Name.AlienDies, pExplosionGroup, 2));
            pColPair.Attach(new GridRemoveAlienObserver());
            pColPair.Attach(new SndObserver(sndEngine, SndObserver.Name.Missile_Alien));
            pColPair.Attach(new AlienNumObserver(sndEngine));

            // Missile vs Shield
            pColPair = ColPairMan.Add(ColPair.Name.Misslie_Shield, pMissileGroup, pShieldRoot);
            pColPair.Attach(new SndObserver(sndEngine, SndObserver.Name.Missile_Shield));
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new ShipReadyObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.MissileDies, GameSprite.Name.MissileDies, pExplosionGroup, 1));

            // Bomb vs Shield
            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Shield, pBombRoot, pShieldRoot);
            pColPair.Attach(new SndObserver(sndEngine, SndObserver.Name.Bomb_Shield));
            pColPair.Attach(new BombObserver(1));
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.BombDies, GameSprite.Name.BombDies, pExplosionGroup, 1));

            // Bomb vs Ship pay attention to the order
            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Ship, pBombRoot, pShipRoot);
            pColPair.Attach(new SndObserver(sndEngine, SndObserver.Name.Bomb_Ship));
            pColPair.Attach(new BombObserver(1));
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new RemoveShipObserver());
            pColPair.Attach(new LifeObserver());
            pColPair.Attach(new AnimExplosionObserver(explosionFactory, GameObject.Name.ShipDies, GameSprite.Name.ShipDies, pExplosionGroup, 2));
            pColPair.Attach(new CreateShipObserver(sndEngine));

            // Ship vs Bumper
            pColPair = ColPairMan.Add(ColPair.Name.Ship_Bumper, pShipRoot, pBumperGroup);
            pColPair.Attach(new ShipMoveObserver());


            // Missle vs Bomb
            pColPair = ColPairMan.Add(ColPair.Name.Missile_Bomb, pMissileGroup, pBombRoot);
            Debug.Assert(pColPair != null);
            pColPair.Attach(new BombObserver(2));
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveBomb2Observer());
            pColPair.Attach(new ShipReadyObserver());
            pColPair.Attach(new ExplosionObserver(explosionFactory, GameObject.Name.MissileBombCol, GameSprite.Name.MissileBombCol, pExplosionGroup, 1));

            //---------------------------------------------------------------------------------------------------------
            // Input
            //---------------------------------------------------------------------------------------------------------

            InputSubject pInputSubject;

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

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

            pInputSubject = InputMan.GetSpaceSubject();
            pInputSubject.Attach(new ShootObserver());

            pInputSubject = InputMan.GetTSubject();
            pInputSubject.Attach(new ToggleObserver());

            pInputSubject = InputMan.GetRSubject();
            pInputSubject.Attach(new ToggleShieldObserver());

            Simulation.SetState(Simulation.State.Realtime);

            //---------------------------------------------------------------------------------------------------------
            // Font
            //---------------------------------------------------------------------------------------------------------
            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Texts, "SCORE<1>", Glyph.Name.Consolas20pt, 100, 730);
            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Texts, "HI-SCORE", Glyph.Name.Consolas20pt, 300, 730);
            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Texts, "SCORE<2>", Glyph.Name.Consolas20pt, 500, 730);
            FontMan.Add(Font.Name.Score1, SpriteBatch.Name.Texts, score1, Glyph.Name.Consolas20pt, 100, 700);
            FontMan.Add(Font.Name.ScoreHigh, SpriteBatch.Name.Texts, scoreHigh, Glyph.Name.Consolas20pt, 300, 700);
            FontMan.Add(Font.Name.Score2, SpriteBatch.Name.Texts, score2, Glyph.Name.Consolas20pt, 500, 700);

            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Texts, "X", Glyph.Name.Consolas20pt, 80, 17);
            FontMan.Add(Font.Name.Life, SpriteBatch.Name.Texts, GetPlayerLife(GetCurrPlayer()).ToString(), Glyph.Name.Consolas20pt, 100, 17);

            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Texts, "Player " + currPlayer.ToString(), Glyph.Name.Consolas20pt, 480, 17);
            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Texts, currPlayer == 1 ? "Level " + player1Level.ToString() : "Level " + player2Level.ToString(), Glyph.Name.Consolas20pt, 570, 17);

            //---------------------------------------------------------------------------------------------------------
            // State settings
            //---------------------------------------------------------------------------------------------------------
            SceneStateGame.SetLoadGhost(false);
        }
Esempio n. 24
0
        public override void Initialize()
        {
            Random pRandom = new Random();

            //---------------------------------------------------------------------------------------------------------
            // Images
            //---------------------------------------------------------------------------------------------------------
            ImageMan.Add(Image.Name.BlueAlien, Texture.Name.Aliens, new Azul.Rect(341, 337, 65, 64));
            ImageMan.Add(Image.Name.BlueAlien2, Texture.Name.Aliens, new Azul.Rect(464, 65, 64, 63));
            ImageMan.Add(Image.Name.GreenAlien, Texture.Name.Aliens, new Azul.Rect(27, 337, 79, 64));
            ImageMan.Add(Image.Name.GreenAlien2, Texture.Name.Aliens, new Azul.Rect(253, 64, 84, 65));
            ImageMan.Add(Image.Name.RedAlien, Texture.Name.Aliens, new Azul.Rect(647, 200, 72, 65));
            ImageMan.Add(Image.Name.RedAlien2, Texture.Name.Aliens, new Azul.Rect(26, 201, 94, 65));
            ImageMan.Add(Image.Name.Explosion, Texture.Name.Aliens, new Azul.Rect(488, 488, 75, 48));
            ImageMan.Add(Image.Name.Explosion_Ground, Texture.Name.Aliens, new Azul.Rect(328, 489, 84, 48));
            ImageMan.Add(Image.Name.UFO, Texture.Name.Aliens, new Azul.Rect(120, 489, 98, 49));

            ImageMan.Add(Image.Name.Missile, Texture.Name.Aliens, new Azul.Rect(267, 501, 9, 34));
            ImageMan.Add(Image.Name.Ship, Texture.Name.Birds2, new Azul.Rect(9, 92, 31, 19));

            ImageMan.Add(Image.Name.Wall, Texture.Name.Birds, new Azul.Rect(40, 185, 20, 10));
            ImageMan.Add(Image.Name.WallBottom, Texture.Name.Birds, new Azul.Rect(40, 185, 20, 1));

            ImageMan.Add(Image.Name.BombStraight, Texture.Name.Birds, new Azul.Rect(110, 100, 7, 49));
            ImageMan.Add(Image.Name.BombZigZag, Texture.Name.Birds, new Azul.Rect(132, 100, 20, 50));
            ImageMan.Add(Image.Name.BombCross, Texture.Name.Birds, new Azul.Rect(219, 103, 19, 47));

            ImageMan.Add(Image.Name.Brick, Texture.Name.Birds, new Azul.Rect(20, 210, 10, 5));
            ImageMan.Add(Image.Name.BrickLeft_Top0, Texture.Name.Birds, new Azul.Rect(15, 180, 10, 5));
            ImageMan.Add(Image.Name.BrickLeft_Top1, Texture.Name.Birds, new Azul.Rect(15, 185, 10, 5));
            ImageMan.Add(Image.Name.BrickLeft_Bottom, Texture.Name.Birds, new Azul.Rect(35, 215, 10, 5));
            ImageMan.Add(Image.Name.BrickRight_Top0, Texture.Name.Birds, new Azul.Rect(75, 180, 10, 5));
            ImageMan.Add(Image.Name.BrickRight_Top1, Texture.Name.Birds, new Azul.Rect(75, 185, 10, 5));
            ImageMan.Add(Image.Name.BrickRight_Bottom, Texture.Name.Birds, new Azul.Rect(55, 215, 10, 5));

            //---------------------------------------------------------------------------------------------------------
            // Game Sprites
            //---------------------------------------------------------------------------------------------------------
            GameSpriteMan.Add(GameSprite.Name.BlueAlien, Image.Name.BlueAlien, 100, 150, 30, 30);
            GameSpriteMan.Add(GameSprite.Name.RedAlien, Image.Name.RedAlien, 200, 150, 30, 30);
            GameSpriteMan.Add(GameSprite.Name.GreenAlien, Image.Name.GreenAlien, 300, 150, 30, 30);
            GameSpriteMan.Add(GameSprite.Name.UFO, Image.Name.UFO, 120, 489, 70, 25);
            GameSpriteMan.Add(GameSprite.Name.Explosion_Ground, Image.Name.Explosion_Ground, 328, 489, 30, 20);
            GameSpriteMan.Add(GameSprite.Name.Explosion, Image.Name.Explosion, 120, 489, 30, 20);

            GameSpriteMan.Add(GameSprite.Name.Missile, Image.Name.Missile, -100, -100, 3, 12);
            GameSpriteMan.Add(GameSprite.Name.Ship, Image.Name.Ship, 500, 100, 50, 20);
            GameSpriteMan.Add(GameSprite.Name.ShipInactive, Image.Name.Ship, 500, 100, 50, 20);
            GameSpriteMan.Add(GameSprite.Name.Wall, Image.Name.Wall, 448, 900, 850, 30);
            GameSpriteMan.Add(GameSprite.Name.WallBottom, Image.Name.WallBottom, 448, 900, 850, 1);

            GameSpriteMan.Add(GameSprite.Name.BombZigZag, Image.Name.BombZigZag, 200, 200, 8, 25);
            GameSpriteMan.Add(GameSprite.Name.BombStraight, Image.Name.BombStraight, 110, 100, 8, 25);
            GameSpriteMan.Add(GameSprite.Name.BombDagger, Image.Name.BombCross, 100, 100, 8, 25);

            GameSpriteMan.Add(GameSprite.Name.Brick, Image.Name.Brick, 50, 25, 10, 5);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftTop0, Image.Name.BrickLeft_Top0, 50, 25, 10, 5);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftTop1, Image.Name.BrickLeft_Top1, 50, 25, 10, 5);
            GameSpriteMan.Add(GameSprite.Name.Brick_LeftBottom, Image.Name.BrickLeft_Bottom, 50, 25, 10, 5);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightTop0, Image.Name.BrickRight_Top0, 50, 25, 10, 5);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightTop1, Image.Name.BrickRight_Top1, 50, 25, 10, 5);
            GameSpriteMan.Add(GameSprite.Name.Brick_RightBottom, Image.Name.BrickRight_Bottom, 50, 25, 10, 5);

            BoxSpriteMan.Add(BoxSprite.Name.Box1, 550.0f, 500.0f, 50.0f, 150.0f, new Azul.Color(1.0f, 1.0f, 1.0f, 1.0f));
            BoxSpriteMan.Add(BoxSprite.Name.Box2, 550.0f, 100.0f, 50.0f, 100.0f);

            this.poSpriteBatchMan = new SpriteBatchMan(3, 1);
            SpriteBatchMan.SetActive(this.poSpriteBatchMan);

            this.poGameObjectMan = new GameObjectMan(10, 2);
            GameObjectMan.SetActive(this.poGameObjectMan);

            this.poInputMan = new InputMan();
            InputMan.SetActive(this.poInputMan);

            this.poTimerMan = new TimerMan();
            TimerMan.SetActive(this.poTimerMan);

            //---------------------------------------------------------------------------------------------------------
            // SpriteBatches
            //---------------------------------------------------------------------------------------------------------
            SpriteBatch pSB_Box     = SpriteBatchMan.Add(SpriteBatch.Name.Boxes, 100, false);
            SpriteBatch pSB_Texts   = SpriteBatchMan.Add(SpriteBatch.Name.Texts, 100, true);
            SpriteBatch pSB_Shields = SpriteBatchMan.Add(SpriteBatch.Name.Shields, 100, true);
            SpriteBatch pSB_Aliens  = SpriteBatchMan.Add(SpriteBatch.Name.Aliens, 100, true);
            SpriteBatch pSB_Bombs   = SpriteBatchMan.Add(SpriteBatch.Name.Bombs, 100, true);

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

            GameObjectMan.Attach(pShipRoot);
            Ship pShip = ShipMan.CreateShip();

            //---------------------------------------------------------------------------------------------------------
            // Player
            //---------------------------------------------------------------------------------------------------------
            Player pPlayer = PlayerMan.GetCurrentPlayer(pShip);

            pShip.SetPlayer(pPlayer);

            //---------------------------------------------------------------------------------------------------------
            // Aliens
            //---------------------------------------------------------------------------------------------------------
            AlienFactory aF = new AlienFactory(SpriteBatch.Name.Aliens, SpriteBatch.Name.Boxes);
            // Do this somewhere else ..
            int yPos = 475;

            if (pPlayer.nCurrLevel == 2)
            {
                yPos -= 40;
            }
            AlienGrid pGrid      = aF.CreateGrid(200, yPos);
            float     pGridDelta = 0.2f;

            if (pPlayer.nCurrLevel == 2)
            {
                pGridDelta = 0.3f;
            }

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

            pMissileGroup.ActivateGameSprite(pSB_Aliens);
            GameObjectMan.Attach(pMissileGroup);

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

            pBombRoot.ActivateCollisionSprite(pSB_Box);
            pBombRoot.ActivateGameSprite(pSB_Bombs);
            GameObjectMan.Attach(pBombRoot);

            //---------------------------------------------------------------------------------------------------------
            // Input
            //---------------------------------------------------------------------------------------------------------
            InputSubject pInputSubject;

            pInputSubject = InputMan.GetArrowRightSubject();
            pInputSubject.Attach(new MoveRightObserver(pShip));

            pInputSubject = InputMan.GetArrowLeftSubject();
            pInputSubject.Attach(new MoveLeftObserver(pShip));

            pInputSubject = InputMan.GetSpaceSubject();
            pInputSubject.Attach(new ShootObserver(pShip));

            pInputSubject = InputMan.GetPeriodSubject();
            pInputSubject.Attach(new ToggleRenderBoxSpriteObserver());

            pInputSubject = InputMan.GetCommaSubject();
            pInputSubject.Attach(new ToggleShieldBricksObserver());

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

            pWallGroup.ActivateGameSprite(pSB_Aliens);

            WallTop pWallTop = new WallTop(GameObject.Name.WallTop, GameSprite.Name.Wall, 400, 750, 700, 15);

            pWallTop.ActivateCollisionSprite(pSB_Aliens);

            WallBottom pWallBottom = new WallBottom(GameObject.Name.WallBottom, GameSprite.Name.WallBottom, 400, 30, 850, 1);

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

            WallLeft pWallLeft = new WallLeft(GameObject.Name.WallLeft, GameSprite.Name.Wall, 0, 300, 15, 600);

            pWallLeft.ActivateCollisionSprite(pSB_Box);

            WallRight pWallRight = new WallRight(GameObject.Name.WallRight, GameSprite.Name.Wall, 800, 300, 15, 600);

            pWallRight.ActivateCollisionSprite(pSB_Box);

            pWallGroup.Add(pWallTop);
            pWallGroup.Add(pWallBottom);
            pWallGroup.Add(pWallRight);
            pWallGroup.Add(pWallLeft);
            GameObjectMan.Attach(pWallGroup);

            //---------------------------------------------------------------------------------------------------------
            // Shield
            //---------------------------------------------------------------------------------------------------------
            ShieldFactory SF           = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Boxes, GameObject.Name.ShieldRoot1);
            Composite     pShieldRoot1 = SF.CreateShield(50.0f, 100.0f);

            GameObjectMan.Attach(pShieldRoot1);

            SF = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Boxes, GameObject.Name.ShieldRoot2);
            Composite pShieldRoot2 = SF.CreateShield(200.0f, 100.0f);

            GameObjectMan.Attach(pShieldRoot2);

            SF = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Boxes, GameObject.Name.ShieldRoot3);
            Composite pShieldRoot3 = SF.CreateShield(500.0f, 100.0f);

            GameObjectMan.Attach(pShieldRoot3);

            SF = new ShieldFactory(SpriteBatch.Name.Shields, SpriteBatch.Name.Boxes, GameObject.Name.ShieldRoot4);
            Composite pShieldRoot4 = SF.CreateShield(650.0f, 100.0f);

            GameObjectMan.Attach(pShieldRoot4);

            //---------------------------------------------------------------------------------------------------------
            // Collision Observers
            //---------------------------------------------------------------------------------------------------------
            ColPair pColPair;

            // Missile vs Wall
            pColPair = ColPairMan.Add(ColPair.Name.Missile_Wall, pMissileGroup, pWallGroup);
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            // Bomb vs Bottom
            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Wall, pBombRoot, pWallGroup);
            pColPair.Attach(new RemoveBombObserver());

            // Bomb vs Missile
            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Missile, pBombRoot, pMissileGroup);
            pColPair.Attach(new RemoveMissileAndBombObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            // Bomb vs Shields
            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Shield1, pBombRoot, pShieldRoot1);
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new RemoveBrickObserver());

            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Shield2, pBombRoot, pShieldRoot2);
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new RemoveBrickObserver());

            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Shield3, pBombRoot, pShieldRoot3);
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new RemoveBrickObserver());

            pColPair = ColPairMan.Add(ColPair.Name.Bomb_Shield4, pBombRoot, pShieldRoot4);
            pColPair.Attach(new RemoveBombObserver());
            pColPair.Attach(new RemoveBrickObserver());

            // Missile vs Shields
            pColPair = ColPairMan.Add(ColPair.Name.Missile_Shield1, pMissileGroup, pShieldRoot1);
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            pColPair = ColPairMan.Add(ColPair.Name.Missile_Shield2, pMissileGroup, pShieldRoot2);
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            pColPair = ColPairMan.Add(ColPair.Name.Missile_Shield3, pMissileGroup, pShieldRoot3);
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            pColPair = ColPairMan.Add(ColPair.Name.Missile_Shield4, pMissileGroup, pShieldRoot4);
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveBrickObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            // Alien Grid vs Shields
            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_Shield1, pGrid, pShieldRoot1);
            pColPair.Attach(new RemoveBrickObserver());

            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_Shield2, pGrid, pShieldRoot2);
            pColPair.Attach(new RemoveBrickObserver());

            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_Shield3, pGrid, pShieldRoot3);
            pColPair.Attach(new RemoveBrickObserver());

            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_Shield4, pGrid, pShieldRoot4);
            pColPair.Attach(new RemoveBrickObserver());

            // Missile vs Alien
            pColPair = ColPairMan.Add(ColPair.Name.Alien_Missile, pMissileGroup, pGrid);
            pColPair.Attach(new RemoveMissileObserver());
            pColPair.Attach(new RemoveAlienObserver());
            pColPair.Attach(new ShipReadyObserver(pShip));

            // Alien Grid vs WallLeft
            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_WallLeft, pGrid, pWallLeft);
            pColPair.Attach(new AlienGridWallLeftObserver(pGridDelta));

            // Alien Grid vs WallRight
            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_WallRight, pGrid, pWallRight);
            pColPair.Attach(new AlienGridWallRightObserver(pGridDelta));

            // Alien Grid vs WallBottom
            pColPair = ColPairMan.Add(ColPair.Name.AlienGrid_WallBottom, pGrid, pWallBottom);
            pColPair.Attach(new AlienGridWallBottomObserver());

            // Ship vs Bomb
            pColPair = ColPairMan.Add(ColPair.Name.ShipBomb, pShipRoot, pBombRoot);
            pColPair.Attach(new BombObserver());

            //---------------------------------------------------------------------------------------------------------
            // Alien Animations
            //---------------------------------------------------------------------------------------------------------
            RedAlienAnimationCommand pRedAlienAnimation = new RedAlienAnimationCommand(GameSprite.Name.RedAlien);

            pRedAlienAnimation.Attach(Image.Name.RedAlien);
            pRedAlienAnimation.Attach(Image.Name.RedAlien2);
            TimerMan.Add(TimeEvent.Name.RedAlienAnimation, pRedAlienAnimation, 1.0f);

            BlueAlienAnimationCommand pBlueAlienAnimation = new BlueAlienAnimationCommand(GameSprite.Name.BlueAlien);

            pBlueAlienAnimation.Attach(Image.Name.BlueAlien);
            pBlueAlienAnimation.Attach(Image.Name.BlueAlien2);
            TimerMan.Add(TimeEvent.Name.BlueAlienAnimation, pBlueAlienAnimation, 1.0f);

            GreenAlienAnimationCommand pGreenAlienAnimation = new GreenAlienAnimationCommand(GameSprite.Name.GreenAlien);

            pGreenAlienAnimation.Attach(Image.Name.GreenAlien);
            pGreenAlienAnimation.Attach(Image.Name.GreenAlien2);
            TimerMan.Add(TimeEvent.Name.GreenAlienAnimation, pGreenAlienAnimation, 1.0f);

            //---------------------------------------------------------------------------------------------------------
            // Alien Bomb Spawns
            //---------------------------------------------------------------------------------------------------------
            BombSpawnEvent pBombSpawn = new BombSpawnEvent(pPlayer.nCurrLevel, pRandom);

            TimerMan.Add(TimeEvent.Name.BombSpawn, pBombSpawn, pRandom.Next(1, 10));

            //---------------------------------------------------------------------------------------------------------
            // Scene Play Sound
            //---------------------------------------------------------------------------------------------------------
            ScenePlaySoundCommand pScenePlaySound = new ScenePlaySoundCommand();

            pScenePlaySound.Attach(Sound.Name.Invader1);
            pScenePlaySound.Attach(Sound.Name.Invader2);
            pScenePlaySound.Attach(Sound.Name.Invader3);
            pScenePlaySound.Attach(Sound.Name.Invader4);
            TimerMan.Add(TimeEvent.Name.ScenePlaySound, pScenePlaySound, 1.5f);

            //---------------------------------------------------------------------------------------------------------
            // UFO
            //---------------------------------------------------------------------------------------------------------
            float           value = pRandom.Next(10, 60);
            SpawnUFOCommand pUFO  = new SpawnUFOCommand(pRandom, pWallLeft, pWallRight);

            TimerMan.Add(TimeEvent.Name.UFO, pUFO, value);

            //---------------------------------------------------------------------------------------------------------
            // Texts
            //---------------------------------------------------------------------------------------------------------
            Texture pTexture = TextureMan.Add(Texture.Name.Consolas36pt, "Consolas20pt.tga");

            GlyphMan.AddXml(Glyph.Name.Consolas20pt, "Consolas20pt.xml", Texture.Name.Consolas20pt);

            Font pFont = FontMan.Add(Font.Name.Credits00, SpriteBatch.Name.Texts, "CREDIT 00", Glyph.Name.Consolas20pt, 700, 15);

            pFont.SetColor(1.0f, 1.0f, 1.0f);

            pFont = FontMan.Add(Font.Name.Score1, SpriteBatch.Name.Texts, "SCORE <1>", Glyph.Name.Consolas20pt, 150, 585);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            Player pPlayer1 = PlayerMan.GetPlayer(1);
            string pPlayer1Score;

            if (pPlayer1 != null)
            {
                pPlayer1Score = pPlayer1.nPoints.ToString();
            }
            else
            {
                pPlayer1Score = "0";
            }
            pFont = FontMan.Add(Font.Name.Score1Value, SpriteBatch.Name.Texts, pPlayer1Score, Glyph.Name.Consolas20pt, 150, 550);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            pFont = FontMan.Add(Font.Name.HighScore, SpriteBatch.Name.Texts, "HIGH SCORE", Glyph.Name.Consolas20pt, 400, 585);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            HighScore hS = new HighScore();

            pFont = FontMan.Add(Font.Name.HighScores, SpriteBatch.Name.Texts, hS.GetScore().ToString(), Glyph.Name.Consolas20pt, 400, 550);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            pFont = FontMan.Add(Font.Name.Score2, SpriteBatch.Name.Texts, "SCORE <2>", Glyph.Name.Consolas20pt, 650, 585);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            Player pPlayer2 = PlayerMan.GetPlayer(2);
            string pPlayer2Score;

            if (pPlayer2 != null)
            {
                pPlayer2Score = pPlayer2.nPoints.ToString();
            }
            else
            {
                pPlayer2Score = "0";
            }
            pFont = FontMan.Add(Font.Name.Score2Value, SpriteBatch.Name.Texts, pPlayer2Score, Glyph.Name.Consolas20pt, 650, 550);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            // Life Totals
            pFont = FontMan.Add(Font.Name.NumLives1, SpriteBatch.Name.Texts, pPlayer.nLives.ToString(), Glyph.Name.Consolas20pt, 15, 15);
            pFont.SetColor(1.0f, 1.0f, 1.0f);

            pShip = ShipMan.CreateInactiveShip(75, 15);
            pShip = ShipMan.CreateInactiveShip(150, 15);
        }
Esempio n. 25
0
 public virtual void VisitWallRight(WallRight wr)
 {
     Debug.Assert(false);
 }
 public virtual void VisitWallRight(WallRight w)
 {
 }
Esempio n. 27
0
 public virtual void VisitWallRight(WallRight w)
 {
     Debug.WriteLine("Visit by WallRight not implemented");
     Debug.Assert(false);
 }
Esempio n. 28
0
 public override void VisitWallRight(WallRight w)
 {
     Debug.WriteLine("UFORoot WallRight");
     CollisionPair.detectCollision(w, (GameObject)this.pChild);
 }
Esempio n. 29
0
        //-----------------------------------------------------------------------------
        // Game::LoadContent()
        //		Allows you to load all content needed for your engine,
        //	    such as objects, graphics, etc.
        //-----------------------------------------------------------------------------
        public override void LoadContent()
        {
            //---------------------------------------------------------------------------------------------------------
            // Setup Managers
            //---------------------------------------------------------------------------------------------------------

            TextureMan.Create(1, 1);
            ImageMan.Create(5, 2);
            GameSpriteMan.Create(4, 2);
            BoxSpriteMan.Create(3, 1);
            SpriteBatchMan.Create(3, 1);
            TimerMan.Create(3, 1);
            ProxyMan.Create(10, 1);
            GameObjectMan.Create(10, 5);
            ColPairMan.Create(3, 1);
            GlyphMan.Create(3, 1);
            FontMan.Create(1, 1);
            //---------------------------------------------------------------------------------------------------------
            // Sound Experiment
            //---------------------------------------------------------------------------------------------------------
            SoundMan.Create(5, 3);
            SoundMan.LoadAll();
            // play a sound file
            SoundMan.PlayMusic(Sound.Name.Snd_Theme);
            SoundMan.Find(Sound.Name.Snd_Theme).SetVolume(0.2f);

            //---------------------------------------------------------------------------------------------------------
            // Load the Textures
            //---------------------------------------------------------------------------------------------------------

            TextureMan.Add(Texture.Name.Birds, "Birds.tga");
            TextureMan.Add(Texture.Name.PacMan, "PacMan.tga");

            TextureMan.Add(Texture.Name.Consolas, "Consolas20pt.tga");
            TextureMan.Add(Texture.Name.Invader_3, "Invaders_3.tga");
            TextureMan.Add(Texture.Name.Invader_4, "Invaders_4.tga");
            TextureMan.LoadTexture();

            //---------------------------------------------------------------------------------------------------------
            // Create Images
            //---------------------------------------------------------------------------------------------------------

            // --- angry birds ---

            ImageMan.Add(Image.Name.RedBird, Texture.Name.Birds, 47, 41, 48, 46);
            ImageMan.Add(Image.Name.YellowBird, Texture.Name.Birds, 124, 34, 60, 56);
            ImageMan.Add(Image.Name.GreenBird, Texture.Name.Birds, 246, 135, 99, 72);
            ImageMan.Add(Image.Name.WhiteBird, Texture.Name.Birds, 139, 131, 84, 97);
            ImageMan.Add(Image.Name.BlueBird, Texture.Name.Birds, 301, 49, 33, 33);
            // --- Pacman Ghosts ---

            ImageMan.Add(Image.Name.RedGhost, Texture.Name.PacMan, 616, 148, 33, 33);
            ImageMan.Add(Image.Name.PinkGhost, Texture.Name.PacMan, 663, 148, 33, 33);
            ImageMan.Add(Image.Name.BlueGhost, Texture.Name.PacMan, 710, 148, 33, 33);
            ImageMan.Add(Image.Name.OrangeGhost, Texture.Name.PacMan, 757, 148, 33, 33);

            // --- Alians ---
            ImageMan.LoadImage();

            //---------------------------------------------------------------------------------------------------------
            // Create Sprites
            //---------------------------------------------------------------------------------------------------------

            // --- BoxSprites ---

            BoxSpriteMan.Add(550.0f, 500.0f, 50.0f, 150.0f, new Azul.Color(1.0f, 1.0f, 1.0f, 1.0f));
            BoxSpriteMan.Add(550.0f, 100.0f, 50.0f, 100.0f);

            GameSpriteMan.Add(GameSprite.Name.RedBird, Image.Name.RedBird, 50, 500, 50, 50);
            GameSpriteMan.Add(GameSprite.Name.YellowBird, Image.Name.YellowBird, 300, 400, 50, 50);
            GameSpriteMan.Add(GameSprite.Name.GreenBird, Image.Name.GreenBird, 400, 200, 50, 50);
            GameSpriteMan.Add(GameSprite.Name.WhiteBird, Image.Name.WhiteBird, 600, 200, 100, 100);
            GameSpriteMan.Add(GameSprite.Name.BlueBird, Image.Name.BlueBird, 50, 50, 50, 50);

            GameSpriteMan.Add(GameSprite.Name.RedGhost, Image.Name.RedGhost, 100, 300, 100, 100);
            GameSpriteMan.Add(GameSprite.Name.PinkGhost, Image.Name.PinkGhost, 300, 300, 100, 100);
            GameSpriteMan.Add(GameSprite.Name.BlueGhost, Image.Name.BlueGhost, 500, 300, 100, 100);
            GameSpriteMan.Add(GameSprite.Name.OrangeGhost, Image.Name.OrangeGhost, 700, 300, 100, 100);

            GameSpriteMan.LoadGameSprite();
            // Create SpriteBatch
            //---------------------------------------------------------------------------------------------------------

            SpriteBatch pSB_Texts   = SpriteBatchMan.Add(SpriteBatch.Name.Batch_Texts);
            SpriteBatch pSB_Birds   = SpriteBatchMan.Add(SpriteBatch.Name.Batch_AngryBirds);
            SpriteBatch pSB_Alieans = SpriteBatchMan.Add(SpriteBatch.Name.Batch_Aliens);
            SpriteBatch pSB_Box     = SpriteBatchMan.Add(SpriteBatch.Name.Batch_Boxes);

            //---------------------------------------------------------------------------------------------------------
            // Attach to Sprite Batch
            //---------------------------------------------------------------------------------------------------------


            pSB_Birds.Attach(GameSprite.Name.RedBird);
            pSB_Birds.Attach(GameSprite.Name.YellowBird);
            pSB_Birds.Attach(GameSprite.Name.GreenBird);
            pSB_Birds.Attach(GameSprite.Name.WhiteBird);


            //---------------------------------------------------------------------------------------------------------
            // Proxy
            //---------------------------------------------------------------------------------------------------------

            // create 10 proxies
            for (int i = 0; i < 10; i++)
            {
                ProxySprite pProxy = ProxyMan.Add(GameSprite.Name.YellowBird);
                pProxy.x = 50.0f + 70 * i;
                pProxy.y = 100.0f;
                pSB_Birds.Attach(pProxy);
            }
            //---------------------------------------------------------------------------------------------------------
            // Game Object
            //---------------------------------------------------------------------------------------------------------

            //---------------------------------------------------------------------------------------------------------
            // Create Birds
            //---------------------------------------------------------------------------------------------------------

            // create the factory

            BirdFactory BF    = new BirdFactory(SpriteBatch.Name.Batch_AngryBirds);
            BirdGrid    pGrid = (BirdGrid)BF.Create(GameObject.Name.BirdGrid, BirdCategory.Type.Grid);

            GameObjectMan.Attach(pGrid);
            BF.LoadAll(pGrid);


            AliensFactory af         = new AliensFactory(SpriteBatch.Name.Batch_Aliens);
            GameObject    pAlienGrid = af.Create(GameObject.Name.Aliens_Grid, AlienCategory.Type.Grid);

            GameObjectMan.Attach(pAlienGrid);
            af.LoadAll(pAlienGrid);

            //pAlienGrid.Print();

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

            // Wall Root
            WallFactory WF        = new WallFactory();
            WallGrid    pWallGrid = (WallGrid)WF.Create(GameObject.Name.Wall_Grid, WallCategory.Type.Wall_Grid, 0.0f, 0.0f);

            GameObjectMan.Attach(pWallGrid);

            WallLeft   pWallLeft   = (WallLeft)WF.Create(GameObject.Name.Wall_Left, WallCategory.Type.Wall_Left, 20, 280, 20, 500);
            WallRight  pWallRight  = (WallRight)WF.Create(GameObject.Name.Wall_Right, WallCategory.Type.Wall_Right, 780, 280, 20, 500);
            WallTop    pWallTop    = (WallTop)WF.Create(GameObject.Name.Wall_Top, WallCategory.Type.Wall_Top, 400, 530, 700, 20);
            WallBottom pWallBottom = (WallBottom)WF.Create(GameObject.Name.Wall_Bottom, WallCategory.Type.Wall_Bottom, 400, 20, 700, 20);

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


            //---------------------------------------------------------------------------------------------------------
            // Create Missile
            //---------------------------------------------------------------------------------------------------------
            MissileFactory MF           = new MissileFactory(SpriteBatch.Name.Batch_Aliens);
            MissileGrid    pMissileGrid = (MissileGrid)MF.Create(GameObject.Name.Missile_Grid, MissileCategory.Type.Missile_Grid);

            GameObjectMan.Attach(pMissileGrid);

            Missile pMissile = (Missile)MF.Create(GameObject.Name.Missile, MissileCategory.Type.Missile, 405, 100);

            pMissileGrid.Add(pMissile);
            Debug.WriteLine("-------------------");


            //---------------------------------------------------------------------------------------------------------
            // ColPair
            //---------------------------------------------------------------------------------------------------------

            // associate in a collision pair
            ColPair pair = ColPairMan.Add(pMissileGrid, pAlienGrid);

            pair.Attach(new MissileHitAlienAnim());
            pair.Attach(new MissileHitAlienSnd());
            ColPairMan.Add(pWallGrid, pAlienGrid);
            ColPairMan.Add(pWallGrid, pMissileGrid);
            //---------------------------------------------------------------------------------------------------------
            // Font Experiment
            //---------------------------------------------------------------------------------------------------------
            GlyphMan.AddXml(Glyph.Name.Consolas36pt, "Consolas36pt.xml", Texture.Name.Consolas);

            FontMan.Add(Font.Name.TestMessage, SpriteBatch.Name.Batch_Texts, "ABC", Glyph.Name.Consolas36pt, 500, 500);
            FontMan.Add(Font.Name.TestOneOff, SpriteBatch.Name.Batch_Texts, "XYZ1234!#=+ZYX", Glyph.Name.Consolas36pt, 200, 200);
        }