protected override void DoAction() { //Debug.WriteLine("Attempting to Spawen an Alien!!!"); if (this.poUfo == null || this.poUfo.bMarkForDeath == true) { int UfoDirection = this.pRandom.Next(0, 2); //Debug.WriteLine("Random direction is: " + UfoDirection); this.poUfo = (UFO)this.poUfoIF.ActiveCreate(GameObject.Type.UFO, Constants.UFOPosXPos, Constants.UFOYPos); if (UfoDirection == 0) { this.poUfo.speedX *= -1.0f; this.poUfo.x = Constants.UFONegXPos; } IrrKlang.ISound pHardwareSound = SoundManager.PlaySound(Sound.Name.UFOLowPitch, true); ColPair pMissile_UFOColPair = ColPairManager.Add(ColPair.Name.Missile_UFO, this.pMissile, this.poUfo); Debug.Assert(pMissile_UFOColPair != null); ColPair pUFO_WallLeftColPair = ColPairManager.Add(ColPair.Name.UFO_WallLeft, this.poUfo, this.pWallMan.GetWallLeft()); Debug.Assert(pUFO_WallLeftColPair != null); ColPair pUFO_WallRightColPair = ColPairManager.Add(ColPair.Name.UFO_WallRight, this.poUfo, this.pWallMan.GetWallRight()); Debug.Assert(pUFO_WallRightColPair != null); // Set up missile UFO collsions pMissile_UFOColPair.Attach(new RemoveCollisionPairObserver(pMissile_UFOColPair)); pMissile_UFOColPair.Attach(new RemoveCollisionPairObserver(pUFO_WallLeftColPair)); pMissile_UFOColPair.Attach(new RemoveCollisionPairObserver(pUFO_WallRightColPair)); pMissile_UFOColPair.Attach(new ShipMissileReadyObserver()); pMissile_UFOColPair.Attach(new ShipRemoveMissileObserver()); pMissile_UFOColPair.Attach(new RemoveUFOObserver(pHardwareSound)); pMissile_UFOColPair.Attach(new AwardPointsObserver()); // Set up UFO left wall collision pUFO_WallLeftColPair.Attach(new RemoveCollisionPairObserver(pUFO_WallLeftColPair)); pUFO_WallLeftColPair.Attach(new RemoveCollisionPairObserver(pUFO_WallRightColPair)); pUFO_WallLeftColPair.Attach(new RemoveCollisionPairObserver(pMissile_UFOColPair)); pUFO_WallLeftColPair.Attach(new RemoveUFOObserver(pHardwareSound)); // Set up UFO Right wall collision pUFO_WallRightColPair.Attach(new RemoveCollisionPairObserver(pUFO_WallRightColPair)); pUFO_WallRightColPair.Attach(new RemoveCollisionPairObserver(pUFO_WallLeftColPair)); pUFO_WallRightColPair.Attach(new RemoveCollisionPairObserver(pMissile_UFOColPair)); pUFO_WallRightColPair.Attach(new RemoveUFOObserver(pHardwareSound)); } }
//----------------------------------------------------------------------------- // 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(); }
//---------------------------------------------------------------------- // 4 Wrapper methods: baseAdd, baseFind, baseRemove, baseDump //---------------------------------------------------------------------- public static ColPair Add(ColPair.Name colpairName, GameObject treeRootA, GameObject treeRootB) { return(ColPairManager.Add(colpairName, 0, treeRootA, treeRootB)); }
public Bomb Create(Type type) { InvaderCategory pInvader = InvaderGridManager.GetRandomBombDropper(this.pInvaderGrid); Bomb pBomb = null; if (pInvader != null) { float posX = pInvader.x; float posY = pInvader.y; switch (type) { case Type.Plain: pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombPlain, BoxSprite.Name.BombBox, posX, posY); break; case Type.ZigZag: pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombZigZag, BoxSprite.Name.BombBox, posX, posY); break; case Type.Dagger: pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombDagger, BoxSprite.Name.BombBox, posX, posY); break; case Type.Rolling: pBomb = new Bomb(GameObject.Name.Bomb, Sprite.Name.BombRolling, BoxSprite.Name.BombBox, posX, posY); break; default: // something is wrong Debug.Assert(false, "Bomb type not supported by this factory"); break; } // set pointer back to invader who dropped the bomb pBomb.pInvaderWhoDroppedMe = pInvader; pBomb.pInvaderWhoDroppedMe.canLaunchBomb = false; //block this invader from dropping another bomb until curren bomb dies // add it to the gameObjectManager Debug.Assert(pBomb != null); GameObjectManager.Attach(pBomb); // Attached to Batches this.pBoxSpriteBatch.Attach(pBomb.poColObj.pColSprite); this.pSpriteBatch.Attach(pBomb.pProxySprite); // Add Collision Pairs and Observers ColPair pMissile_BombColPair = ColPairManager.Add(ColPair.Name.Missile_Bomb, pBomb, ShipManager.GetMissile()); Debug.Assert(pMissile_BombColPair != null); ColPair pBomb_FloorColPair = ColPairManager.Add(ColPair.Name.Bomb_Floor, pBomb, pWallMan.GetFloor()); Debug.Assert(pBomb_FloorColPair != null); ColPair pBomb_ShipColPair = ColPairManager.Add(ColPair.Name.Bomb_Ship, pBomb, ShipManager.GetShip()); Debug.Assert(pBomb_ShipColPair != null); // Observers for Bomb vs Missile pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair)); pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair)); pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair)); pMissile_BombColPair.Attach(new ShipMissileReadyObserver()); pMissile_BombColPair.Attach(new ShipRemoveMissileObserver()); pMissile_BombColPair.Attach(new RemoveBombObserver()); //// Observers for Bomb vs Floor pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair)); pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair)); pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair)); pBomb_FloorColPair.Attach(new RemoveBombObserver()); // Observers for Bomb vs Ship pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair)); pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair)); pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair)); pBomb_ShipColPair.Attach(new RemoveShipObserver()); pBomb_ShipColPair.Attach(new RemoveBombObserver()); GameObject pShieldZone = GameObjectManager.UnsafeFind(GameObject.Name.ShieldZone); if (pShieldZone != null) { // Add Collision pair for Bomb vs Shields ColPair pBomb_ShieldColPair = ColPairManager.Add(ColPair.Name.Bomb_Shield, pBomb, pShieldZone); Debug.Assert(pBomb_ShieldColPair != null); // Added observers to previous shield pairs to remove the bomb vs shield col pair pMissile_BombColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair)); pBomb_FloorColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair)); pBomb_ShipColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair)); // Observers for Bomb vs Shield pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShieldColPair)); pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pBomb_FloorColPair)); pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pMissile_BombColPair)); pBomb_ShieldColPair.Attach(new RemoveCollisionPairObserver(pBomb_ShipColPair)); pBomb_ShieldColPair.Attach(new RemoveBombObserver()); pBomb_ShieldColPair.Attach(new RemoveShieldBrickObserver()); } } return(pBomb); }
protected virtual void PlayerTwoInit(GameManager pGameManager) { float levelSpeed = 0.75f / pGameManager.pActivePlayer.level; pGameManager.poPlayer2.pGrid = InvaderGridManager.GenerateGrid(pGameManager.pActivePlayer.level); //Debug.WriteLine("Generated Grid ({0}) for P2", pGameManager.poPlayer2.pGrid.GetHashCode()); pGameManager.poPlayer2.pShieldZone = ShieldBuilder.CreateShieldZone(175, 300, 150, 4); //--------------------------------------------------------------------------------------------------------- // Create GameSpace and Wall Objects //--------------------------------------------------------------------------------------------------------- WallManager pWallMan = new WallManager(); //Debug.WriteLine("WallLeft Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.leftWallXPos, Constants.leftWallYPos, Constants.leftWallWidth, Constants.leftWallHeight); //Debug.WriteLine("WallRight Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.rightWallXPos, Constants.rightWallYPos, Constants.rightWallWidth, Constants.rightWallHeight); //Debug.WriteLine("Ceiling Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.ceilingXPos, Constants.ceilingYPos, Constants.ceilingWidth, Constants.ceilingHeight); //Debug.WriteLine("Floor Consts x: {0}, y:{1}, width:{2}, height:{3}", Constants.floorXPos, Constants.floorYPos, Constants.floorWidth, Constants.floorHeight); //--------------------------------------------------------------------------------------------------------- // Set up Sprite Animations //--------------------------------------------------------------------------------------------------------- // Set up animations for the 3 basic Invaders AnimationSprite pSmInvaderAnim = new AnimationSprite(Sprite.Name.SmallInvader); pSmInvaderAnim.Attach(Image.Name.SmallInvader1); pSmInvaderAnim.Attach(Image.Name.SmallInvader2); AnimationSprite pMedInvaderAnim = new AnimationSprite(Sprite.Name.MediumInvader); pMedInvaderAnim.Attach(Image.Name.MediumInvader1); pMedInvaderAnim.Attach(Image.Name.MediumInvader2); AnimationSprite pLgInvaderAnim = new AnimationSprite(Sprite.Name.LargeInvader); pLgInvaderAnim.Attach(Image.Name.LargeInvader1); pLgInvaderAnim.Attach(Image.Name.LargeInvader2); // Add the Invader animations as timed events to the TimerManager TimerManager.Add(TimeEvent.Name.SmInvaderMarchAnimation, pSmInvaderAnim, levelSpeed); TimerManager.Add(TimeEvent.Name.MedInvaderMarchAnimation, pMedInvaderAnim, levelSpeed); TimerManager.Add(TimeEvent.Name.LgInvaderMarchAnimation, pLgInvaderAnim, levelSpeed); // Set up bomb animations AnimationSprite pBombZigZagAnim = new AnimationSprite(Sprite.Name.BombZigZag); pBombZigZagAnim.Attach(Image.Name.BombZigZag1); pBombZigZagAnim.Attach(Image.Name.BombZigZag2); pBombZigZagAnim.Attach(Image.Name.BombZigZag3); pBombZigZagAnim.Attach(Image.Name.BombZigZag4); AnimationSprite pBombDaggerAnim = new AnimationSprite(Sprite.Name.BombDagger); pBombDaggerAnim.Attach(Image.Name.BombDagger1); pBombDaggerAnim.Attach(Image.Name.BombDagger2); pBombDaggerAnim.Attach(Image.Name.BombDagger3); pBombDaggerAnim.Attach(Image.Name.BombDagger4); AnimationSprite pBombRollingAnim = new AnimationSprite(Sprite.Name.BombRolling); pBombRollingAnim.Attach(Image.Name.BombRolling1); pBombRollingAnim.Attach(Image.Name.BombRolling2); // Add the bomb animations as timed events to the TimerManager TimerManager.Add(TimeEvent.Name.BombAnimation, pBombZigZagAnim, 0.25f); TimerManager.Add(TimeEvent.Name.BombAnimation, pBombDaggerAnim, 0.25f); TimerManager.Add(TimeEvent.Name.BombAnimation, pBombRollingAnim, 0.25f); //--------------------------------------------------------------------------------------------------------- // Set up TimedSoundEffects //--------------------------------------------------------------------------------------------------------- TimedSoundEffects pGridMarchingSounds = new TimedSoundEffects(); pGridMarchingSounds.Attach(Sound.Name.InvaderMarch4); pGridMarchingSounds.Attach(Sound.Name.InvaderMarch3); pGridMarchingSounds.Attach(Sound.Name.InvaderMarch2); pGridMarchingSounds.Attach(Sound.Name.InvaderMarch1); TimerManager.Add(TimeEvent.Name.GridMarchSoundEffects, pGridMarchingSounds, levelSpeed); //--------------------------------------------------------------------------------------------------------- // Setting up the collisions for the player ship and missile //--------------------------------------------------------------------------------------------------------- Ship pShip = ShipManager.ActivateShip(); Missile pMissile = ShipManager.GetMissile(); //--------------------------------------------------------------------------------------------------------- // Add Collision Pairs and their Observers //--------------------------------------------------------------------------------------------------------- // Applies to both players // ship vs left wall ColPair pShip_WallLeftColPair = ColPairManager.Add(ColPair.Name.Ship_WallLeft, pShip, pWallMan.GetWallLeft()); Debug.Assert(pShip_WallLeftColPair != null); pShip_WallLeftColPair.Attach(new Ship_WallLeftObserver()); // ship vs Right wall ColPair pShip_WallRightColPair = ColPairManager.Add(ColPair.Name.Ship_WallRight, pShip, pWallMan.GetWallRight()); Debug.Assert(pShip_WallRightColPair != null); pShip_WallRightColPair.Attach(new Ship_WallRightObserver()); // Missile vs Ceiling ColPair pMissile_CeilingColPair = ColPairManager.Add(ColPair.Name.Missile_Ceiling, pMissile, pWallMan.GetCeiling()); Debug.Assert(pMissile_CeilingColPair != null); pMissile_CeilingColPair.Attach(new ShipMissileReadyObserver()); pMissile_CeilingColPair.Attach(new ShipRemoveMissileObserver()); //--------------------------------------------------------------------------------------------------------- // Set up Random UFO Spawns //--------------------------------------------------------------------------------------------------------- RandomlySpawnUFO pRandomUfoEvent = new RandomlySpawnUFO(30.0f, pMissile, pWallMan); TimerManager.Add(TimeEvent.Name.RandomlySpawnUFO, pRandomUfoEvent, 10.0f); //--------------------------------------------------------------------------------------------------------- // Create Alien Grid and random bomb drops //--------------------------------------------------------------------------------------------------------- BombFactory pBombFactory = new BombFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, pGameManager.poPlayer2.pGrid, pWallMan); RandomlySpawnBomb pRandomBombEvent = new RandomlySpawnBomb(2.0f, pBombFactory); TimerManager.Add(TimeEvent.Name.RandomBombSpawn, pRandomBombEvent, 2.0f); // Applies to players seperately // Set up timing for Grid and UFO motion TimeBasedMover pGridMover = new TimeBasedMover(pGameManager.poPlayer2.pGrid); TimerManager.Add(TimeEvent.Name.TimedGridMover, pGridMover, levelSpeed); //--------------------------------------------------------------------------------------------------------- // Create the Shields //--------------------------------------------------------------------------------------------------------- // Applies to each player seperately // grid vs leftwall ColPair pGrid_WallLeftColPair = ColPairManager.Add(ColPair.Name.Grid_WallLeft, pGameManager.poPlayer2.pGrid, pWallMan.GetWallLeft()); Debug.Assert(pGrid_WallLeftColPair != null); pGrid_WallLeftColPair.Attach(new Grid_WallLeftObserver()); // Grid vs rightwall ColPair pGrid_WallRightcolPair = ColPairManager.Add(ColPair.Name.Grid_WallRight, pGameManager.poPlayer2.pGrid, pWallMan.GetWallRight()); Debug.Assert(pGrid_WallRightcolPair != null); pGrid_WallRightcolPair.Attach(new Grid_WallRightObserver()); // Grid vs ship ColPair pShip_GridColPair = ColPairManager.Add(ColPair.Name.Ship_Grid, pShip, pGameManager.poPlayer2.pGrid); Debug.Assert(pShip_GridColPair != null); pShip_GridColPair.Attach(new RemoveShipObserver()); // Grid vs Missile ColPair pMissile_GridColPair = ColPairManager.Add(ColPair.Name.Missile_Grid, pMissile, pGameManager.poPlayer2.pGrid); Debug.Assert(pMissile_GridColPair != null); pMissile_GridColPair.Attach(new ShipRemoveMissileObserver()); pMissile_GridColPair.Attach(new ShipMissileReadyObserver()); pMissile_GridColPair.Attach(new RemoveInvaderObserver()); pMissile_GridColPair.Attach(new AwardPointsObserver()); // Grid vs Shields ColPair pGrid_ShieldZoneColPair = ColPairManager.Add(ColPair.Name.Grid_ShieldZone, pGameManager.poPlayer2.pGrid, pGameManager.poPlayer2.pShieldZone); pGrid_ShieldZoneColPair.Attach(new RemoveShieldBrickObserver()); // Missile vs Shields ColPair pMissile_ShieldZoneColPair = ColPairManager.Add(ColPair.Name.Missile_ShieldZone, pMissile, pGameManager.poPlayer2.pShieldZone); pMissile_ShieldZoneColPair.Attach(new ShipMissileReadyObserver()); pMissile_ShieldZoneColPair.Attach(new ShipRemoveMissileObserver()); pMissile_ShieldZoneColPair.Attach(new RemoveShieldBrickObserver()); // STORE Current State of managers into manager mementos pGameManager.poPlayer2.ArchiveManagerStates(pGameManager.pGame.GetTime()); }