GAM456-SpaceInvaders / SpaceInvaders / 4_GameObject / Bomb / Strategy / FallDagger.cs
FallDagger.cs
Raw
using System;
using System.Diagnostics;


namespace SpaceInvaders
{
    public class FallDagger : FallStrategy
    {
        //-------------------------------------------------------------------
        //  FIELDS
        //-------------------------------------------------------------------

        private float oldY;

        //-------------------------------------------------------------------
        //  CLASS METHODS
        //-------------------------------------------------------------------

        public FallDagger()
        {
            this.oldY = 0.0f;
        }

        //-------------------------------------------------------------------
        //  OVERRIDDEN METHODS
        //-------------------------------------------------------------------

        public override void Reset(float y)
        {
            this.oldY = y;
        }

        public override void Fall(Bomb pBomb)
        {
            Debug.Assert(pBomb != null);

            float targetY = oldY - 1.0f * pBomb.GetBoundingBoxHeight();
            if(pBomb.y < targetY)
            {
                pBomb.MultiplyScale(1.0f, -1.0f);
                oldY = targetY;
            }
        }
    }
}