Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     if (!init)
     {
         GridSystem grid = GameObject.Find("GameSystem").GetComponent <GameSystem>().greenBlobHeatmap;
         grid.AddBlobToHeatMap(transform.position, weight);
         init = true;
     }
 }
Esempio n. 2
0
    void EndSplit()
    {
        grid = GameObject.Find("GameSystem").GetComponent <GameSystem>().greenBlobHeatmap;
        GameObject newGreenBlob = Instantiate(GreenBlob.gameObject);
        Vector3    offset       = new Vector3(0.1f, 0);

        newGreenBlob.transform.position = transform.position + offset;
        transform.position -= offset;
        newGreenBlob.GetComponent <GreenBlob_Behaviour>().jumpTimer = -2f;
        newGreenBlob.GetComponent <GreenBlob_Behaviour>().canSplit  = false;
        grid.AddBlobToHeatMap(newGreenBlob.transform.position);
        newGreenBlob.GetComponent <GreenBlob_Behaviour>().blobWasInit = true;
    }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        if (!isBeeingJumpedOn)
        {
            grid = GameObject.Find("GameSystem").GetComponent <GameSystem>().greenBlobHeatmap;

            if (isIdle)
            {
                int xBlob, yBlob;
                grid.GetXY(transform.position, out xBlob, out yBlob);
                if (grid.value(xBlob, yBlob) < minimalDensityToSplit)
                {
                    if (canSplit)//split and reset the splitTimer
                    {
                        Split();
                        canSplit  = false;
                        splitTime = Random.Range(0.8f, 1.2f) * averageSplitTime;
                    }
                    else
                    {
                        if (splitTimer > splitTime)//begin splitting
                        {
                            canSplit   = true;
                            splitTimer = -5f;
                        }
                    }
                    splitTimer += Time.deltaTime; //only increment the split timer if the blob is in a situation where he could split
                }
                else if (jumpTimer > idleTime)    //it is time to jump !
                {
                    jumpTimer = 0f;
                    isIdle    = false;
                    // Initialize the Jump
                    jumpVector = JumpInit();
                    lastIdleX  = transform.position.x;
                    lastIdleY  = transform.position.y;
                }
            }
            else
            {
                if (jumpTimer > jumpDuration)//it is time to stop jumping !
                {
                    jumpTimer = 0f;
                    isIdle    = true;
                    idleTime  = Random.Range(averageIdleTime * 0.5f, averageIdleTime * 1.5f);
                    if (blobWasInit)//only remove the blob if he was already added (this should be in start, but for some reason it does not work when put there...)
                    {
                        grid.RemoveBlobFromHeatMap(new Vector3(lastIdleX, lastIdleY));
                    }
                    grid.AddBlobToHeatMap(transform.position);
                    Stop();
                    blobWasInit = true;//if the blob was not yet added, it now is
                }
                else//we are in the middle of a jump
                {
                    Move(jumpVector);
                }
            }
            jumpTimer += Time.deltaTime;
        }
        else
        {
            Stop();
            if (jumpedTimer > 3 * averageIdleTime)
            {
                isBeeingJumpedOn = false;
            }
            jumpedTimer += Time.deltaTime;
        }
    }