コード例 #1
0
    /*
     *	FUNCTION: Randomise an element to generate on the path
     *	RETURNS: Element number to generate
     *	CALLED BY:  Start()
     *				Update()
     *				generateElements()
     */
    private int getRandomElement()
    {
        float highestFrequency = 0;
        int   elementIndex     = 0;

        int   i        = 0;
        float tempFreq = 0;

        if (iLastPowerupGenerated > iForcePowerupGeneration && //force powerup generation if not generated for a while
            !hPowerupsMainController.isPowerupActive() &&     //ensure that a powerup is not currently active
            bPowerupPlaced == false)                           //do not generate powerup if one is already active
        {
            for (i = iObstacleCount; i < (iObstacleCount + iPowerupCount); i++)
            {
                tempFreq = elements[i].iFrequency * Random.value;
                if (highestFrequency < tempFreq)
                {
                    highestFrequency = tempFreq;
                    elementIndex     = i;
                }
            }
            iLastPowerupGenerated = 0; //reset variable
        }
        else                           //normal case; generate any random element
        {
            for (i = 0; i < iTotalCount; i++)
            {
                if ((elements[i].elementType == ElementType.Powerup &&
                     hPowerupsMainController.isPowerupActive()) ||              //do not generate powerup if one is already active
                    (elements[i].elementType == ElementType.Powerup && bPowerupPlaced == true))                 //do not place powerup on current patch if one has already been placed
                {
                    continue;
                }

                tempFreq = elements[i].iFrequency * Random.value;
                if (highestFrequency < tempFreq)
                {
                    highestFrequency = tempFreq;
                    elementIndex     = i;
                }
            }            //end of for
        }

        //if a powerup has been placed, stop placing more powerups in current patch
        if (elements[elementIndex].elementType == ElementType.Powerup)
        {
            bPowerupPlaced = true;
        }

        return(elementIndex);
    }
コード例 #2
0
    void Update()
    {
        if (hInGameScript.isGamePaused() == true)
        {
            return;
        }

        if (PUState == 1)                                                                                   //hide the powerup
        {
            if (hPowerupsMainController.isPowerupActive(PowerupsMainController.PowerUps.Magnetism) == true) //magnetism powerup is active
            {
                //adjust the currency's height
                v3CurrencyLerpPosition    = tPlayer.position;
                v3CurrencyLerpPosition.x += 2;
                v3CurrencyLerpPosition.y += 5;

                //pull the currency towards the player
                transform.position   = Vector3.Lerp(transform.position, v3CurrencyLerpPosition, (Time.time - StartTime) / 0.8f);
                transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(0.1f, 0.1f, 0.1f), (Time.time - StartTime) / 0.8f);
            }
            else    //regular cases
            {
                //pull the currency towards the player
                transform.position   = Vector3.Lerp(transform.position, tPlayer.position, (Time.time - StartTime) / 0.2f);
                transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(0.01f, 0.01f, 0.01f), (Time.time - StartTime) / 0.002f);
            }

            if ((Time.time - StartTime) > 0.2f)
            {
                //disable currency if magnetism is activated
                if (powerupType == PowerupsMainController.PowerUps.Currency || hPowerupsMainController.isPowerupActive(PowerupsMainController.PowerUps.Magnetism) == true)
                {
                    toggleMeshRender(false);            //make currency invisible
                }
                else
                {
                    this.gameObject.SetActive(false);            //deactivate object
                }
            }
            return;
        }

        v3DistanceVector = transform.position - tPlayer.position;

        //destroy not collect currency/ powerup
        if (v3DistanceVector.sqrMagnitude < 40000.0f)
        {
            bDestroyWhenFarFlag = true;
        }

        //destroy currency or powerup if not collected
        if (bDestroyWhenFarFlag == true)
        {
            if (v3DistanceVector.sqrMagnitude > 90000.0f)
            {
                if (powerupType == PowerupsMainController.PowerUps.Currency)
                {
                    toggleMeshRender(false);
                }
                else
                {
                    this.gameObject.SetActive(false);
                }
            }
        }

        if (powerupType == PowerupsMainController.PowerUps.Currency)//currency pull radius
        {
            fCatchRadius = hPowerupsMainController.getMagnetismRadius();
        }

        if (v3DistanceVector.sqrMagnitude < fCatchRadius) //catch the orb
        {
            PUState   = 1;                                //hide the orb
            StartTime = Time.time;

            hPowerupsMainController.collectedPowerup((int)powerupType);//tell power-up main script what has been collected
        }
    }//end of update