GAM456-SpaceInvaders / SpaceInvaders / 1_Sprite / SpriteBatch / SpriteNode.cs
SpriteNode.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class SpriteNode : DLink
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        private SpriteBase pSpriteBase;      //ref to sprite
        private SpriteNodeMan pBackSpriteNodeMan; //back pointer


        //-------------------------------------------------------------------
        //  CONSTRUCTION
        //-------------------------------------------------------------------

        public SpriteNode() : base()
        {
            this.pSpriteBase = null;
            this.pBackSpriteNodeMan = null;
        }


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

        public void SetSpriteNode(SpriteBase pSpriteBase, SpriteNodeMan pSpriteNodeMan)
        {
            Debug.Assert(pSpriteBase != null);
            Debug.Assert(pSpriteNodeMan != null);

            //save ref
            this.pSpriteBase = pSpriteBase;

            //set back pointers
            this.pSpriteBase.SetSpriteNode(this);
            this.pBackSpriteNodeMan = pSpriteNodeMan;
            Debug.Assert(this.pBackSpriteNodeMan != null);
        }

        public SpriteBase GetSprite()
        {
            return this.pSpriteBase;
        }

        public SpriteBatch GetSpriteBatch()
        {
            Debug.Assert(this.pBackSpriteNodeMan != null);
            return this.pBackSpriteNodeMan.GetSpriteBatch();
        }

        public SpriteNodeMan GetNodeMan()
        {
            Debug.Assert(this.pBackSpriteNodeMan != null);
            return this.pBackSpriteNodeMan;
        }

        public override void Reset()
        {
            this.Clear();
        }

        public override void PrintStats()
        {
            Debug.WriteLine("{0} node", this.GetHashCode());
            Debug.WriteLine("pSprite: {0} ({1})", this.pSpriteBase.GetName(), this.pSpriteBase.GetHashCode());

            base.PrintStats();
        }


        //-------------------------------------------------------------------
        //  PRIVATE METHODS
        //-------------------------------------------------------------------

        private void Clear()
        {
            this.pSpriteBase = null;
        }


    } //end class

} //end namespace