Exemple #1
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);
            }
        }