using System; using System.Diagnostics; namespace SpaceInvaders { public class SpriteBatch : DLink { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- public enum BatchName { Aliens, UFO, Ships, Boxes, BumpBox, Shields, Walls, Bumpers, Bombs, Missles, Text_UI, Text_Attract1, Text_Attract2, Uninitialized } public SpriteBatch.BatchName name; private SpriteNodeMan poSpriteNodeMan; private bool toggle; private int priority; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public SpriteBatch() : base() { this.name = BatchName.Uninitialized; this.priority = 0; this.toggle = true; this.poSpriteNodeMan = new SpriteNodeMan(); Debug.Assert(this.poSpriteNodeMan != null); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void SetBatch(SpriteBatch.BatchName name, int priority, int numReserve = 3, int growReserve = 2) { //set batch name & priority this.name = name; this.priority = priority; //set asso sprite node this.poSpriteNodeMan.SetSpriteNode(name, numReserve, growReserve); } public SpriteNodeMan GetSpriteNodeMan() { return this.poSpriteNodeMan; } public void SetToggle(bool status) { this.toggle = status; } public bool GetToggle() { return this.toggle; } public SpriteNode AttachBatch(GameObject pObject) { Debug.Assert(pObject != null); SpriteNode pNode = this.poSpriteNodeMan.AttachSpriteNode(pObject.pProxy); //initialize batch node pNode.SetSpriteNode(pObject.pProxy, this.poSpriteNodeMan); //back pointer this.poSpriteNodeMan.SetSpriteBatch(this); return pNode; } public SpriteNode AttachBatch(SpriteBase pBase) { SpriteNode pNode = this.poSpriteNodeMan.AttachSpriteNode(pBase); pNode.SetSpriteNode(pBase, this.poSpriteNodeMan); this.poSpriteNodeMan.SetSpriteBatch(this); return pNode; } //------------------------------------------------------------------- // OVERRIDE METHODS //------------------------------------------------------------------- //compare batches same by name public override bool Compare(Node pNode) { //check incoming node Debug.Assert(pNode != null); SpriteBatch pBatch2 = (SpriteBatch)pNode; if(this.name == pBatch2.name) { return true; } return false; } public override bool ComparePriority(Node pNode) { //check incoming Debug.Assert(pNode != null); SpriteBatch pBatch2 = (SpriteBatch)pNode; if(this.priority <= pBatch2.priority) { return true; } return false; } public override object GetName() { return this.name; } public override void Reset() { this.Clear(); } public override void PrintStats() { Debug.WriteLine("Name: {0} --> {1}", this.name, this.GetHashCode()); Debug.WriteLine("Priority: {0}", this.priority); base.PrintStats(); } //------------------------------------------------------------------- // PRIVATE METHODS //------------------------------------------------------------------- private void Clear() { this.name = BatchName.Uninitialized; this.priority = 0; } } //end class } //end namespace