コード例 #1
0
    void ChewObjects()
    {
        float mass_to_eat = m_EatMassPerSecond * Time.deltaTime;

        while (true)
        {
            if (m_ChewingObjects.Count == 0)
            {
                return;
            }

            FallingObject fo       = m_ChewingObjects[0];
            float         progress = fo.GetChewingProcess();
            if (progress >= 1.0f)
            {
                fo.SetChewed();
                EatMass(0.0f, fo);
                continue;
            }
            float mass      = fo.GetMass();
            float mass_left = (1.0f - progress) * mass;
            if (mass_to_eat < mass_left)
            {
                EatMass(mass_to_eat);
                progress = (progress * mass + mass_to_eat) / mass;
                fo.SetChewingProcess(progress);
                break;
            }
            fo.SetChewingProcess(1.0f);
            fo.SetChewed();
            EatMass(mass_left, fo);
            mass_to_eat -= mass_left;
        }
    }
コード例 #2
0
    void StartChewObjects(FallingObject falling_obj)
    {
        GameObject go = falling_obj.gameObject;

        m_ChewingObjects.Add(falling_obj);
        m_MassChewingObjs += falling_obj.GetMass();
        float speed_was = falling_obj.GetSpeed();

        ApplyImpulse(go.rigidbody2D.mass * speed_was);

        // Report to conveyor
        m_LevelController.GetConveyor(m_IsRightHead).UnlinkObject(falling_obj);

        // Back off
        StartCoroutine(Backoff(0.3f));

        // Play sound
        audio.PlayOneShot(m_ImpactAudio, 1.0f);
    }