Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        float xOffsetForMinIntensity = -2f;
        float xOffsetForMaxIntensity = 3f;
        float xOffsetDiff            = xOffsetForMaxIntensity - xOffsetForMinIntensity;
        float camPos   = transform.position.x;
        float seasonX1 = SeasonalSystem.GetSingleton().GetSeasonX1(mSeason);
        float seasonX2 = SeasonalSystem.GetSingleton().GetSeasonX2(mSeason);
        float intensityRelativeToX1 = (Mathf.Clamp(camPos - seasonX1, xOffsetForMinIntensity, xOffsetForMaxIntensity) - xOffsetForMinIntensity) / xOffsetDiff;
        float intensityRelativeToX2 = (Mathf.Clamp(seasonX2 - camPos, xOffsetForMinIntensity, xOffsetForMaxIntensity) - xOffsetForMinIntensity) / xOffsetDiff;
        float summerIntensity       = Mathf.Min(intensityRelativeToX1, intensityRelativeToX2);
        float aboveCloudsIntensity  = Mathf.Clamp(0.25f * (transform.position.y - CloudLayer.CLOUD_HEIGHT), 0f, 1f);
        float intensity             = Mathf.Max(summerIntensity, aboveCloudsIntensity);

        var      colOverTime = GetComponent <ParticleSystem>().colorOverLifetime;
        Gradient grad        = new Gradient();

        grad.SetKeys(new GradientColorKey[] {
            new GradientColorKey(Color.white, 0.0f),
            new GradientColorKey(Color.white, 1.0f)
        },
                     new GradientAlphaKey[] {
            new GradientAlphaKey(0.0f, 0.0f),
            new GradientAlphaKey(intensity, 0.12f),
            new GradientAlphaKey(intensity, 0.88f),
            new GradientAlphaKey(0.0f, 1.0f)
        });
        colOverTime.color = grad;
    }
Esempio n. 2
0
    private void Start()
    {
        gameObject.SetActive(false);

        SeasonalSystem seasonalSystem = SeasonalSystem.GetSingleton();

        mFallSquirrelStartPoint = seasonalSystem.GetSeasonalVariants(fallSquirrelStartPoint.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
        mFallSquirrel           = seasonalSystem.GetSeasonalVariants(squirrel.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
        mFallDropAcornTrigger   = seasonalSystem.GetSeasonalVariants(dropAcornTrigger.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
        mFallAcornSpawner       = seasonalSystem.GetSeasonalVariants(acornSpawner.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
    }
Esempio n. 3
0
    private void Update()
    {
        if (mSleeping)
        {
            if (bubble != null)
            {
                if (mBubbleTimer >= 0f)
                {
                    mBubbleTimer -= Time.deltaTime;
                    if (mBubbleTimer < 0f)
                    {
                        GameObject b = Instantiate(bubble, mBubbleSpawnPoint.position, Quaternion.identity);
                        b.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 1);
                        mBubbleTimer = bubbleTime;
                    }
                }
            }
        }
        else
        {
            if (mTargetFruit == null)
            {
                SeasonalSystem seasonSystem     = SeasonalSystem.GetSingleton();
                Season         season           = GetComponent <Seasonal>().Season;
                float          seasonLeftBound  = seasonSystem.GetSeasonX1(season);
                float          seasonRightBound = seasonSystem.GetSeasonX2(season);

                GameObject[] fruits = GameObject.FindGameObjectsWithTag("Fruit");
                float        best   = 9999;
                foreach (GameObject fruit in fruits)
                {
                    float fruitX = fruit.transform.position.x;
                    if (fruitX < seasonLeftBound || fruitX > seasonRightBound)
                    {
                        continue;
                    }
                    if (fruit.transform.position.y > transform.position.y)
                    {
                        continue;
                    }

                    float dist = fruitX - transform.position.x;
                    if (dist < best)
                    {
                        best         = dist;
                        mTargetFruit = fruit;
                        mEating      = false;
                        GetComponent <Animator>().SetBool("eating", mEating);
                    }
                }
            }
        }
    }
Esempio n. 4
0
    // Start is called before the first frame update
    void Start()
    {
        if (GetComponent <Seasonal>().Season != Season.FALL)
        {
            gameObject.SetActive(false);
            return;
        }

        // a little annoying, but these are references to the SPRING version.
        // need to find the fall versions.
        SeasonalSystem seasonalSystem = SeasonalSystem.GetSingleton();

        mResetTrigger = seasonalSystem.GetSeasonalVariants(resetTrigger.GetComponent <Seasonal>())[(int)Season.SUMMER].gameObject;
        mAcornSpawner = seasonalSystem.GetSeasonalVariants(acornSpawner.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
        mLeafPlatform = seasonalSystem.GetSeasonalVariants(leafPlatform.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
    }
Esempio n. 5
0
    // Start is called before the first frame update
    void Start()
    {
        Season season = GetComponent <Seasonal>().Season;

        if (season != Season.FALL && season != Season.SUMMER)
        {
            gameObject.SetActive(false);
            return;
        }

        SeasonalSystem seasonalSystem = SeasonalSystem.GetSingleton();

        foreach (GameObject spawner in appleSpawners)
        {
            GameObject fallSpawner = seasonalSystem.GetSeasonalVariants(spawner.GetComponent <Seasonal>())[(int)Season.FALL].gameObject;
            mFallAppleSpawners.Add(fallSpawner);
        }
    }
Esempio n. 6
0
    // Update is called once per frame
    void Update()
    {
        Season season = GetComponent <Seasonal>().Season;

        /**
         * S = width of a season
         * P = the camera's position relative to the season's start
         * B = the width of the background image (in game units)
         * Offset1 = -B*P/S  (left side of the image relative to the left camera's position)
         * Offset2 = B/2 -B*P/S  (center of the image relative to the left camera's position)
         */
        float   S       = SeasonalSystem.SEASONAL_OFFSET;
        float   P       = mCameraObj.transform.localPosition.x - SeasonalSystem.GetSingleton().GetSeasonX1(season);
        float   B       = mBackgroundWidth;
        float   offset1 = -B * P / S;
        float   offset  = (B / 2f) - B * P / S;
        Vector3 pos     = transform.localPosition;

        // copy the y of the camera
        transform.localPosition = new Vector3(mCameraObj.transform.localPosition.x + offset, mCameraObj.transform.localPosition.y, pos.z);
    }
Esempio n. 7
0
    private void Update()
    {
        if (!mGoingForAcorn)
        {
            bool hasAcorn = mAcornHolder.childCount > 0;
            if (!hasAcorn)
            {
                GameObject acorn = GameObject.FindGameObjectWithTag("Acorn");
                if (acorn != null && acorn.transform.position.y <= -3 && !acorn.GetComponent <Rigidbody2D>().simulated)
                {
                    mGoingForAcorn = true;
                    Debug.Log("going for acorn");
                    if (transform.position.y > -3)
                    {
                        // assume the squirrel is sitting on the logs
                        mRigidbody.AddRelativeForce(new Vector2(-90, -10));
                    }
                    mTargetObject = acorn;
                }
            }
        }

        if (mTargetObject != null)
        {
            Vector3 toTarget = mTargetObject.transform.position - transform.position;
            if (Mathf.Abs(toTarget.x) <= 0.1f)
            {
                mRigidbody.velocity = new Vector2(0, mRigidbody.velocity.y);

                if (mTargetObject.CompareTag("Acorn"))
                {
                    mTargetObject.transform.SetParent(mAcornHolder, true); // worldPositionStays means that grabbing the acorn wont change the scale of it
                    mTargetObject.transform.localPosition = new Vector3(0, 0, 0);
                    SelectWaypoint(null);
                    Debug.Log("picked up acorn");
                    mGoingForAcorn = false;
                }
                else
                {
                    if (mAcornHolder.childCount > 0) // hasAcorn
                    {
                        // move all versions of the growing tree to match the position of the waypoint
                        if (growTree != null)
                        {
                            SeasonalSystem  seasonalSystem = SeasonalSystem.GetSingleton();
                            List <Seasonal> waypoints      = seasonalSystem.GetSeasonalVariants(mTargetObject.GetComponent <Seasonal>());
                            List <Seasonal> trees          = seasonalSystem.GetSeasonalVariants(growTree.GetComponent <Seasonal>());
                            for (int i = 0; i < 4; ++i)
                            {
                                trees[i].BroadcastMessage("PositionChanged", waypoints[i].gameObject);
                            }
                        }
                    }

                    mFleeing      = false;
                    mTargetObject = null;
                }
            }
            else
            {
                float towardsSign = Mathf.Sign(toTarget.x);
                //GetComponentInChildren<SpriteRenderer>().flipX = towardsSign < 0;
                transform.localScale = new Vector3(mScaleX * towardsSign, transform.localScale.y, transform.localScale.z);
                if (transform.position.y <= -3)
                {
                    mRigidbody.velocity = new Vector2(towardsSign * mFleeSpeed, mRigidbody.velocity.y);
                }
            }
        }
    }
Esempio n. 8
0
    void FixedUpdate()
    {
        if (!mSleeping)
        {
            if (mTargetFruit == null)
            {
                SeasonalSystem seasonSystem = SeasonalSystem.GetSingleton();
                Season         season       = GetComponent <Seasonal>().Season;
                if (transform.localPosition.x < seasonSystem.GetSeasonX1(season))
                {
                    SetFacingDirection(1);
                }
                if (transform.localPosition.x > seasonSystem.GetSeasonX2(season))
                {
                    SetFacingDirection(-1);
                }
            }
            else
            {
                float distToTarget = mTargetFruit.transform.position.x - transform.position.x;
                if (Mathf.Abs(distToTarget) <= 0.1f)
                {
                    // stop moving (unless we get another fruit)
                    mEating = true;
                    GetComponent <Animator>().SetBool("eating", mEating);
                    Destroy(mTargetFruit);
                    mTargetFruit = null;

                    // sync all pandas with this one
                    SeasonalSystem  seasonalSystem = SeasonalSystem.GetSingleton();
                    Seasonal        seasonal       = GetComponent <Seasonal>();
                    Season          season         = seasonal.Season;
                    List <Seasonal> pandas         = seasonalSystem.GetSeasonalVariants(seasonal);
                    float           relativeX      = transform.position.x - seasonalSystem.GetSeasonX1(season);
                    for (int i = 0; i < 4; ++i)
                    {
                        if (i != (int)Season.WINTER)
                        {
                            continue;                         // I know the loop is unnecessary now, but it's here because of design churn, and maybe it'll be needed again...
                        }
                        //if(i == (int)season || i == (int)Season.SPRING || i == ) continue;

                        Season    s       = (Season)i;
                        float     seasonX = seasonalSystem.GetSeasonX1(s);
                        Transform panda   = pandas[i].transform;
                        panda.position = new Vector3(seasonX + relativeX, transform.position.y, transform.position.z);
                    }
                }
                else
                {
                    SetFacingDirection(distToTarget > 0 ? 1 : -1);
                }
            }

            if (mTargetFruit && !mEating)
            {
                // Accelerate to desired velocity
                Rigidbody2D rb           = GetComponent <Rigidbody2D>();
                float       desiredV     = mFacing * mSpeed;
                float       deltaV       = desiredV - rb.velocity.x;
                float       desiredAccel = deltaV / Time.fixedDeltaTime;
                float       maxAccel     = 30f;
                float       actualAccel  = Mathf.Min(Mathf.Abs(desiredAccel), maxAccel) * Mathf.Sign(desiredAccel) * 1000;
                rb.AddForce(new Vector2(actualAccel, 0f));
            }
        }
    }
Esempio n. 9
0
 private void Awake()
 {
     sSingleton = this;
 }