using System; using System.Diagnostics; namespace SpaceInvaders { public class Attract1 : Command { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- Font pFont; Font pFont1; Font pFont2; float delayTime; int curr; int i = 0; string message; Attract2 attract2; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public Attract1() { } public Attract1(float delayTime) { this.delayTime = delayTime; FontMan.AddFont(Font.FontName.Attract_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract1, "INSERT COIN", 260, 600, 3.9f, 4.4f, 1.35f); pFont = FontMan.AddFont(Font.FontName.Attract_PlayerSelect, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract1, "", 200, 430, 3.9f, 4.4f, 1.35f); pFont1 = FontMan.AddFont(Font.FontName.Attract_Player1, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract1, "", 200, 330, 3.9f, 4.4f, 1.35f); pFont2 = FontMan.AddFont(Font.FontName.Attract_Player2, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract1, "", 200, 230, 3.9f, 4.4f, 1.35f, Sprite.pGreen); attract2 = new Attract2(delayTime); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public override void Execute(float deltaTime) { switch(curr) { case 0: message = "<1 OR 2 PLAYERS>"; UpdateFont(pFont, message); break; case 1: message = "*1 PLAYER 1 COIN"; UpdateFont(pFont1, message); break; case 2: message = "*2 PLAYERS 2 COINS"; UpdateFont(pFont2, message); break; case 3: SpriteBatch pBatch = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Text_Attract1); Debug.Assert(pBatch != null); pBatch.SetToggle(false); attract2.Reset(); SpriteBatch pBatch2 = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Text_Attract2); Debug.Assert(pBatch2 != null); pBatch2.SetToggle(true); TimerEventMan.AddEvent(TimerEvent.EventName.Attract2, attract2, deltaTime + 1.5f); break; default: Debug.Assert(false); break; } attract2.SetAttract1(this); } public void Reset() { pFont.UpdateMessage(""); pFont1.UpdateMessage(""); pFont2.UpdateMessage(""); this.curr = 0; this.i = 0; } //------------------------------------------------------------------- // PRIVATE METHODS //------------------------------------------------------------------- private void UpdateFont(Font font, string mssg) { Debug.Assert(font != null); Debug.Assert(mssg != null); string subMssg; if(this.i < mssg.Length) { subMssg = mssg.Substring(0, this.i + 1); font.UpdateMessage(subMssg); TimerEventMan.AddEvent(TimerEvent.EventName.Attract1, this, delayTime); i++; } else { curr++; i = 0; TimerEventMan.AddEvent(TimerEvent.EventName.Attract1, this, delayTime); } } } // end class } // end namespace