GAM456-SpaceInvaders / SpaceInvaders / 4_GameObject / Shield / ShieldColumn.cs
ShieldColumn.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class ShieldColumn : Composite
    {
        //-------------------------------------------------------------------
        //  CONSTRUCTION
        //-------------------------------------------------------------------

        public ShieldColumn(GameObject.ObjectName objName, Sprite.SpriteName spriteName, float x, float y) 
            : base(objName, spriteName)
        {
            this.x = x;
            this.y = y;

            this.SetCollisionColor(0.0f, 0.0f, 1.0f);
        }


        //-------------------------------------------------------------------
        //  PUBLIC METHODS
        //-------------------------------------------------------------------

        public void Resurrect(float x, float y)
        {
            this.x = x;
            this.y = y;

            this.SetCollisionColor(1.0f, 0.0f, 0.0f);
            base.Ressurect();
        }

        public override void Update()
        {
            base.UpdateBoundingBox(this);
            base.Update();
        }

        public override void Remove()
        {
            //Debug.WriteLine("Removing: {0}", this.name);

            //set col rect to 0
            this.pColObj.pCollisionRect.Set(0, 0, 0, 0);
            base.Update();

            //update 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(Missile missile)
        {
            //missile vs shield col
            CollisionPair.CollidePair(missile, (GameObject)ForwardIterator.GetChild(this));
        }

        public override void Visit(Bomb bomb)
        {
            //bomb vs shield col
            CollisionPair.CollidePair(bomb, (GameObject)ForwardIterator.GetChild(this));
        }


    } //end class

} // end namespace