using System; using System.Diagnostics; namespace SpaceInvaders { public class Missile : Missiles { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- public float delta; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public Missile(Sprite.SpriteName spriteName, float x, float y) : base(GameObject.ObjectName.Missile, spriteName, x, y) { this.x = x; this.y = y; this.delta = 10.0f; this.pColObj.pCollisionSprite.SetColor(1.0f, 1.0f, 0.0f); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void SetPosition(float x, float y) { this.x = x; this.y = y; } public void Resurrect(float x, float y) { this.x = x; this.y = y; this.delta = 8.0f; base.Ressurect(); this.pColObj.pCollisionSprite.SetColor(1.0f, 1.0f, 0.0f); } public override void Update() { base.Update(); this.y += delta; } public override void Remove() { //Debug.WriteLine("Removing: {0}", this.name); this.pColObj.pCollisionRect.Set(0.0f, 0.0f, 0.0f, 0.0f); base.Update(); //update parent (root) GameObject pParent = (GameObject)this.pParent; pParent.Update(); //remove it base.Remove(); } //------------------------------------------------------------------- // ACCEPT METHODS //------------------------------------------------------------------- public override void Accept(Visitor other) { other.Visit(this); } public override void Visit(AlienGrid alien) { //missile vs alien grid CollisionPair.CollidePair(this, (GameObject)ForwardIterator.GetChild(alien)); } public override void Visit(AlienColumn alien) { //missile vs alien col CollisionPair.CollidePair(this, (GameObject)ForwardIterator.GetChild(alien)); } public override void Visit(OctopusAlien alien) { //missile vs octopus alien CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(this, alien); pPair.NotifyListeners(); } public override void Visit(CrabAlien alien) { //missile vs crab alien CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(this, alien); pPair.NotifyListeners(); } public override void Visit(SquidAlien alien) { //missile vs squid alien CollisionPair pPair = CollisionPairMan.GetActivePair(); Debug.Assert(pPair != null); pPair.SetCollision(this, alien); pPair.NotifyListeners(); } } }