Example #1
0
        /// <summary>
        /// Process velocity and animation by
        /// passing the status. (Enum)
        /// </summary>
        /// <param name="statusX"> status in x axis </param>
        /// <param name="statusY"> status in y axis </param>
        public void FlyByStatus(StatusX statusX, StatusY statusY)
        {
            // process vertical axis (x-axis)
            switch (statusX)
            {
            case StatusX.IDLE:
                FlyX(0);
                break;

            case StatusX.LEFT:
                FlyX(JCS_Mathf.ToNegative(mFlyForceX));
                break;

            case StatusX.RIGHT:
                FlyX(JCS_Mathf.ToPositive(mFlyForceX));
                break;
            }

            // process horizontal axis (y-axis)
            switch (statusY)
            {
            case StatusY.IDLE:
                FlyY(0);
                break;

            case StatusY.DOWN:
                FlyY(JCS_Mathf.ToNegative(mFlyForceY));
                break;

            case StatusY.UP:
                FlyY(JCS_Mathf.ToPositive(mFlyForceY));
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Fly to a direction base on possibilities.
        /// </summary>
        public void FlyDirectionByPossiblity()
        {
            // direction we are going to use next.
            StatusX directionX = StatusX.IDLE;
            StatusY directionY = StatusY.IDLE;

            // if is already get attack do the mad effect.
            if (mMadEffect && mAttackRecorder != null)
            {
                Transform lastAttacker = mAttackRecorder.LastAttacker;

                // if the last attacker does not exist,
                // do nothing.
                if (lastAttacker != null)
                {
                    // NOTE(JenChieh): if does exist, start
                    // following the attacker.

                    // X-axis
                    if (lastAttacker.position.x < this.transform.position.x)
                    {
                        directionX = StatusX.LEFT;
                    }
                    else
                    {
                        directionX = StatusX.RIGHT;
                    }

                    // Y-axis
                    if (lastAttacker.position.y < this.transform.position.y)
                    {
                        directionY = StatusY.DOWN;
                    }
                    else
                    {
                        directionY = StatusY.UP;
                    }

                    // do that direction and return.
                    FlyByStatus(directionX, directionY);
                    return;
                }
            }

            // record down how what does success to go with.
            int resultCounterX = 0;
            int resultCounterY = 0;

            float idlePossiblityX = JCS_Random.Range(0, 100);
            float leftPossiblity  = JCS_Random.Range(0, 100);
            float rightPossiblity = JCS_Random.Range(0, 100);

            if (idlePossiblityX < mToIdleVetical)
            {
                // success to do idle in x axis
                directionX = StatusX.IDLE;
                ++resultCounterX;
            }

            if (leftPossiblity < mToLeft)
            {
                // success to do left
                directionX = StatusX.LEFT;
                ++resultCounterX;
            }

            if (rightPossiblity < mToRight)
            {
                // success to do right
                directionX = StatusX.RIGHT;
                ++resultCounterX;
            }


            float idlePossiblityY = JCS_Random.Range(0, 100);
            float upPossiblity    = JCS_Random.Range(0, 100);
            float downPossiblity  = JCS_Random.Range(0, 100);

            if (idlePossiblityY < mToIdleHorizontal)
            {
                // success to do idle in y axis
                directionY = StatusY.IDLE;
                ++resultCounterY;
            }

            if (downPossiblity < mToDown)
            {
                // success to do left
                directionY = StatusY.DOWN;
                ++resultCounterY;
            }

            if (upPossiblity < mToUp)
            {
                // success to do right
                directionY = StatusY.UP;
                ++resultCounterY;
            }

            // if there are multiple result do randomly
            if (resultCounterX >= 2 &&
                resultCounterY >= 2)
            {
                FlyRandomly();
            }
            // else if we successfully find the direction,
            // use the direction algorithm found.
            else
            {
                FlyByStatus(directionX, directionY);
            }
        }