using System; using System.Diagnostics; namespace SpaceInvaders { public class Attract2 : Command { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- SpriteBatch pAlienBatch; Font pFont0; Font pFont1; Font pFont2; Font pFont3; Font pFont4; Font pFont5; Font pFont6; int curr = 0; int i = 0; string message; float delayTime; Attract1 attract1; //------------------------------------------------------------------- // CONSTRUCTION //------------------------------------------------------------------- public Attract2() { } public Attract2(float delayTime) { this.delayTime = delayTime; pFont0 = FontMan.AddFont(Font.FontName.Attract_Play, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 395, 650, 3.9f, 4.4f, 1.35f); pFont1 = FontMan.AddFont(Font.FontName.Attract_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 250, 550, 3.9f, 4.4f, 1.35f); pFont2 = FontMan.AddFont(Font.FontName.Attract_ScoreTable, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 180, 410, 3.9f, 4.4f, 1.35f); pFont3 = FontMan.AddFont(Font.FontName.Attract_Ufo, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 355, 340, 3.9f, 4.4f, 1.35f); pFont4 = FontMan.AddFont(Font.FontName.Attract_Squid, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 355, 270, 3.9f, 4.4f, 1.35f); pFont5 = FontMan.AddFont(Font.FontName.Attract_Crab, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 355, 200, 3.9f, 4.4f, 1.35f); pFont6 = FontMan.AddFont(Font.FontName.Attract_Jellyfish, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_Attract2, "", 355, 130, 3.9f, 4.4f, 1.35f, Sprite.pGreen); pAlienBatch = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Aliens); Debug.Assert(pAlienBatch != null); } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public void SetAttract1(Attract1 attract) { Debug.Assert(attract != null); this.attract1 = attract; } public override void Execute(float deltaTime) { switch(curr) { case 0: message = "PLAY"; UpdateFont(pFont0, message); break; case 1: message = "SPACE INVADERS"; UpdateFont(pFont1, message); break; case 2: pAlienBatch.SetToggle(true); pFont2.UpdateMessage("*SCORE ADVANCE TABLE*"); pFont3.UpdateMessage("?= "); curr++; i = 2; TimerEventMan.AddEvent(TimerEvent.EventName.Attract2, this, delayTime); break; case 3: message = "=? MYSTERY"; UpdateFont(pFont3, message); break; case 4: message = "=30 POINTS"; UpdateFont(pFont4, message); break; case 5: message = "=20 POINTS"; UpdateFont(pFont5, message); break; case 6: message = "=10 POINTS"; UpdateFont(pFont6, message); break; case 7: //cycle back to Attract 1 pAlienBatch.SetToggle(false); SpriteBatch pBatch = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Text_Attract2); Debug.Assert(pBatch != null); pBatch.SetToggle(false); attract1.Reset(); SpriteBatch pBatch2 = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Text_Attract1); Debug.Assert(pBatch2 != null); pBatch2.SetToggle(true); TimerEventMan.AddEvent(TimerEvent.EventName.Attract1, attract1, deltaTime + 1.5f); break; default: Debug.Assert(false); break; } } public void Reset() { pFont0.UpdateMessage(""); pFont1.UpdateMessage(""); pFont2.UpdateMessage(""); pFont3.UpdateMessage(""); pFont4.UpdateMessage(""); pFont5.UpdateMessage(""); pFont6.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.Attract2, this, delayTime); i++; } else { curr++; i = 0; TimerEventMan.AddEvent(TimerEvent.EventName.Attract2, this, delayTime); } } } //end class } // end namespace