Beispiel #1
0
        public override void Update()
        {
            GameObject gameObjectA = this.pSubject.goA;
            GameObject gameObjectB = this.pSubject.goB;
            GameObject go          = Missile.GetNonMissile(gameObjectA, gameObjectB);
            ColorName  pColorName  = ColorName.White;

            if (go.gameObjectName == GameObjectName.Bomb)
            {
                pColorName = ColorName.Orange;
            }
            else if (go.gameObjectName == GameObjectName.UFO)
            {
                pColorName = ColorName.Red;
            }
            else if (go.gameObjectName == GameObjectName.UFOBomb)
            {
                pColorName = ColorName.Yellow;
            }
            Alien       pExplosion = new Explosion(GameObjectName.Splat, SpriteBaseName.Splat, AlienType.Splat, gameObjectB, pColorName, 0);
            SpriteBatch sbAliens   = SpriteBatchManager.Find(SpriteBatchName.Aliens);
            SpriteBatch sbBoxes    = SpriteBatchManager.Find(SpriteBatchName.Boxes);

            pExplosion.ActivateGameSprite(sbAliens);
            pExplosion.ActivateCollisionSprite(sbBoxes);
            GameObjectManager.AttachTree(pExplosion);
            TimerManager.Add(TimerEventName.RemoveGameObject, TimerManager.GetCurrentTime(), TimerManager.GetCurrentTime(), new RemoveGameObjectCommand(pExplosion));
        }
Beispiel #2
0
        public void PopulateAlienGrid(float gridHeight)
        {
            //---------------------------------------------------------------------------------------------------------
            // Create GameObjects via AlienFactory
            //---------------------------------------------------------------------------------------------------------
            PCSTree      pAlienTree   = new PCSTree();
            AlienFactory alienFactory = new AlienFactory(SpriteBatchName.Aliens, pAlienTree, new Random());

            alienFactory.SetParent(null);
            Alien pGridRoot = alienFactory.Create(AlienType.Grid, GameObjectName.Grid);
            Grid  pGrid     = (Grid)pGridRoot;

            pGrid.marchSpeed    = 0.75f;
            pGrid.bombFrequency = 1.0f;
            for (int i = 0; i < 11; i++)
            {
                int additive = _horizontalSpace * i;
                alienFactory.SetParent(pGridRoot);
                Alien pColumn = alienFactory.Create(AlienType.Column, GameObjectName.Column, i, 0.0f, 0.0f);
                alienFactory.SetParent(pColumn);
                alienFactory.Create(AlienType.Squid, GameObjectName.Squid, i, 51.0f + additive, gridHeight);
                alienFactory.Create(AlienType.Crab, GameObjectName.Crab, i + 11, 51.5f + additive, gridHeight - 75.0f);
                alienFactory.Create(AlienType.Crab, GameObjectName.Crab, i, 51.5f + additive, gridHeight - 150.0f);
                alienFactory.Create(AlienType.Octopus, GameObjectName.Octopus, i + 11, 51.5f + additive, gridHeight - 225.0f);
                alienFactory.Create(AlienType.Octopus, GameObjectName.Octopus, i, 51.5f + additive, gridHeight - 300.0f);
                Column col = (Column)pColumn;
                col.alienCount   += 5;
                pGrid.alienCount += 5;
                pGrid.colCount++;
            }
            GameObjectManager.AttachTree(pGridRoot);
        }
        //this observer triggers the explosion animation before removing an alien;
        public override void Notify()
        {
            //todo - create an explosion manager that can add and remove explosion objects
            //can't simply swap image of the alien object due to proxy pattern - stupid


            //get the coordinates of the destroyed subject;
            this.pos_x = this.pSubject.pObjB.x;
            this.pos_y = this.pSubject.pObjB.y;

            //create a game object to temporarily render in the position of the destroyed subject
            //game sprites and sprite batch stuff is taken care of in the constructor;
            this.pAlienExplosionObj = new ExplodingAlien(GameObject.Name.ExplodingAlien, GameSprite.Name.AlienExplosion, 0, this.pos_x, this.pos_y);

            this.pAlienExplosionObj.x = this.pos_x;
            this.pAlienExplosionObj.y = this.pos_y;

            GameObjectManager.AttachTree(this.pAlienExplosionObj);


            this.pAlienExplosionObj.Update();


            //pass to delay manager
            AnimateAlienExplosionObserver pObserver = new AnimateAlienExplosionObserver(this);

            DelayedObjectManager.Attach(pObserver);
        }
Beispiel #4
0
 public override void Update()
 {
     if (GameManager.GetGame().GetState() is GameActiveState)
     {
         GameObject ship = ShipManager.GetShip();
         if (ship != null)
         {
             ship.Remove();
             GameObject pShipRoot = GameObjectManager.Find(GameObjectName.ShipRoot);
             pShipRoot.Remove();
         }
         Alien       pExplosion = new Explosion(GameObjectName.Explosion, SpriteBaseName.Explosion, AlienType.Explosion, ship, ColorName.Green, 0);
         SpriteBatch sbAliens   = SpriteBatchManager.Find(SpriteBatchName.Aliens);
         SpriteBatch sbBoxes    = SpriteBatchManager.Find(SpriteBatchName.Boxes);
         pExplosion.ActivateGameSprite(sbAliens);
         pExplosion.ActivateCollisionSprite(sbBoxes);
         GameObjectManager.AttachTree(pExplosion);
         Game pGame = GameManager.GetGame();
         pGame.roundNum = 1;
         ScoreManager.ClearLives();
         TimerManager.ClearTimerManager();
         pExplosion.Remove();
         pGame.Die();
         TimerManager.Add(TimerEventName.GameStart, TimerManager.GetCurrentTime() + 10.0f, 10.0f, new GameStartEvent(pGame));
     }
 }
Beispiel #5
0
        public Bomb Create(float x, float y, FallType type)
        {
            Bomb pBomb = null;

            this.pBombRoot = new BombRoot(GameObjectName.BombRoot, SpriteBaseName.Null, 0.0f, 0.0f, 0);
            this.pTree.Insert(pBombRoot, null);
            pBombRoot.ActivateCollisionSprite(this.pSpriteBatch);
            pBomb = new Bomb(GameObjectName.Bomb, SpriteBaseName.BombStraight, new FallStraight(), x, y, 0);
            this.pTree.Insert(pBomb, pBombRoot);
            pBomb.ActivateCollisionSprite(this.pSpriteBatch);
            pBomb.ActivateGameSprite(this.pSpriteBatch);
            GameObjectManager.AttachTree(pBombRoot);
            return(pBomb);
        }
Beispiel #6
0
        public static void Insert(GameObject pGameObject, GameObject pParent)
        {
            GameObjectManager goMan = GameObjectManager.GetInstance();

            Debug.Assert(pGameObject != null);

            if (pParent == null)
            {
                GameObjectManager.AttachTree(pGameObject);
            }
            else
            {
                Debug.Assert(pParent != null);

                goMan.pRoot.SetRoot(pParent);
                goMan.pRoot.Insert(pGameObject, pParent);
            }
        }
Beispiel #7
0
        public override void Update()
        {
            //Debug.WriteLine("RemoveShipObserver: {0} {1}", this.pSubject.goA, this.pSubject.goB);
            GameObject ship = ShipManager.GetShip();

            if (ship != null)
            {
                ship.Remove();
                GameObject pShipRoot = GameObjectManager.Find(GameObjectName.ShipRoot);
                pShipRoot.Remove();
            }
            Alien       pExplosion = new Explosion(GameObjectName.Explosion, SpriteBaseName.Explosion, AlienType.Explosion, ship, ColorName.Green, 0);
            SpriteBatch sbAliens   = SpriteBatchManager.Find(SpriteBatchName.Aliens);
            SpriteBatch sbBoxes    = SpriteBatchManager.Find(SpriteBatchName.Boxes);

            pExplosion.ActivateGameSprite(sbAliens);
            pExplosion.ActivateCollisionSprite(sbBoxes);
            GameObjectManager.AttachTree(pExplosion);

            Game pGame = GameManager.GetGame();
            //pGame.Pause();
            int lives = ScoreManager.UpdateLives();

            if (lives == 0)
            {
                pGame.roundNum = 1;
                TimerManager.ClearTimerManager();
                pExplosion.Remove();
                pGame.Die();
                TimerManager.Add(TimerEventName.GameStart, TimerManager.GetCurrentTime() + 10.0f, 10.0f, new GameStartEvent(pGame));
            }
            else
            {
                TimerManager.Add(TimerEventName.RemoveGameObject, TimerManager.GetCurrentTime(), TimerManager.GetCurrentTime(), new RemoveGameObjectCommand(pExplosion));
                PCSTree pRootTree = GameObjectManager.GetRootTree();
                //ShipRoot pShipRoot = (ShipRoot)GameObjectManager.Find(GameObjectName.ShipRoot);
                //pShipRoot.ActivateCollisionSprite(sbBoxes);
                //pShipRoot.ActivateGameSprite(sbAliens);
                ShipManager.Create(GameManager.GetCollisionBoxes());
            }
        }
Beispiel #8
0
        public static void Insert(GameObject pGameObj, GameObject pParent)
        {
            GameObjectManager pMan = GameObjectManager.privGetInstance();

            Debug.Assert(pGameObj != null);

            if (pParent == null)
            {
                //GameObjectManager.AttachTree(pGameObj, null);
                GameObjectManager.AttachTree(pGameObj);
            }
            else
            {
                //parent shouldn't be null if here
                Debug.Assert(pParent != null);

                //set the root as the parent and insert pGamObj as
                //a child of the parent in the same tree;
                pMan.pRootTree.SetRoot(pParent);
                pMan.pRootTree.Insert(pGameObj, pParent);
            }
        }
Beispiel #9
0
        public Alien Create(AlienType alienType, GameObjectName goName, int goIdx = 0, float x = 0.0f, float y = 0.0f)
        {
            Alien pAlien = null;

            switch (alienType)
            {
            case AlienType.Crab:
                pAlien = new Crab(goName, SpriteBaseName.Crab, x, y, goIdx);
                break;

            case AlienType.Squid:
                pAlien = new Squid(goName, SpriteBaseName.Squid, x, y, goIdx);
                break;

            case AlienType.Octopus:
                pAlien = new Octopus(goName, SpriteBaseName.Octopus, x, y, goIdx);
                break;

            case AlienType.Grid:
                pAlien = new Grid(goName, SpriteBaseName.Null, x, y, goIdx);
                GameObjectManager.AttachTree(pAlien);
                break;

            case AlienType.Column:
                pAlien = new Column(goName, SpriteBaseName.Null, x, y, goIdx, this.pRandom);
                break;

            default:
                Debug.Assert(pAlien != null);
                break;
            }
            this.pTree.Insert(pAlien, this.pParent);
            pAlien.ActivateGameSprite(this.pSpriteBatch);
            pAlien.ActivateCollisionSprite(this.pSpriteBatch);
            return(pAlien);
        }
Beispiel #10
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();
        }
Beispiel #11
0
        private ShieldRoot GenerateShield(PCSTree pRootTree, float startX, float startY, int idx)
        {
            ShieldRoot pShieldRoot = new ShieldRoot(GameObjectName.ShieldRoot, SpriteBaseName.Null, 0.0f, 0.0f, idx);

            pRootTree.Insert(pShieldRoot, null);
            GameObjectManager.AttachTree(pShieldRoot);
            ShieldFactory shieldFactory = new ShieldFactory(SpriteBatchName.Shields, SpriteBatchName.Boxes, pRootTree);

            shieldFactory.SetParent(pShieldRoot);
            ShieldCategory pShieldGrid = shieldFactory.Create(ShieldType.Grid, GameObjectName.ShieldGrid);

            int            j = 0;
            ShieldCategory pCol;

            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.ShieldColumn, j++);
            shieldFactory.SetParent(pCol);

            int i = 0;

            float start_x     = startX;
            float start_y     = startY;
            float off_x       = 0;
            float brickWidth  = 15.0f;
            float brickHeight = 10.0f;

            for (int x = 0; x < 8; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.Create(ShieldType.LeftTop1, GameObjectName.ShieldBrick, start_x, start_y + 8 * brickHeight, i++);
            shieldFactory.Create(ShieldType.LeftTop0, GameObjectName.ShieldBrick, start_x, start_y + 9 * brickHeight, i++);
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 0; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            shieldFactory.Create(ShieldType.LeftBottom, GameObjectName.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight);
            for (int x = 3; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 3; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            shieldFactory.Create(ShieldType.RightBottom, GameObjectName.ShieldBrick, start_x + off_x, start_y + 2 * brickHeight, i++);
            for (int x = 3; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 0; x < 10; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.SetParent(pShieldGrid);
            pCol = shieldFactory.Create(ShieldType.Column, GameObjectName.Column, j++);
            shieldFactory.SetParent(pCol);

            off_x += brickWidth;
            for (int x = 0; x < 8; x++)
            {
                shieldFactory.Create(ShieldType.Brick, GameObjectName.ShieldBrick, start_x + off_x, start_y + x * brickHeight, i++);
            }
            shieldFactory.Create(ShieldType.RightTop1, GameObjectName.ShieldBrick, start_x + off_x, start_y + 8 * brickHeight);
            shieldFactory.Create(ShieldType.RightTop0, GameObjectName.ShieldBrick, start_x + off_x, start_y + 9 * brickHeight);

            return(pShieldRoot);
        }
Beispiel #12
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();
        }
Beispiel #13
0
        private static Ship CreateShips()
        {
            ShipManager pShipMan = ShipManager.privInstance();

            Debug.Assert(pShipMan != null);

            // get the game object tree
            PCSTree rootGamObjTree = GameObjectManager.GetRootTree();

            Debug.Assert(rootGamObjTree != null);

            //create the root - coordinates are 0 since it's a root
            //ShipRoot pShipRoot = new ShipRoot(GameObject.Name.ShipRoot, GameSprite.Name.NullObject, 0, 0.0f, 0.0f);
            //DeathManager.Attach(shipRoot);

            //todo find the ship object from loading instead of creating a new one
            // copy over safe copy (new or find precreated game object)

            //todo - refactor this using object pooling for ships - also will need more than these 3 ships w/ two player!
            //Create 3 ships total-----------------

            //create the starting ship;
            Ship pShip = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 0, pShipMan.startShip_PosX, pShipMan.startShip_PosY);

            //set as the ship managers current ship
            pShipMan.pCurrentShip = pShip;

            // Attach the sprite to the correct sprite batch
            SpriteBatch pSB_GameSprites = SpriteBatchManager.Find(SpriteBatch.Name.GameSprites);
            SpriteBatch pSB_Boxes       = SpriteBatchManager.Find(SpriteBatch.Name.SpriteBoxes);

            pSB_GameSprites.Attach(pShip.pProxySprite);
            pShip.ActivateCollisionSprite(pSB_Boxes);


            // Attach the ship to the ship root
            // get the root (created before this function was called)
            GameObject pShipRoot = GameObjectManager.Find(GameObject.Name.ShipRoot);

            Debug.Assert(pShipRoot != null);

            // Add current ship tree to GameObject Tree - {update and collisions}
            rootGamObjTree.Insert(pShipMan.pCurrentShip, pShipRoot);

            //TESTING - CREATING 2 EXTRA SHIPS-------------------------------------------

            //extra ship one
            Ship pShipOne = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 1, pShipMan.extraShipOne_X, pShipMan.extraShip_Y);

            //add to the ship tree as well as root game object tree
            rootGamObjTree.Insert(pShipOne, pShipMan.pCurrentShip);

            // Attach the sprite to the correct sprite batch

            pSB_GameSprites.Attach(pShipOne.pProxySprite);
            pShipOne.ActivateGameSprite(pSB_GameSprites);
            pShipOne.ActivateCollisionSprite(pSB_Boxes);

            //update the position of the new ship
            pShipOne.Update();

            //extra ship two
            Ship pShipTwo = new Ship(GameObject.Name.Ship, GameSprite.Name.Ship, 2, pShipMan.extraShipTwo_X, pShipMan.extraShip_Y);


            //add to the ship tree as well as root game object tree
            rootGamObjTree.Insert(pShipTwo, pShipOne);

            // Attach the sprite to the correct sprite batch
            pSB_GameSprites.Attach(pShipTwo.pProxySprite.pSprite);
            pShipTwo.ActivateGameSprite(pSB_GameSprites);
            pShipTwo.ActivateCollisionSprite(pSB_Boxes);

            //update the position of the new ship
            pShipTwo.Update();

            //END TESTING OF CREATING 2 EXTRA SHIPS-------------------------------------------


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

            return(pShipMan.pCurrentShip);
        }