private void SpawnBomb() { int random = this.pGrid.pRandom.Next(0, pGrid.colCount); Column pColumn = pGrid.GetColumn(random); //Debug.WriteLine("Firing from Column{0}", random); if (pColumn != null) { PCSTree pTree = GameObjectManager.GetRootTree(); SpriteBaseName sName = SpriteBaseName.Null; FallStrategy pStrat = null; switch (pGrid.pRandom.Next(0, 3)) { case 0: sName = SpriteBaseName.BombStraight; pStrat = new FallStraight(); break; case 1: sName = SpriteBaseName.BombDagger; pStrat = new FallDagger(); break; case 2: default: sName = SpriteBaseName.BombZigZag; pStrat = new FallZigZag(); break; } Bomb pBomb = new Bomb(GameObjectName.Bomb, sName, pStrat, pColumn.x, pColumn.pCollisionObject.pCollisionRect.minY, 0); pBomb.ActivateCollisionSprite(this.sbBoxes); pBomb.ActivateGameSprite(this.sbAliens); pTree.Insert(pBomb, this.pBombRoot); } }
//called from column ( (GameObject)this.pParent ); public override void DropBomb() { float bomb_startPosX = this.x; float bomb_startPosY = this.y; //Bomb pBomb = new Bomb(GameObject.Name.Bomb, GameSprite.Name.CrossAlienBomb, new FallStraight(), 0, bomb_startPosX, bomb_startPosY); //Debug.Assert(pBomb != null); Random r = new Random(); int randomBombType = r.Next(1, 4); Bomb pBomb = privCreateBomb(randomBombType, bomb_startPosX, bomb_startPosY); //get the root tree PCSTree rootGamObjTree = GameObjectManager.GetRootTree(); Debug.Assert(rootGamObjTree != null); //find the bomb root GameObject pBombRoot = GameObjectManager.Find(GameObject.Name.BombRoot); Debug.Assert(pBombRoot != null); rootGamObjTree.Insert(pBomb, pBombRoot); //activate the sprites SpriteBatch pSB_GameSprites = SpriteBatchManager.Find(SpriteBatch.Name.GameSprites); SpriteBatch pSB_Boxes = SpriteBatchManager.Find(SpriteBatch.Name.SpriteBoxes); pBomb.ActivateGameSprite(pSB_GameSprites); pBomb.ActivateCollisionSprite(pSB_Boxes); }
public static Missile ActivateMissile() { ShipManager pShipMan = ShipManager.privInstance(); Debug.Assert(pShipMan != null); // get the game object tree PCSTree pTree = GameObjectManager.GetRootTree(); Debug.Assert(pTree != null); //create a new missile!! // copy over safe copy (create a new one or find in game object tree) Missile pMissile = new Missile(GameObject.Name.Missile, GameSprite.Name.Missile, 0, 400, 100); pShipMan.pMissile = pMissile; // Attach missile to SpriteBatches SpriteBatch pSB_Aliens = SpriteBatchManager.Find(SpriteBatch.Name.GameSprites); SpriteBatch pSB_Boxes = SpriteBatchManager.Find(SpriteBatch.Name.SpriteBoxes); pMissile.ActivateCollisionSprite(pSB_Boxes); pMissile.ActivateGameSprite(pSB_Aliens); // Attach the missile to the missile root GameObject pMissileRoot = GameObjectManager.Find(GameObject.Name.MissileRoot); Debug.Assert(pMissileRoot != null); // Add to GameObject Tree - {update and collisions} pTree.Insert(pShipMan.pMissile, pMissileRoot); return(pShipMan.pMissile); }
public static Missile ActivateMissile() { ShipManager shipMan = ShipManager.GetInstance(); PCSTree pcsTree = GameObjectManager.GetRootTree(); Debug.Assert(pcsTree != null); Missile pMissile = new Missile(GameObjectName.Missile, SpriteBaseName.Missile, 400.0f, 100.0f, 0); pMissile.pProxySprite.pSprite.SetColor(ColorFactory.Create(ColorName.Green).pAzulColor); shipMan.pMissile = pMissile; SpriteBatch sbAliens = SpriteBatchManager.Find(SpriteBatchName.Aliens); SpriteBatch sbBoxes = SpriteBatchManager.Find(SpriteBatchName.Boxes); pMissile.ActivateCollisionSprite(sbBoxes); pMissile.ActivateGameSprite(sbAliens); GameObject pMissileRoot = GameObjectManager.Find(GameObjectName.MissileRoot); Debug.Assert(pMissileRoot != null); pcsTree.Insert(shipMan.pMissile, pMissileRoot); return(shipMan.pMissile); }
public static Ship ActivateShip(bool isCollisionBoxActive) { ShipManager shipMan = ShipManager.GetInstance(); PCSTree pcsTree = GameObjectManager.GetRootTree(); Debug.Assert(pcsTree != null); Ship pShip = new Ship(GameObjectName.Ship, SpriteBaseName.Ship, 150.0f, 100.0f); shipMan.pShip = pShip; SpriteBatch sbAliens = SpriteBatchManager.Find(SpriteBatchName.Aliens); SpriteBatch sbBoxes = SpriteBatchManager.Find(SpriteBatchName.Boxes); if (isCollisionBoxActive) { pShip.ActivateCollisionSprite(sbBoxes); } pShip.ActivateGameSprite(sbAliens); //sbAliens.Attach(pShip.pProxySprite); GameObject pShipRoot = GameObjectManager.Find(GameObjectName.ShipRoot); Debug.Assert(pShipRoot != null); pShip.Update(); pcsTree.Insert(shipMan.pShip, pShipRoot); return(shipMan.pShip); }
public static void DropBomb() { UFOManager ufoMan = UFOManager.GetInstance(); UFO ufo = ufoMan.pUFO; PCSTree pcsTree = GameObjectManager.GetRootTree(); Debug.Assert(pcsTree != null); Bomb pBomb = new Bomb(GameObjectName.UFOBomb, SpriteBaseName.UFOBomb, new FallStraight(), ufo.x, ufo.y, 0); pBomb.pProxySprite.pSprite.SetColor(ColorFactory.Create(ColorName.Red).pAzulColor); ufoMan.pBomb = pBomb; SpriteBatch sbAliens = SpriteBatchManager.Find(SpriteBatchName.Aliens); SpriteBatch sbBoxes = SpriteBatchManager.Find(SpriteBatchName.Boxes); pBomb.ActivateCollisionSprite(sbBoxes); pBomb.ActivateGameSprite(sbAliens); GameObject pBombRoot = GameObjectManager.Find(GameObjectName.BombRoot); Debug.Assert(pBombRoot != null); pcsTree.Insert(ufoMan.pBomb, pBombRoot); SetUFOBombActive(true); Debug.WriteLine("UFO Bomb dropped!"); }
public static UFO ActivateUFO(bool isCollisionBoxActive) { Debug.WriteLine("UFO has been activated!"); UFOManager ufoMan = UFOManager.GetInstance(); PCSTree pcsTree = GameObjectManager.GetRootTree(); Debug.Assert(pcsTree != null); UFOStrategy strat = new UFOMoveRight(); float x = -10.0f; if (pRandom.Next(0, 2) == 0) { strat = new UFOMoveLeft(); x = 915.0f; } UFO pUFO = new UFO(GameObjectName.UFO, SpriteBaseName.UFO, strat, x, 905.0f); ufoMan.pUFO = pUFO; UFORoot pUFORoot = (UFORoot)GameObjectManager.Find(GameObjectName.UFORoot); SpriteBatch sbAliens = SpriteBatchManager.Find(SpriteBatchName.Aliens); SpriteBatch sbBoxes = SpriteBatchManager.Find(SpriteBatchName.Boxes); if (isCollisionBoxActive) { pUFO.ActivateCollisionSprite(sbBoxes); } pUFO.ActivateGameSprite(sbAliens); pcsTree.Insert(ufoMan.pUFO, pUFORoot); SetUFOActive(true); return(ufoMan.pUFO); }
public override void execute(float currentTime) { PCSTree pTree = GameObjectManager.GetRootTree(); float value = pRandom.Next(100, 760); Bomb pBomb = new Bomb(GameObjectName.Bomb, SpriteBaseName.BombStraight, new FallStraight(), value, 850.0f, 0); pBomb.ActivateCollisionSprite(this.sbBoxes); pBomb.ActivateGameSprite(this.sbAliens); pTree.Insert(pBomb, pBombRoot); }
//----------------------------------------------------------------------------- // 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(); }
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); }
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(); }
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); }