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

namespace SpaceInvaders
{
    public class ReviveShip : Command
    {
        public ReviveShip() : base()
        {  }


        public override void Execute(float deltaTime)
        {
            //assume player has died & a ship is in ghost man
            Ship pShip;
            ObjectNode pObjNode = GhostMan.FindObj(GameObject.ObjectName.Ship);

            //pull dead ship from ghost man
            pShip = (Ship)pObjNode.GetObject();

            //remove from ghost man
            GhostMan.RemoveObj(pObjNode);
            pShip.ResurrectShip(450.0f, 100.0f);

            //add back to batch
            SpriteBatch pShipBatch = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Ships);
            SpriteBatch pBoxBatch = SpriteBatchMan.FindBatch(SpriteBatch.BatchName.Boxes);

            pShip.ActivateCollisionSprite(pBoxBatch);
            pShip.ActivateSprite(pShipBatch);

            //add to composite
            GameObject pShipRoot = ObjectNodeMan.FindObject(GameObject.ObjectName.ShipRoot);
            Debug.Assert(pShipRoot != null);

            pShipRoot.AddComponent(pShip);
        }
    }
}