using System; using System.Diagnostics; namespace SpaceInvaders { public class SpriteProxy : SpriteBase { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- public enum ProxyName { Proxy, NullObject, Uninitialized } public ProxyName name; private Sprite pSprite; private float x; private float y; public float sx; public float sy; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- protected SpriteProxy(SpriteProxy.ProxyName name) : base() { this.name = name; this.Clear(); } public SpriteProxy() : base() { this.Clear(); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void SetProxy(Sprite.SpriteName name) { this.name = ProxyName.Proxy; this.x = 0.0f; this.y = 0.0f; this.sx = 1.0f; this.sy = 1.0f; this.pSprite = SpriteMan.FindSprite(name); Debug.Assert(this.pSprite != null); } public void SetProxy(Sprite pSprite) { Debug.Assert(pSprite != null); this.pSprite = pSprite; } public void SetPos(float x, float y) { this.x = x; this.y = y; } public void MultiplyScale(float sx, float sy) { this.sx *= sx; this.sy *= sy; } public Sprite GetSprite() { return this.pSprite; } public override void Render() { //update actual sprite this.PushToReal(); //update & draw real sprite this.pSprite.Update(); this.pSprite.Render(); } public override void Update() { this.PushToReal(); this.pSprite.Update(); } public override bool Compare(Node pNode) { //check incoming Debug.Assert(pNode != null); SpriteProxy pProxyB = (SpriteProxy)pNode; if(this.pSprite.name == pProxyB.pSprite.name) { return true; } return false; } public override object GetName() { return this.name; } public override void Reset() { this.Clear(); } public override void PrintStats() { Debug.WriteLine("{0}-->{1}", this.name, this.GetHashCode()); // Data: if (pSprite != null) { Debug.WriteLine("Sprite:{0}-->{1}", this.pSprite.GetName(), this.pSprite.GetHashCode()); } else { Debug.WriteLine("Sprite: null"); } Debug.WriteLine("(x,y): {0},{1}", this.x, this.y); base.PrintStats(); } //------------------------------------------------------------------- // PRIVATE METHODS //------------------------------------------------------------------- private void Clear() { this.name = ProxyName.Uninitialized; this.x = 0.0f; this.y = 0.0f; this.sx = 1.0f; this.sy = 1.0f; this.pSprite = null; } private void PushToReal() { Debug.Assert(this.pSprite != null); this.pSprite.SetPos(this.x, this.y, this.sx, this.sy); } } //end class } //end namespace