public void Reset() { this.lives = 3; this.score = 0; this.pGrid = null; this.pShieldZone = null; }
public static InvaderCategory GetRandomBombDropper(InvaderGrid pGrid) { InvaderGridManager pMan = InvaderGridManager.PrivGetInstance(); Debug.Assert(pMan != null); InvaderCategory pTmpInvader = null; // Find a random bottom row invader to drop the bomb int numColumns = pGrid.GetNumChildren(); int randomColumnIndex = pMan.pRandom.Next(numColumns); InvaderColumn pColumn = (InvaderColumn)pGrid.GetChild(randomColumnIndex); pTmpInvader = (InvaderCategory)pColumn.GetChild(0); // Check to see if the invader drop the bomb, if not go find another invader InvaderCategory pInvader = null; for (int i = 0; i < numColumns; i++) { randomColumnIndex = pMan.pRandom.Next(numColumns); pColumn = (InvaderColumn)pGrid.GetChild(randomColumnIndex); pTmpInvader = (InvaderCategory)pColumn.GetChild(0); if (pTmpInvader.canLaunchBomb) { pInvader = pTmpInvader; break; } } return(pInvader); }
public static void ActivateGrid(InvaderGrid pGrid, SpriteBatch.Name spriteBatchName, SpriteBatch.Name boxSpriteBatchName) { Debug.Assert(pGrid != null); GameObjectManager.Attach(pGrid); SpriteBatch pSpriteBatch = SpriteBatchManager.Find(spriteBatchName); Debug.Assert(pSpriteBatch != null); SpriteBatch pBoxSpriteBatch = SpriteBatchManager.Find(boxSpriteBatchName); Debug.Assert(pBoxSpriteBatch != null); pBoxSpriteBatch.Attach(pGrid.poColObj.pColSprite); pSpriteBatch.Attach(pGrid.pProxySprite); ForwardIterator pFwdItor = new ForwardIterator(pGrid); GameObject pGameObj = (GameObject)pFwdItor.Next(); while (!pFwdItor.IsDone()) { GameObjectManager.Attach(pGameObj); pBoxSpriteBatch.Attach(pGameObj.poColObj.pColSprite); pSpriteBatch.Attach(pGameObj.pProxySprite); pGameObj = (GameObject)pFwdItor.Next(); } }
// TODO maybe this becomes a init crit method and make activategrid just display the grid rather than create a new one public static InvaderGrid GenerateGrid(int level) { // Get factory for producing gameobjects and adding them to the gameobject manager and spritebatches InvaderFactory rootLevelIF = new InvaderFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes); // create the grid composite data structure InvaderGrid pGrid = (InvaderGrid)rootLevelIF.ActiveCreate(GameObject.Type.InvaderGrid, 0, 0); // Get another factory for producing gameobjects and adding them to the Grid as well as the gameobject manager and sprite batches InvaderFactory columnIF = new InvaderFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, pGrid); for (int i = 0; i < 11; i++) { InvaderColumn pColumn = (InvaderColumn)columnIF.ActiveCreate(GameObject.Type.InvaderColumn, 0, 0); InvaderFactory gridAliensIF = new InvaderFactory(SpriteBatch.Name.Sprites, SpriteBatch.Name.Boxes, pColumn); float xPos = Constants.gridXOrigin + i * Constants.gridColumnDelta; gridAliensIF.ActiveCreate(GameObject.Type.SmallInvader, xPos, Constants.smallInvaderYPos - level * 10); gridAliensIF.ActiveCreate(GameObject.Type.MediumInvader, xPos, Constants.MediumInvaderYPos1 - level * 10); gridAliensIF.ActiveCreate(GameObject.Type.MediumInvader, xPos, Constants.MediumInvaderYPos2 - level * 10); gridAliensIF.ActiveCreate(GameObject.Type.LargeInvader, xPos, Constants.LargeInvaderYPos1 - level * 10); gridAliensIF.ActiveCreate(GameObject.Type.LargeInvader, xPos, Constants.LargeInvaderYPos2 - level * 10); } pGrid.SetState(InvaderGridManager.State.NotCollingWithWall); return(pGrid); }
protected override void derivedUpdate(ColSubject pColSubject) { //Debug.WriteLine("Grid_Observer: {0} vs {1}", pColSubject.pObjA.name, pColSubject.pObjB.name); // Grid will always be pObjB GameObject pGameObjA = pColSubject.pObjA; GameObject pGameObjB = pColSubject.pObjB; Debug.Assert(pGameObjA != null); Debug.Assert(pGameObjB != null); InvaderGrid pGrid = null; if (pGameObjA.name == GameObject.Name.InvaderGrid) { pGrid = (InvaderGrid)pGameObjA; } else if (pGameObjB.name == GameObject.Name.InvaderGrid) { pGrid = (InvaderGrid)pGameObjB; } else { Debug.Assert(false, "Neither of the objects are InvaderGrid"); } pGrid.SetState(InvaderGridManager.State.CollidingRightWall); }
public override void VisitInvaderGrid(InvaderGrid pGrid) { //Debug.WriteLine("in ShieldZone, visit from InvaderGrid"); GameObject pGameObj = (GameObject)pGrid.GetFirstChild(); ColPair.FwdCollide(this, pGameObj); }
public override void VisitInvaderGrid(InvaderGrid pGrid) { //Debug.WriteLine(" --->DONE<----"); ColPair pColPair = ColPairManager.GetActiveColPair(); Debug.Assert(pColPair != null); // Always set grid as ObjB pColPair.SetCollision(this, pGrid); pColPair.NotifyListeners(); }
public static void DeactivateGrid(InvaderGrid pGrid) { Debug.Assert(pGrid != null); // Remove from SpriteBatch // Find the SBNode Debug.Assert(pGrid.pProxySprite != null); SpriteBaseNode pSBNode = pGrid.pProxySprite.GetSBNode(); // Remove it from the manager Debug.Assert(pSBNode != null); SpriteBatchManager.Remove(pSBNode); // Remove collision sprite from spriteBatch Debug.Assert(pGrid.poColObj != null); Debug.Assert(pGrid.poColObj.pColSprite != null); pSBNode = pGrid.poColObj.pColSprite.GetSBNode(); Debug.Assert(pSBNode != null); SpriteBatchManager.Remove(pSBNode); GameObjectManager.NonTreeRemove(pGrid); ForwardIterator pFwdItor = new ForwardIterator(pGrid); GameObject pGameObj = (GameObject)pFwdItor.Next(); while (!pFwdItor.IsDone()) { // Remove from SpriteBatch // Find the SBNode Debug.Assert(pGameObj.pProxySprite != null); pSBNode = pGameObj.pProxySprite.GetSBNode(); // Remove it from the manager Debug.Assert(pSBNode != null); SpriteBatchManager.Remove(pSBNode); // Remove collision sprite from spriteBatch Debug.Assert(pGameObj.poColObj != null); Debug.Assert(pGameObj.poColObj.pColSprite != null); pSBNode = pGameObj.poColObj.pColSprite.GetSBNode(); Debug.Assert(pSBNode != null); SpriteBatchManager.Remove(pSBNode); GameObjectManager.NonTreeRemove(pGameObj); pGameObj = (GameObject)pFwdItor.Next(); } }
// Creates invader And adds it to Batches or gameobject manager public GameObject ActiveCreate(GameObject.Type type, float posX, float posY) { GameObject pGameObj = null; switch (type) { case GameObject.Type.SmallInvader: pGameObj = new SmallInvader(GameObject.Name.SmallInvader, Sprite.Name.SmallInvader, BoxSprite.Name.SmallInvaderBox, posX, posY); break; case GameObject.Type.MediumInvader: pGameObj = new MediumInvader(GameObject.Name.MediumInvader, Sprite.Name.MediumInvader, BoxSprite.Name.MediumInvaderBox, posX, posY); break; case GameObject.Type.LargeInvader: pGameObj = new LargeInvader(GameObject.Name.LargeInvader, Sprite.Name.LargeInvader, BoxSprite.Name.LargeInvaderBox, posX, posY); break; case GameObject.Type.UFO: pGameObj = new UFO(GameObject.Name.UFO, Sprite.Name.UFO, BoxSprite.Name.UFOBox, posX, posY); break; case GameObject.Type.InvaderColumn: pGameObj = new InvaderColumn(GameObject.Name.InvaderColumn, BoxSprite.Name.InvaderColumnBox); break; case GameObject.Type.InvaderGrid: pGameObj = new InvaderGrid(GameObject.Name.InvaderGrid, BoxSprite.Name.InvaderGridBox); break; default: // something is wrong Debug.Assert(false, "GameObject type not supported by this factory"); break; } // add it to the gameObjectManager Debug.Assert(pGameObj != null); GameObjectManager.Attach(pGameObj); if (pGOComposite != null) { // add to grouping pGOComposite.Add(pGameObj); } // Attached to Batches this.pBoxSpriteBatch.Attach(pGameObj.poColObj.pColSprite); this.pSpriteBatch.Attach(pGameObj.pProxySprite); return(pGameObj); }
public BombFactory(SpriteBatch.Name spriteBatchName, SpriteBatch.Name boxSpriteBatchName, InvaderGrid pInvaderGrid, WallManager pWallMan) { Debug.Assert(pInvaderGrid != null); this.pInvaderGrid = pInvaderGrid; Debug.Assert(pWallMan != null); this.pWallMan = pWallMan; this.pSpriteBatch = SpriteBatchManager.Find(spriteBatchName); Debug.Assert(this.pSpriteBatch != null); this.pBoxSpriteBatch = SpriteBatchManager.Find(boxSpriteBatchName); Debug.Assert(this.pBoxSpriteBatch != null); }
public PlayerArtifact(Name name) { this.name = name; this.lives = 3; this.score = 0; this.level = 1; this.pGrid = null; this.pShieldZone = null; this.pTimerMemento = new TimerMemento(); this.pGameObjectMemento = new ManagerMemento(); this.pColPairMemento = new ManagerMemento(); this.pSpritesSBNodeMemento = new ManagerMemento(); this.pSpriteBoxesSBNodeMemento = new ManagerMemento(); }
// Creates invader but does not add it to Batches or gameobject manager public GameObject PassiveCreate(GameObject.Type type, float posX, float posY) { GameObject pGameObj = null; switch (type) { case GameObject.Type.SmallInvader: pGameObj = new SmallInvader(GameObject.Name.SmallInvader, Sprite.Name.SmallInvader, BoxSprite.Name.SmallInvaderBox, posX, posY); break; case GameObject.Type.MediumInvader: pGameObj = new MediumInvader(GameObject.Name.MediumInvader, Sprite.Name.MediumInvader, BoxSprite.Name.MediumInvaderBox, posX, posY); break; case GameObject.Type.LargeInvader: pGameObj = new LargeInvader(GameObject.Name.LargeInvader, Sprite.Name.LargeInvader, BoxSprite.Name.LargeInvaderBox, posX, posY); break; case GameObject.Type.UFO: pGameObj = new UFO(GameObject.Name.UFO, Sprite.Name.UFO, BoxSprite.Name.UFOBox, posX, posY); break; case GameObject.Type.InvaderColumn: pGameObj = new InvaderColumn(GameObject.Name.InvaderColumn, BoxSprite.Name.InvaderColumnBox); break; case GameObject.Type.InvaderGrid: pGameObj = new InvaderGrid(GameObject.Name.InvaderGrid, BoxSprite.Name.InvaderGridBox); break; default: // something is wrong Debug.Assert(false, "GameObject type not supported by this factory"); break; } if (pGOComposite != null) { // add to grouping pGOComposite.Add(pGameObj); } return(pGameObj); }
public override void Move(InvaderGrid pGrid) { if (this.alreadyMovedDown) { //Debug.WriteLine("Grid Colliding with Right Wall : Moving Left"); pGrid.speedX = -Math.Abs(pGrid.roStaticSpeedX); pGrid.speedY = 0.0f; this.Handle(pGrid); this.alreadyMovedDown = false; } else { //Debug.WriteLine("Grid Colliding with Right Wall : Moving Down"); pGrid.speedX = 0.0f; pGrid.speedY = -Math.Abs(pGrid.roStaticSpeedY); this.alreadyMovedDown = true; SpeedUpGridMarchObserver pObserver = new SpeedUpGridMarchObserver(pGrid.speedUpMultiplier); DelayedObjectManager.Attach(pObserver); } }
public virtual void VisitInvaderGrid(InvaderGrid pGrid) { // no differed to subcass Debug.WriteLine("Visit by InvaderGrid not implemented"); Debug.Assert(false); }
public override void Handle(InvaderGrid pGrid) { }
public override void Handle(InvaderGrid pGrid) { pGrid.SetState(InvaderGridManager.State.NotCollingWithWall); }
public abstract void Move(InvaderGrid pGrid);
public abstract void Handle(InvaderGrid pGrid);
public override void VisitInvaderGrid(InvaderGrid pGrid) { GameObject pGameObj = (GameObject)pGrid.GetFirstChild(); ColPair.FwdCollide(this, pGameObj); }
public override void Move(InvaderGrid pGrid) { }