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


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

        public ShieldRoot(GameObject.ObjectName name, Sprite.SpriteName spriteName, float x, float y)
            : base(name, spriteName)
        {
            this.x = x;
            this.y = y;
        }


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

        //we don't delete root---?
        public void Resurrect(float x, float y)
        {
            this.x = x;
            this.y = y;
            base.Ressurect();
        }

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

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

            this.pColObj.pCollisionRect.Set(0, 0, 0, 0);
            base.Update();

            GameObject pParent = (GameObject)this.pParent;
            pParent.Update();

            base.Remove();
        }


        //-------------------------------------------------------------------
        //  ACCEPT METHODS
        //-------------------------------------------------------------------

        public override void Accept(Visitor other)
        {
            other.Visit(this);
        }

        public override void Visit(MissileGroup missile)
        {
            //missile root vs shield root
            CollisionPair.CollidePair((GameObject)ForwardIterator.GetChild(missile), this);
        }

        public override void Visit(Missile missile)
        {
            //missile vs shield root
            CollisionPair.CollidePair(missile, (GameObject)ForwardIterator.GetChild(this));
        }

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

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


    } //end class

} //end namespace