using System; using System.Diagnostics; namespace SpaceInvaders { public class Bomb : Bombs { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- public float delta; private FallStrategy pStrategy; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public Bomb(GameObject.ObjectName name, Sprite.SpriteName spriteName, FallStrategy pStrategy, float x, float y) : base(name, spriteName, x, y, BombType.Bomb) { this.x = x; this.y = y; this.delta = 3.0f; //for now Debug.Assert(pStrategy != null); this.pStrategy = pStrategy; this.pStrategy.Reset(this.y); this.pColObj.pCollisionSprite.SetColor(1.0f, 1.0f, 0.0f); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void ResurrectBomb(float x, float y) { base.Ressurect(); this.pColObj.pCollisionSprite.SetColor(1.0f, 0.0f, 0.0f); this.x = x; this.y = y; this.delta = 3.0f; //this.pStrategy.Reset(this.y); } public float GetBoundingBoxHeight() { return this.pColObj.pCollisionRect.height; } public void SwapBombType(Sprite.SpriteName spriteName, FallStrategy newStrategy) { this.spriteName = spriteName; this.pProxy.SetProxy(spriteName); this.pStrategy = null; this.pStrategy = newStrategy; this.pStrategy.Reset(this.y); } public void MultiplyScale(float sx, float sy) { Debug.Assert(this.pProxy != null); this.pProxy.MultiplyScale(sx, sy); } public override void Remove() { //Debug.WriteLine("Removing: {0}", this.name); //reset obj this.pColObj.pCollisionRect.Set(0, 0, 0, 0); base.Update(); //update parent GameObject pParent = (GameObject)this.pParent; pParent.Update(); //call game obj to remove base.Remove(); } public override void Update() { base.Update(); this.y -= delta; this.pStrategy.Fall(this); } //------------------------------------------------------------------- // VISITOR METHODS //------------------------------------------------------------------- public override void Accept(Visitor other) { other.Visit(this); } public override void Visit(Missile missile) { CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(missile, this); pPair.NotifyListeners(); } public override void Visit(BottomWall wall) { CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(wall, this); pPair.NotifyListeners(); } public override void Visit(ShipRoot ship) { CollisionPair.CollidePair((GameObject)ForwardIterator.GetChild(ship), this); } public override void Visit(Ship ship) { CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(ship, this); pPair.NotifyListeners(); } public override void Visit(ShieldGrid shield) { CollisionPair.CollidePair((GameObject)ForwardIterator.GetChild(shield), this); } public override void Visit(ShieldRoot shield) { CollisionPair.CollidePair((GameObject)ForwardIterator.GetChild(shield), this); } public override void Visit(ShieldColumn shield) { CollisionPair.CollidePair((GameObject)ForwardIterator.GetChild(shield), this); } public override void Visit(ShieldBrick shield) { CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(shield, this); pPair.NotifyListeners(); } } // end class } // end namespace