Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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));
            }
        }
    }