Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // Update Move Logic
        if (startGame)
        {
            // Handle Movement Dependant of current fuel
            if (fuel.HasFuel())
            {
                if (outOfFuel)
                {
                    // This is when you gain fuel again after out of fuel
                    outOfFuel = false;

                    // Turn on thrusters again
                    player.SetThrusters(true);
                    thrusters.Play();
                    audio.PlaySound(thrustUp);

                    // Reset score counter to continue calculating score now
                    score.ForwardAgain(distance);

                    // Adjust camera back to bottom and turn on top object generations
                    cameraFollow.MoveCameraUp();
                    generator.TopGenerate();
                    isLerping = true;
                }
                currentSpeedUp = speedUp;
            }
            else
            {
                if (!isBoost)
                {
                    currentSpeedUp = speedDown;
                    if (!outOfFuel)
                    {
                        // This is for when you run out of fuel
                        outOfFuel = true;

                        // Turn off thrusters
                        audio.PlaySound(thrustDown);
                        player.SetThrusters(false);
                        thrusters.Stop();

                        // Move camera up to look at incoming objects from behind
                        cameraFollow.MoveCameraDown();
                        generator.FallGenerate();
                        isLerping = true;
                    }
                }
            }

            // Speed adjustments based on fuel changes
            if (isLerping)
            {
                if (outOfFuel)
                {
                    currentSpeedUp = Mathf.Lerp(speedUp, speedDown, t);
                }
                else
                {
                    currentSpeedUp = Mathf.Lerp(speedDown, speedUp, t);
                }

                t += lerpSpeed * Time.deltaTime;

                if (t >= 1.0f)
                {
                    if (outOfFuel)
                    {
                        currentSpeedUp = speedDown;
                    }
                    else
                    {
                        currentSpeedUp = speedUp;
                    }
                    isLerping = false;
                    t         = 0.0f;
                }
            }

            // Adjust speed
            if (speedUp < maxSpeed)
            {
                speedUp += (acceleration * Time.deltaTime);

                if (speedUp > maxSpeed)
                {
                    speedUp = maxSpeed;
                }
            }
            else
            {
                speedUp = maxSpeed;
            }

            speedDown = -speedUp;

            ui.curSpeed = ((speedUp + boostMod) - 5.0f).ToString("f0");
            ui.UpdateSpeed();

            // Adjust Distance
            distance = Mathf.Round(transform.position.y - startYPos);

            // Update Score
            score.ScoreUpdate(distance, (speedUp + boostMod) - 5.0f);
        }
        else
        {
            currentSpeedUp = 5.0f;
        }

        // Animate tilts
        if (anim)
        {
            anim.SetInteger("tilt", (int)currentSpeedX);
        }

        // Set finished movment each frame
        rb.velocity        = new Vector3(currentSpeedX, currentSpeedUp + boostMod, 0.0f);
        transform.position = new Vector3(Mathf.Clamp(transform.position.x, -xClamp, xClamp), transform.position.y, transform.position.z);
    }