Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        float deltaTime    = Time.deltaTime;
        float stepDistance = _speed * deltaTime;

        truck.AddDeltaY(-stepDistance * (warp ? 3 : 1));

        if (warp)
        {
            warpTime += deltaTime;
            if (warpTime >= WARP_DURATION)
            {
                warp = false;
                truck.WarpProgress(0);
                blocks.GenerateNextWall();
                createRandomFruit();
                if (nextFruitScore > 15)
                {
                    createRandomFruit();
                    nextFruitScore = 0;
                }
            }
            else
            {
                truck.WarpProgress(warpTime / WARP_DURATION);
            }
            return;
        }
        if (blocks.IsStopped())
        {
            if (truck.IsBounce())
            {
                //wait for bounce finish
            }
            else
            {
                if (onWallCollision())
                {
                    if (truck.Hit())
                    {
                        score++;
                        dest += blocks.IsPositiveHit() ? 1 : -1;
                        updateStatistics();
                    }
                    else  //game over
                    {
                        SceneManager.LoadScene(0);
                    }
                }
                else
                {
                    warp     = true;
                    warpTime = 0;
                }
            }
        }
    }