コード例 #1
0
    public override void Update()
    {
        base.Update();
        moving = !GamePause.paused;
        if (!moving)
        {
            return;
        }

        ShieldUpdate();

        if (mode == 0)         //shielding
        {
            if (currentState == state.DECIDING)
            {
                goingRight   = !ShouldWeGoLeft(thingpoints[thingIdx]);               //pick a direction to move in
                currentState = state.MOVING;
            }
            else if (currentState == state.MOVING)
            {
                Arrive();
            }
            else if (currentState == state.SHIELDING)
            {
                ShieldingLoop();
            }
        }
        else if (mode == 1)         //boosting regen
        {
            if (currentState == state.DECIDING)
            {
                goingRight   = !ShouldWeGoLeft(thingpoints[thingIdx]);               //pick a direction to move in
                currentState = state.MOVING;
            }
            else if (currentState == state.MOVING)
            {
                Arrive();
            }
            else if (currentState == state.SHIELDING)
            {
                ShieldingLoop();
            }
            else if (currentState == state.BOOSTING)
            {
                BoostingLoop();
            }
        }
        else if (mode == 2)         //blocking shots
        {
            if (currentState == state.DECIDING)
            {
                if (reachedMiddle)
                {
                    currentState = state.MOVING;
                }
                else
                {
                    currentState = state.DIVING;
                }
            }
            else if (currentState == state.MOVING)
            {
                if (!reachedMiddle)
                {
                    currentState = state.DIVING;
                    return;
                }
                if (mode3reversing)
                {
                    if (clockwise)
                    {
                        thetas.z = -0.00005f;
                    }
                    else
                    {
                        thetas.z = 0.00005f;
                    }
                    if ((!clockwise && thetas.y >= 0.008f) || (clockwise && thetas.y <= -0.008f))
                    {
                        mode3reversing = false;
                    }
                }
                else
                {
                    thetas.y = 0.008f;
                    if (clockwise)
                    {
                        thetas.y *= -1;
                    }
                }
                if (directiontimer.TimeElapsedSecs() > secondsToReverse)
                {
                    clockwise = !clockwise;
                    System.Random rand = new System.Random();
                    secondsToReverse = MIN_SECS + (float)(rand.NextDouble() * (MAX_SECS - MIN_SECS));
                    directiontimer.Restart();
                    mode3reversing = true;
                }
            }
            else if (currentState == state.SHIELDING)
            {
                ShieldingLoop();
            }
            else if (currentState == state.BOOSTING)
            {
                BoostingLoop();
            }
            else if (currentState == state.DIVING)
            {
                if (radii.x > 3 * Dial.FULL_LENGTH / 4f)
                {
                    radii.z = -0.05f;
                }
                else if (radii.x > Dial.FULL_LENGTH / 2f)
                {
                    radii.z = 0.04f;
                }
                else
                {
                    Debug.Log("we finished diving");
                    radii.x = Dial.FULL_LENGTH / 2f;
                    radii.y = 0f;
                    radii.z = 0f;
                    PickTargetZone();
                    reachedMiddle = true;
                    currentState  = state.DECIDING;
                }
            }               /*else if(currentState == state.RETREATING){
                             *     if(radii.x < 3f*Dial.FULL_LENGTH/4f){
                             *             radii.z = 0.05f;
                             *     }else if(radii.x < Dial.FULL_LENGTH-hitboxCorrection){
                             *             radii.z = -0.04f;
                             *     }else{
                             *             radii.x = Dial.FULL_LENGTH-hitboxCorrection;
                             *             radii.y = 0f;
                             *             radii.z = 0f;
                             *             PickTargetZone();
                             *             currentState = state.DECIDING;
                             *     }
                             * }*/
        }
        else if (mode == 3) //stealing
        //beams proceed independent of state
        {
            List <Enemy> potentialTargets = Dial.GetAllShieldedEnemies();
            if (eaterTimer.TimeElapsedSecs() > eatDelay && potentialTargets.Count > 0)
            {
                eaterTimer.Restart();
                GameObject beam = GameObject.Instantiate(Resources.Load("Prefabs/MainCanvas/ShieldEater")) as GameObject;
                beam.transform.SetParent(transform, false);
                BigBulkShieldEater bbse = beam.GetComponent <BigBulkShieldEater>();
                bbse.SetBigBulk(this);
                int random = Random.Range(0, potentialTargets.Count);
                bbse.SetTarget(potentialTargets[random].gameObject);
                potentialTargets[random].MakeBulkDrainTarget();
            }
            //state handling
            if (currentState == state.DECIDING)
            {
                goingRight   = !ShouldWeGoLeft(thingpoints[thingIdx]);               //pick a direction to move in
                currentState = state.MOVING;
            }
            else if (currentState == state.MOVING)
            {
                if (reachedMiddle)
                {
                    reachedMiddle = false;
                    currentState  = state.RETREATING;
                    return;
                }
                if (mode3reversing)
                {
                    if (clockwise)
                    {
                        thetas.z = -0.00005f;
                    }
                    else
                    {
                        thetas.z = 0.00005f;
                    }
                    if ((!clockwise && thetas.y >= 0.008f) || (clockwise && thetas.y <= -0.008f))
                    {
                        mode3reversing = false;
                    }
                }
                else
                {
                    thetas.y = 0.008f;
                    if (clockwise)
                    {
                        thetas.y *= -1;
                    }
                }
                if (directiontimer.TimeElapsedSecs() > secondsToReverse)
                {
                    clockwise = !clockwise;
                    System.Random rand = new System.Random();
                    secondsToReverse = MIN_SECS + (float)(rand.NextDouble() * (MAX_SECS - MIN_SECS));
                    directiontimer.Restart();
                    mode3reversing = true;
                }
            }
            else if (currentState == state.SHIELDING)
            {
                ShieldingLoop();
            }
            else if (currentState == state.BOOSTING)
            {
                BoostingLoop();
            }
            else if (currentState == state.DIVING)
            {
                if (radii.x > 3 * Dial.FULL_LENGTH / 4f)
                {
                    radii.z = -0.05f;
                }
                else if (radii.x > Dial.FULL_LENGTH / 2f)
                {
                    radii.z = 0.04f;
                }
                else
                {
                    radii.x      = Dial.FULL_LENGTH / 2f;
                    currentState = state.RETREATING;
                }
            }
            else if (currentState == state.RETREATING)
            {
                if (radii.x < 3f * Dial.FULL_LENGTH / 4f)
                {
                    radii.z = 0.05f;
                }
                else if (radii.x < Dial.FULL_LENGTH - hitboxCorrection)
                {
                    radii.z = -0.04f;
                }
                else
                {
                    radii.x      = Dial.FULL_LENGTH - hitboxCorrection;
                    radii.y      = 0f;
                    radii.z      = 0f;
                    currentState = state.DECIDING;
                }
            }
        }
    }