GAM456-SpaceInvaders / SpaceInvaders / 7_GameState / State_End.cs
State_End.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class State_End : State
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        SpriteBatchMan poSpriteBatchMan;
        FontMan poFontMan;


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

        public State_End() : base()
        {  }


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

        public override void Init()
        {
            //---------------------------------------------------------------
            // LOAD MANAGERS
            //---------------------------------------------------------------

            this.poSpriteBatchMan = new SpriteBatchMan();
            Debug.Assert(this.poSpriteBatchMan != null);
            SpriteBatchMan.SetActiveMan(this.poSpriteBatchMan);

            this.poFontMan = new FontMan();
            Debug.Assert(this.poFontMan != null);
            FontMan.SetActiveMan(this.poFontMan);


            //---------------------------------------------------------------
            // LOAD SPRITE BATCH
            //---------------------------------------------------------------

            SpriteBatchMan.AddBatch(SpriteBatch.BatchName.Text_UI, 2);


            //---------------------------------------------------------------
            // LOAD FONT
            //---------------------------------------------------------------

            FontMan.AddFont(Font.FontName.P1_Score_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "SCORE<1>", 40, 980, 3.9f, 4.4f, 1.35f);
            FontMan.AddFont(Font.FontName.P1_Score, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "0000", 90, 930, 3.9f, 4.4f, 1.35f);

            FontMan.AddFont(Font.FontName.P2_Score_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "SCORE<2>", 620, 980, 3.9f, 4.4f, 1.35f);
            FontMan.AddFont(Font.FontName.P2_Score, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "0000", 680, 930, 3.9f, 4.4f, 1.35f);

            FontMan.AddFont(Font.FontName.HighScore_Title, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "HI-SCORE", 330, 980, 3.9f, 4.4f, 1.35f);
            FontMan.AddFont(Font.FontName.HighScore, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "0000", 380, 930, 3.9f, 4.4f, 1.35f);

            FontMan.AddFont(Font.FontName.GameCredits, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "CREDIT 00", 570, 40, 3.9f, 4.4f, 1.35f);

            FontMan.AddFont(Font.FontName.GameOver, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "GAME OVER", 275, 750, 4.9f, 5.4f, 1.35f);
            FontMan.AddFont(Font.FontName.Message, Glyph.GlyphName.InvaderFont, SpriteBatch.BatchName.Text_UI, "PRESS R TO REPLAY", 150, 500, 4.9f, 5.4f, 1.35f);


        }

        public override void OnEnter()
        {
            InputSubject pSubject = InputMan.GetKeyR();
            pSubject.Attach(new StateObserver(this));

            SpriteBatchMan.SetActiveMan(this.poSpriteBatchMan);
            FontMan.SetActiveMan(this.poFontMan);

            Font pFont = FontMan.FindFont(Font.FontName.HighScore);
            pFont.UpdateMessage(pContext.GetHighScore().ToString("D4"));
        }

        public override void Draw()
        {
            SpriteBatchMan.DrawBatch();
        }

        public override void Update(float sysTime)
        {
            InputMan.Update();
        }

        public override void OnExit()
        {
            InputSubject pSubject = InputMan.GetKeyR();
            pSubject.DetachInputs();

            SpriteBatchMan.UnactivateMan();
            FontMan.UnactivateMan();
        }

        public override void Handle()
        {
            pContext.Restart();
        }
    }
}