// shoot a missile public void Shoot() { // missile should be fast this.setDelta(10.0f); // for missile if (this.direction == 1f && !ProjectileTracker.MissileFlying) { ProjectileTracker.MissileHandle(); } }
// For Missile object use // When missile hits Alien public override void VisitAlien() { if (this.category == Category.Missile) { // Explode //Debug.Print("Missile exloded!"); // Reset location this.pProxy.x = 0f; this.pProxy.y = -10f; this.pProxy.Update(); // Flip Missile Handle ProjectileTracker.MissileHandle(); } }
// When projectile hits Wall public override void VisitWall() { if (this.category == Category.Missile) { // Explode // Reset location this.pProxy.x = -10f; this.pProxy.y = -10f; this.pProxy.Update(); // Flip Missile Handle ProjectileTracker.MissileHandle(); } else if (this.category == Category.Bomb) { // reset bomb location this.pProxy.x = -10f; this.pProxy.y = -10f; this.pProxy.Update(); // Explode // ReDrop immediately if (this.pProxy.pSprite.name == GameSprite.Name.DaggerBomb) { this.dropID = (new Random().Next(0, 10)); //Debug.Print("Bomb Drop ID: " + this.dropID.ToString()); ProjectileTracker.DaggerHandle(); } else if (this.pProxy.pSprite.name == GameSprite.Name.RollingBomb) { this.dropID = (new Random().Next(0, 10)); ProjectileTracker.RollingHandle(); } else if (this.pProxy.pSprite.name == GameSprite.Name.ZigZagBomb) { this.dropID = (new Random().Next(0, 10)); ProjectileTracker.ZigZagHandle(); } } else if (this.category == Category.AlienGrid) { //Debug.Print("Alien Grid collides Wall"); float oldDelta = this.pProxy.delta; this.CompositeSetDelta(oldDelta * -1f); } }
// When missile hits Shield public override void VisitShield() { if (this.category == Category.Missile) { // Explode // Reset location this.pProxy.x = 0f; this.pProxy.y = -10f; this.pProxy.Update(); // Flip Missile Handle ProjectileTracker.MissileHandle(); } else if (this.category == Category.Bomb) { // reset bomb location this.pProxy.x = -10f; this.pProxy.y = -10f; this.pProxy.Update(); // Explode // ReDrop immediately if (this.pProxy.pSprite.name == GameSprite.Name.DaggerBomb) { this.dropID = (new Random().Next(0, 10)); ProjectileTracker.DaggerHandle(); } else if (this.pProxy.pSprite.name == GameSprite.Name.RollingBomb) { this.dropID = (new Random().Next(0, 10)); ProjectileTracker.RollingHandle(); } else if (this.pProxy.pSprite.name == GameSprite.Name.ZigZagBomb) { this.dropID = (new Random().Next(0, 10)); ProjectileTracker.ZigZagHandle(); } } }
// Visitor logic // TODO: can be simplified using strategy public override void Accept(Visitor v) { if (this.category == Category.Wall) { if (this.mGameSprtName == GameSprite.Name.LeftWall) { v.VisitLeftWall(); } else if (this.mGameSprtName == GameSprite.Name.RightWall) { v.VisitRightWall(); } else { v.VisitWall(); } } else if (this.category == Category.Alien) { v.VisitAlien(); } else if (this.category == Category.Shield) { v.VisitShield(); } else if (this.category == Category.Missile) { if (ProjectileTracker.MissileFlying) { v.VisitMissile(); // Reset location this.pProxy.x = 0f; this.pProxy.y = -10f; this.pProxy.Update(); // Flip Missile Handle ProjectileTracker.MissileHandle(); } } else if (this.category == Category.Ship) { v.VisitShip(); } // If hit by missile, start self-destruction process if (((GameObject)v).category == Category.Missile || (((GameObject)v).category == Category.Bomb && this.category != Category.Missile)) { // Play explosion animation Debug.Print(this.category + " hit by" + ((GameObject)v).category); // If ship, trigger next round if (this.category == Category.Ship) { SoundUtility.getInstance().playExplosion(); SpaceInvaders.currentState.Handle(); return; } // If Alien, incremente score if (this.mGameSprtName == GameSprite.Name.Octopus) { GlobalPlayerStats.incrementScore(10); } else if (this.mGameSprtName == GameSprite.Name.Crab) { GlobalPlayerStats.incrementScore(20); } else if (this.mGameSprtName == GameSprite.Name.Squid) { GlobalPlayerStats.incrementScore(20); } // set itself as not collidable, if it's not wall if (this.category != Category.Wall) { if (this.category == Category.Alien) { SoundUtility.getInstance().killed(); this.mGameSprite.ShowExplosion(); } else if (this.category == Category.UFO) { SoundUtility.getInstance().killed(); ((UFOProxy)this.pProxy).reset(); GlobalPlayerStats.incrementScore(300); return; } else { SoundUtility.getInstance().playExplosion(); } this.collidable = false; // Remove itself from active GameObjectManager.getInstance().Remove(this); } } }