GAM456-SpaceInvaders / SpaceInvaders / 3_Timer / Commands / DeployUFO.cs
DeployUFO.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class DeployUFO : Command
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        UFOAlien pUFO;


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

        public DeployUFO()
        {
            this.pUFO = null;   //default value
        }


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

        public override void Execute(float deltaTime)
        {
            GameObject pRoot = ObjectNodeMan.FindObject(GameObject.ObjectName.UFORoot);
            ObjectNode pObjNode = GhostMan.FindObj(GameObject.ObjectName.UFO);

            //check to see if ghost man has it
            if(pObjNode == null)
            {
                pUFO = new UFOAlien(Sprite.SpriteName.UFO, 57.0f, 850.0f);
            }
            else
            {
                pUFO = (UFOAlien)pObjNode.GetObject();
                GhostMan.RemoveObj(pObjNode);

                pUFO.Resurrect(57.0f, 850.0f); //I LIVEEEE
            }

            //add to batch 
            pUFO.ActivateSprite(SpriteBatchMan.FindBatch(SpriteBatch.BatchName.UFO));
            pUFO.ActivateCollisionSprite(SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Boxes));

            //add to tree
            pRoot.AddComponent(pUFO);

            //invoke animation
            AnimateUFO pMoveUFO = new AnimateUFO();
            TimerEventMan.AddEvent(TimerEvent.EventName.AnimateUFO, pMoveUFO, 0.0f);
        }


    } //end class

} // end namespace