protected override void derivedUpdate(ColSubject pColSubject) { //Debug.WriteLine("RemoveShieldBrickObserver: {0} vs {1}", pColSubject.pObjA.name, pColSubject.pObjB.name); // No Clue which is which so just check the names GameObject pGameObjA = pColSubject.pObjA; GameObject pGameObjB = pColSubject.pObjB; Debug.Assert(pGameObjA != null); Debug.Assert(pGameObjB != null); if (pGameObjA.name == GameObject.Name.ShieldBrick) { this.pShieldBrick = pGameObjA; } else if (pGameObjB.name == GameObject.Name.ShieldBrick) { this.pShieldBrick = pGameObjB; } else { Debug.Assert(false, "Neither of the objects are shields"); } if (this.pShieldBrick.bMarkForDeath == false) { this.pShieldBrick.bMarkForDeath = true; // Delay - remove object later RemoveShieldBrickObserver pObserver = new RemoveShieldBrickObserver(this); DelayedObjectManager.Attach(pObserver); } }
//---------------------------------------------------------------------------------- // Abstract Methods //---------------------------------------------------------------------------------- public override void Notify() { // Delete missile //Debug.WriteLine("RemoveBrickObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); this.pAlien = (AlienGO)this.pSubject.pObjB; Debug.Assert(this.pAlien != null); if (pAlien.bMarkForDeath == false) { //Award points int points = ((AlienGO)this.pAlien).GetPoints(); Debug.WriteLine(" +{0} points!", points); Score.IncreaseScore(points); Score.Refresh(); pAlien.bMarkForDeath = true; // Delay RemoveAlienObserver pObserver = new RemoveAlienObserver(this); DelayedObjectManager.Attach(pObserver); } else { pAlien.bMarkForDeath = true; } }
//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); }
public override void Notify() { // Delete missile //Debug.WriteLine("ShipRemoveMissileObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); // At this point we have two game objects // Actually we can control the objects in the visitor // Alphabetical ordering... A is missile, B is wall // This cast will throw an exception if I'm wrong this.pBomb = (Bomb)this.pSubject.pObjA; this.pSubB = this.pSubject.pObjB; //Debug.WriteLine("MissileRemoveObserver: --> delete missile {0}", pBomb); if (pBomb.bMarkForDeath == false) { pBomb.bMarkForDeath = true; // Delay - remove object later // TODO - reduce the new functions RemoveBombObserver pObserver = new RemoveBombObserver(this); DelayedObjectManager.Attach(pObserver); } //this.pBomb.pOwner.Handle(); }
//---------------------------------------------------------------------------------- // Abstract Methods //---------------------------------------------------------------------------------- public override void Notify() { // Delete missile //Debug.WriteLine("RemoveMissileObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); if (this.pSubject.pObjA.GetName() == GameObject.Name.Missile) { this.pMissile = (Missile)this.pSubject.pObjA; } else if (this.pSubject.pObjB.GetName() == GameObject.Name.Missile) { this.pMissile = (Missile)this.pSubject.pObjB; } Debug.Assert(this.pMissile != null); if (pMissile.bMarkForDeath == false) { pMissile.bMarkForDeath = true; // Delay RemoveMissileObserver pObserver = new RemoveMissileObserver(this); DelayedObjectManager.Attach(pObserver); } else { pMissile.bMarkForDeath = true; } }
protected override void derivedUpdate(ColSubject pColSubject) { //Debug.WriteLine("ShipRemoveMissileObserver: {0} vs {1}", pColSubject.pObjA.name, pColSubject.pObjB.name); // Missle will always be pObjA GameObject pGameObjA = pColSubject.pObjA; GameObject pGameObjB = pColSubject.pObjB; Debug.Assert(pGameObjA != null); Debug.Assert(pGameObjB != null); Missile pMissile = null; if (pGameObjA.name == GameObject.Name.Missle) { pMissile = (Missile)pGameObjA; } else if (pGameObjB.name == GameObject.Name.Missle) { pMissile = (Missile)pGameObjB; } else { Debug.Assert(false, "Neither of the objects are Missle"); } if (pMissile.bMarkForDeath == false) { pMissile.bMarkForDeath = true; // Delay - remove object later ShipRemoveMissileObserver pObserver = new ShipRemoveMissileObserver(); DelayedObjectManager.Attach(pObserver); } }
//---------------------------------------------------------------------------------- // Abstract Methods //---------------------------------------------------------------------------------- public override void Notify() { // Delete missile //Debug.WriteLine("RemoveBombObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); // Need to separate out collision-pairs since this class can handle multiple Explosion cases. switch (this.name) { case GameSprite.Name.AlienExplosion: this.pTargetObj = this.pSubject.pObjB; break; case GameSprite.Name.MissileExplosion: this.pTargetObj = this.pSubject.pObjA; break; case GameSprite.Name.BombExplosion: this.pTargetObj = this.pSubject.pObjA; break; case GameSprite.Name.SaucerExplosion: this.pTargetObj = this.pSubject.pObjB; break; case GameSprite.Name.ShipExplosionA: this.pTargetObj = this.pSubject.pObjB; break; case GameSprite.Name.ShipExplosionB: this.pTargetObj = this.pSubject.pObjB; break; default: Debug.WriteLine("There is no Default explosion. Make sure you enter the name you want."); Debug.Assert(false); break; } Debug.Assert(this.pTargetObj != null); float px = this.pTargetObj.x; float py = this.pTargetObj.y; // Factor attaches to the correct sprite batches // Could be an AlienExplosion, BombExplosion, MissileExplosion // Should be explosion sprites this.pExplosionSprite = EF.Create(this.name, px, py); this.pExplosionSprite.SetPosition(px, py); // Delay ExplosionSpriteObserver pObserver = new ExplosionSpriteObserver(this); DelayedObjectManager.Attach(pObserver); }
//---------------------------------------------------------------------------------- // Abstract Methods //---------------------------------------------------------------------------------- public override void Notify() { // Delete missile //Debug.WriteLine("RemoveBombObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); // Need to separate out collision-pairs since this class can handle multiple Explosion cases. switch (this.name) { case GameObject.Name.AlienExplosion: this.pTargetObj = this.pSubject.pObjB; break; case GameObject.Name.MissileExplosion: this.pTargetObj = this.pSubject.pObjA; break; case GameObject.Name.BombExplosion: this.pTargetObj = this.pSubject.pObjA; break; default: Debug.WriteLine("There is no Default explosion. Make sure you enter the name you want."); Debug.Assert(false); break; } Debug.Assert(this.pTargetObj != null); float px = this.pTargetObj.x; float py = this.pTargetObj.y; // Factor attaches to the correct sprite batches // Could be an AlienExplosion, BombExplosion, MissileExplosion this.pExplosion = EF.Create(this.name, px, py); // Attach the missile to the missile root GameObject pExplosionRoot = GameObjectManager.Find(GameObject.Name.ExplosionRoot); Debug.Assert(pExplosionRoot != null); // Add to GameObject Tree - {update and collisions} pExplosionRoot.Add(this.pExplosion); // Delay ExplosionObserver pObserver = new ExplosionObserver(this); DelayedObjectManager.Attach(pObserver); }
public override void Notify() { this.pAlien = this.pSubject.pObjB; if (this.pAlien.bMarkForDeath == false) { this.pAlien.bMarkForDeath = true; // Delay - remove object later // TODO - reduce the new functions RemoveAlienObserver pObserver = new RemoveAlienObserver(this); DelayedObjectManager.Attach(pObserver); } }
protected override void derivedUpdate(ColSubject pColSubject) { //Debug.WriteLine("[Observer({4})] ColPair {5}({3}) - RemoveCollisionPairObserver: {0} vs {1}({2})", pColSubject.pObjA.name, pColSubject.pObjB.name, pColSubject.pObjB.GetHashCode(), this.pColPair.GetHashCode(), this.GetHashCode(), this.pColPair.name); //Debug.WriteLine(this.pColPair + "MARKED FOR DEATH"); if (this.pColPair.bMarkForDeath == false) { //ColPairManager.PrintReport(); this.pColPair.bMarkForDeath = true; //Delay - remove object later RemoveCollisionPairObserver pObserver = new RemoveCollisionPairObserver(this); DelayedObjectManager.Attach(pObserver); } }
public override void Notify() { // Delete missile Debug.WriteLine("ShipRemoveMissileObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); this.pMissile = MissileCategory.GetMissile(this.pSubject.pObjA, this.pSubject.pObjB); Debug.WriteLine("MissileRemoveObserver: --> delete missile {0}", pMissile); if (pMissile.markForDeath == false) { pMissile.markForDeath = true; // Delay ShipRemoveMissileObserver pObserver = new ShipRemoveMissileObserver(this); DelayedObjectManager.Attach(pObserver); } }
public override void Notify() { // Delete missile //Debug.WriteLine("RemoveMissileObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); this.pBrick = (ShieldBrick)this.pSubject.pObjB; Debug.Assert(this.pBrick != null); if (pBrick.markForDeath == false) { pBrick.markForDeath = true; // Delay RemoveBrickObserver pObserver = new RemoveBrickObserver(this); DelayedObjectManager.Attach(pObserver); } }
public override void Notify() { // Delete missile //Debug.WriteLine("RemoveBombObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); //this.pBomb = BombCategory.GetBomb(this.pSubject.pObjA, this.pSubject.pObjB); this.pBomb = (Bomb)this.pSubject.pObjA; Debug.Assert(this.pBomb != null); //Debug.WriteLine("RemoveBombObserver: --> delete bomb {0}", pBomb); if (pBomb.markForDeath == false) { pBomb.markForDeath = true; // Delay //todo replace this new with a find from object pool; RemoveBombObserver pObserver = new RemoveBombObserver(this); DelayedObjectManager.Attach(pObserver); } }
public override void Notify() { // Delete missile this.pBrick = (ShieldBrick)this.pSubject.pObjB; Debug.Assert(this.pBrick != null); if (pBrick.bMarkForDeath == false) { pBrick.bMarkForDeath = true; // Delay RemoveBrickObserver pObserver = new RemoveBrickObserver(this); DelayedObjectManager.Attach(pObserver); } //else // { //pBrick.bMarkForDeath = true; //} }
public override void Notify() { // At this point we have two game objects // Actually we can control the objects in the visitor // Alphabetical ordering... A is missile, B is wall // This cast will throw an exception if I'm wrong this.pMissile = (Missile)this.pSubject.pObjB; //Debug.WriteLine("MissileRemoveObserver: --> delete missile {0}", pMissile); if (pMissile.bMarkForDeath == false) { pMissile.bMarkForDeath = true; // Delay - remove object later // TODO - reduce the new functions ShipRemoveMissileObserverAltPair pObserver = new ShipRemoveMissileObserverAltPair(this); DelayedObjectManager.Attach(pObserver); } }
public override void Notify() { //Debug.WriteLine("RemoveBombObserver: {0} {1}", this.pSubject.pObjA, this.pSubject.pObjB); this.pBomb = (Bomb)this.pSubject.pObjA; this.pShip = (Ship)this.pSubject.pObjB; Debug.Assert(this.pBomb != null); Debug.Assert(this.pShip != null); if (pShip.bMarkForDeath == false) { pShip.bMarkForDeath = true; // Delay ShipTakeDamageObserver pObserver = new ShipTakeDamageObserver(this); DelayedObjectManager.Attach(pObserver); } else { pShip.bMarkForDeath = true; } }
protected override void derivedUpdate(ColSubject pColSubject) { //Debug.WriteLine(this.GetHashCode() + " RemoveBombObserver: {0} vs {1}", pColSubject.pObjA.name, pColSubject.pObjB.name); // Bomb will always be pObjB GameObject pGameObjA = pColSubject.pObjA; GameObject pGameObjB = pColSubject.pObjB; Debug.Assert(pGameObjA != null); Debug.Assert(pGameObjB != null); if (pGameObjA.name == GameObject.Name.Bomb) { this.pBomb = (Bomb)pGameObjA; } else if (pGameObjB.name == GameObject.Name.Bomb) { this.pBomb = (Bomb)pGameObjB; } else { Debug.Assert(false, "Neither of the objects are Bombs"); } //Debug.WriteLine("Set state of Invader to true" + this.pBomb.pInvaderWhoDroppedMe); if (this.pBomb.bMarkForDeath == false) { this.pBomb.pInvaderWhoDroppedMe.canLaunchBomb = true; pBomb.bMarkForDeath = true; OneTimeAnimation pDeathAnimation = new OneTimeAnimation(Sprite.Name.BombDeath, this.pBomb.x, this.pBomb.y); pDeathAnimation.Attach(Image.Name.BombDeath); TimerManager.Add(TimeEvent.Name.InvaderDeath, pDeathAnimation, 0.1f); // Delay - remove object later RemoveBombObserver pObserver = new RemoveBombObserver(this); DelayedObjectManager.Attach(pObserver); } }
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); } }
protected override void derivedUpdate(ColSubject pColSubject) { //Debug.WriteLine("RemoveInvaderObserver: {0} vs {1}", pColSubject.pObjA.name, pColSubject.pObjB.name); if (pColSubject.pObjA.name == GameObject.Name.SmallInvader || pColSubject.pObjA.name == GameObject.Name.MediumInvader || pColSubject.pObjA.name == GameObject.Name.LargeInvader || pColSubject.pObjA.name == GameObject.Name.UFO) { this.pInvader = (InvaderCategory)pColSubject.pObjA; } else if (pColSubject.pObjB.name == GameObject.Name.SmallInvader || pColSubject.pObjB.name == GameObject.Name.MediumInvader || pColSubject.pObjB.name == GameObject.Name.LargeInvader || pColSubject.pObjB.name == GameObject.Name.UFO) { this.pInvader = (InvaderCategory)pColSubject.pObjB; } else { Debug.Assert(false, "Neither Object is not an Invader!"); } Debug.Assert(this.pInvader != null); if (pInvader.bMarkForDeath == false) { pInvader.bMarkForDeath = true; OneTimeAnimation pDeathAnimation = new OneTimeAnimation(Sprite.Name.InvaderDeath, this.pInvader.x, this.pInvader.y); pDeathAnimation.Attach(Image.Name.InvaderDeath2); pDeathAnimation.Attach(Image.Name.InvaderDeath1); TimerManager.Add(TimeEvent.Name.InvaderDeath, pDeathAnimation, 0.05f); // Delay - remove object later RemoveInvaderObserver pObserver = new RemoveInvaderObserver(this); DelayedObjectManager.Attach(pObserver); } }
public override void Notify() { GameOverObserver pObserver = new GameOverObserver(this); DelayedObjectManager.Attach(pObserver); }
public override void Notify() { //Delete Alien //Debug.WriteLine("RemoveShieldBrickObserver: {0} {1}", this.subject.gameObject_A, this.subject.gameObject_B); //set this observer's alien object as the subject's pointer object that got hit //this.pAlienObj = (AlienType)this.pSubject.pObjB; this.pAlienObj = (GameObject)this.pSubject.pObjB; Debug.Assert(this.pAlienObj != null); //set the alien object as markedForDeath if (this.pAlienObj.markForDeath == false) { this.pAlienObj.markForDeath = true; ////hold the x, y coordinates of the target alien; //int index = pAlienObj.index; //float target_X = pAlienObj.pProxySprite.x; //float target_Y = pAlienObj.pProxySprite.y; ////create the alien explosion object to temporarily replace the normal alien object in the grid //ExplodingAlien pExplodeAlien = new ExplodingAlien(GameObject.Name.ExplodingAlien, GameSprite.Name.AlienExplosion, index, target_X, target_Y); ////get the right sprite batch and activate the explosion sprite //SpriteBatch pSB_GameSprites = SpriteBatchManager.Find(SpriteBatch.Name.GameSprites); //SpriteBatch pSB_Boxes = SpriteBatchManager.Find(SpriteBatch.Name.SpriteBoxes); ////activate the game and collision sprites //pExplodeAlien.ActivateGameSprite(pSB_GameSprites); //pExplodeAlien.ActivateCollisionSprite(pSB_Boxes); ////hold a pointer to old alien and its parent; //GameObject targetAlien = (GameObject)this.pAlienObj; //GameObject parentColumn = (GameObject)targetAlien.pParent; ////make sure the parent exists; //Debug.Assert(parentColumn != null); ////remove the alien //targetAlien.Remove(); //Debug.WriteLine("removing alien {0} at x:{1}, y: {2}, sx: {3}, sy: {4}", targetAlien.pProxySprite.pSprite.GetName(), // targetAlien.pProxySprite.x, // targetAlien.pProxySprite.y, // targetAlien.pProxySprite.sx, // targetAlien.pProxySprite.sy //); ////hot swap the object pointers! ////set this remove alien's pAlienObj pointer to explosion alien; //this.pAlienObj = pExplodeAlien; ////insert the explosion alien as a child of column (where old alien used to be) //PCSTree rootGamObjTree = GameObjectManager.GetRootTree(); //Debug.Assert(rootGamObjTree != null); ////update the coordinate data to render in old spot (GameObjectManager already called update) //this.pAlienObj.Update(); //rootGamObjTree.Insert(this.pAlienObj, parentColumn); //Debug.WriteLine("added exploding alien {0} at x:{1}, y: {2}, sx: {3}, sy: {4}", pExplodeAlien.pProxySprite.pSprite.GetName(), // pExplodeAlien.pProxySprite.x, // pExplodeAlien.pProxySprite.y, // pExplodeAlien.pProxySprite.sx, // pExplodeAlien.pProxySprite.sy //); //Debug.WriteLine("added this pAlienObj {0} at x:{1}, y: {2}, sx: {3}, sy: {4}", this.pAlienObj.pProxySprite.pSprite.GetName(), // this.pAlienObj.pProxySprite.x, // this.pAlienObj.pProxySprite.y, // this.pAlienObj.pProxySprite.sx, // this.pAlienObj.pProxySprite.sy //); ////before removal, swap the sprite of JUST THIS ALIEN'S sprite image to the explosion sprite ////this forces ALL sprites to do the pop animation. dumb proxy sprites //this.pAlienObj.ChangeImage(Image.Name.AlienExplosionPop); //test - try and hot swap proxy sprite with this game sprite? //Azul.Rect pProxySpriteRect = this.pAlienObj.pProxySprite.pSprite.GetScreenRect(); //Azul.Color white = new Azul.Color(1, 1, 1); //Image pImage = ImageManager.Find(Image.Name.AlienExplosionPop); float currentTime = Simulation.GetTimeStep(); float totalTime = Simulation.GetTotalTime(); //Delay //todo create an ObserverManager or refactor DelayObjectManager to pool observer objects - avoid using new at all cost! RemoveAlienObserver observer = new RemoveAlienObserver(this); DelayedObjectManager.Attach(observer); } else { Debug.Assert(false); } }
protected override void derivedUpdate(InputSubject pInputSubject) { AdvanceGameStateObserver pObserver = new AdvanceGameStateObserver(); DelayedObjectManager.Attach(pObserver); }
protected override void derivedUpdate(ColSubject pColSubject) { SpeedUpGridMarchObserver pObserver = new SpeedUpGridMarchObserver(this.speedUpMultiplier); DelayedObjectManager.Attach(pObserver); }