Exemple #1
0
    // Use this for initialization
    void Start()
    {
        GameObject bunn = GameObject.Find("Bunnies");
        if(bunn)
        {
            bunnies = bunn.GetComponent<Bunnies>();
        }
        cameraShake = Camera.main.GetComponent<Shake>();
        cR = GetComponent<SpriteRenderer>();
        timeOfDeath = 0;
        ingameUI = GameObject.FindGameObjectsWithTag("IngameUI");
        ingameRends = new SpriteRenderer[ingameUI.Length];
        for(int i =0; i < ingameUI.Length; ++i)
        {
            ingameRends[i] = ingameUI[i].GetComponent<SpriteRenderer>();
        }
        gameoverUI = GameObject.FindGameObjectsWithTag("GameOverUI");
        goRends = new SpriteRenderer[gameoverUI.Length];
        for(int i =0; i < gameoverUI.Length; ++i)
        {
            goRends[i] = gameoverUI[i].GetComponent<SpriteRenderer>();
        gameoverUI[i].SetActive(false);
        }
        if(GOPercentage)
        {
            GOPercentageS = GOPercentage.GetComponent<Percentage>();
        }
        t = 0;

        gameOverAudio = GetComponent<AudioSource>();
    }
    // Use this for initialization
    void Start()
    {
        Application.targetFrameRate = 60;
        loaded = false;
        offBeatObjects = new GameObject[2];
        offBeatObjects[0] = Instantiate(offbeat);
        offBeatObjects[1] = Instantiate(offbeat);
        offBeatObjects[0].SetActive(false);
        offBeatObjects[1].SetActive(false);

        offBeatCounter = 0;

        nextPermittedBeat = 0;
        GlobalData.GOButtonsReady = false;

        touches = new Vector3[2];
        screenHeight = Camera.main.orthographicSize * 2.0f;
        screenWidth = Camera.main.aspect * screenHeight;

        effect = Camera.main.GetComponent<effects>();
        cameraMiss = Camera.main.GetComponent<MissFrame>();
        cameraShake = Camera.main.GetComponent<Shake>();

        latestTouch = 0;
        lastTouchPosition = new Vector2(100, 100);
        fxParticles = new GameObject[2];
        fxParticles[0] = Instantiate(FXParticles);
        fxParticles[1] = Instantiate(FXParticles);
        fxParticlesControl = new CustomParticles[2];
        fxParticlesControl[0] = fxParticles[0].GetComponent<CustomParticles>();
        fxParticlesControl[1] = fxParticles[1].GetComponent<CustomParticles>();

        UpdateColors();

        fxPointer = 0;
        wrongClicks = 0;
        beat = GlobalData.beat;

        wiggleSpace = GlobalData.wiggleSpace;

        time = 0;
        god = GameObject.Find("God").GetComponent<GodDeath>();
        /* PAUSE READY
        pause = GameObject.Find("Pause").GetComponent<Pause>();
        */
        bool missed = false;
        uint oneInXMissing = 3;
        float distanceCoef = (700.0f / 500.0f);
        float expectedBunnyLifetime = GetJumpTimeFromLinearTime((350.0f / (250.0f)) * distanceCoef, beat) / (0.48f / beat);

        realDuration = 0;
        if (audio.clip)
            realDuration = audio.clip.length;
        if (percentage)
        {
            percentageS = percentage.GetComponent<Percentage>();
            percentageS.realDuration = Mathf.Floor((realDuration - expectedBunnyLifetime) / beat) * beat + expectedBunnyLifetime;
        }

        if (GOPercentage)
        {
            GOPercentageS = GOPercentage.GetComponent<Percentage>();
            GOPercentageS.realDuration = Mathf.Floor((realDuration - expectedBunnyLifetime) / beat) * beat + expectedBunnyLifetime;
        }

        float[] angles = new float[5] { Mathf.PI / 2.0f, 4.6f, 2.65f, 5.6f, 1.4f };
        if (beat == 0.375f)
        {
            oneInXMissing = 5;
        }
        effectObject = GameObject.Find("Offbeat");

        GameObject bunnObject = GameObject.Find("Bunnies");
        if (bunnObject)
        {
            bunz = bunnObject.GetComponent<Bunnies>();
        }
        GameObject screen = GameObject.Find("Screen");
        int latestColor = 0;
        Color[] colorsRhino = new Color[3]{
            new Color(0,1.0f,91.0f / 255.0f),
            new Color(0,1.0f,187.0f / 255.0f),
            new Color(144.0f / 255.0f,0,1),
        };

        Color[] colorsBear = new Color[3]{
            new Color(1,0,0),
            new Color(1,212.0f / 255.0f,0),
            new Color(1,0,110.0f / 255.0f),
        };

        Color[] colorsBull = new Color[3]{
            new Color(1.0f,0,238 / 255.0f),
            new Color(0,206 / 255.0f,229 / 255.0f),
            new Color(144 / 255.0f,0,1),
        };

        Color[] colors = null;
        switch (GlobalData.selectedGod)
        {
            case GlobalData.Gods.RHINO:
                colors = colorsRhino;
                break;
            case GlobalData.Gods.BEAR:
                colors = colorsBear;
                break;
            case GlobalData.Gods.BULL:
                colors = colorsBull;
                break;
        }

        for (int i = 0; i < maxCount; i++)
        {
            float endTime = 0;
            if (missing && (Random.Range(0, oneInXMissing)) == 0 && !missed && i > 2 && endTime < 50.0f)
            {
                missed = true;
            } else if (missed)
            {
                missed = false;
            }
            if (!missed)
            {
                GameObject bunny = null;
                if (bunz)
                {
                    bunny = bunz.bunnies[i];
                    bunny.SetActive(true);
                }
                else
                {
                    bunny = Instantiate(bunnyPrefab);
                    bunny.GetComponent<BunnyJump>().Startingu();
                    bunny.SetActive(true);
                }
                bunny.transform.parent = null;
                BunnyJump bunnyJumpS = bunny.GetComponent<BunnyJump>();
                bunnyJumpS.parentTransform = screen.transform;
                bunnyJumpS.startTime = i * beat;
                endTime = i * beat + expectedBunnyLifetime;
                bunnyJumpS.expectedBunnyLifetime = expectedBunnyLifetime;
                bunnyJumpS.beat = beat;
                bunnyJumpS.god = god;
                int randomColor = Random.Range(0, 3);
                while (randomColor == latestColor)
                {
                    randomColor = Random.Range(0, 3);
                }
                latestColor = randomColor;
                bunnyJumpS.color = colors[randomColor];
                bunnyJumpS.wiggleSpace = wiggleSpace;
                if (!randomSpawn)
                {
                    bunnyJumpS.angle = angles[i];
                }
                float scale = Random.Range(0.8f, 1.4f);
                bunny.GetComponent<Transform>().localScale = new Vector3(scale, scale, 1);
                bunnyJumpS.Init();
                bunnyCount++;
                bunnies.Add(bunnyJumpS);
            }
            if (endTime + beat > realDuration)
            {
                break;
            }
        }

        freq = 1.0f / audio.clip.frequency;

        startTime = AudioSettings.dspTime;

        minOffset = 0.0f;
        maxOffset = 0.0f;
    }