Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (timeRemaining > 0 && playing)
        {
            timeRemaining -= Time.deltaTime;
            timer_sprite.transform.Rotate(Vector3.back * (360 * Time.deltaTime / TIME_TO_COUNT));

            if (send_next)
            {
                Ballot created_ballot = Instantiate(ballot, new Vector3(0f + Random.Range(-1f, 1f), -10f + Random.Range(-1f, 1f), 0f + Random.Range(-1f, 1f)), Quaternion.Euler(0, 0, Random.Range(-5, 5)));
                int    candidate      = Random.Range(0, 100) < johny_chance ? 2 : 1;
                if (timeRemaining > TIME_TO_COUNT * 3 / 4)
                {
                    candidate = Random.Range(0, 100) < ((johny_chance / 3) * 2) ? 2 : 1;
                    created_ballot.GetComponent <Ballot>().SetCandidate(candidate, 1);
                }
                else if (timeRemaining > TIME_TO_COUNT / 2)
                {
                    created_ballot.GetComponent <Ballot>().SetCandidate(candidate, 2);
                }
                else if (timeRemaining > TIME_TO_COUNT / 4)
                {
                    created_ballot.GetComponent <Ballot>().SetCandidate(candidate, 3);
                }
                else
                {
                    created_ballot.GetComponent <Ballot>().SetCandidate(candidate, 4);
                }
                created_ballot.GetComponent <Ballot>().MoveTo(new Vector3(0f, -1f, 0f));
                current_ballot = created_ballot;
                send_next      = false;
            }

            if (!send_next)
            {
                if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
                {
                    votes[current_ballot.GetComponent <Ballot>().GetCandidate()]++;
                    UpdatePerentages();

                    if (current_ballot.GetComponent <Ballot>().GetCandidate() == 1)
                    {
                        eagle.PlaySound();
                    }

                    current_ballot.GetComponent <Ballot>().MoveToAndDestroy(new Vector3(-15f, 0f, 0f));
                    send_next = true;
                }
                if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
                {
                    if (current_ballot.GetComponent <Ballot>().GetCandidate() == 2)
                    {
                        eagle.PlaySound();
                    }

                    current_ballot.GetComponent <Ballot>().MoveToAndDestroy(new Vector3(15f, 0f, 0f));
                    shredder.Shake();
                    send_next = true;
                }
            }

            if (timeRemaining < TIME_TO_COUNT / 4 && !clock.shaking)
            {
                clock.StartShaking(timeRemaining);
            }
        }
        else if (playing)
        {
            StartCoroutine(StopTheCount());
            playing = false;
        }
        else if (!playing && Input.GetKeyDown(KeyCode.Space) && can_restart)
        {
            Destroy(title_screen);

            rank_table.GetComponent <RankTable>().ResetPositonAndStopSounds();

            johny.GetComponent <Bythem>().ResetPosition();
            ronald.GetComponent <Dump>().ResetPosition();

            timeRemaining = TIME_TO_COUNT;

            votes       = new Dictionary <int, int>();
            percentages = new Dictionary <int, float>();

            // Initial votes
            votes.Add(1, 20);   // Ronald
            votes.Add(2, 4);    // Johny
            UpdatePerentages();

            playing              = true;
            send_next            = true;
            can_restart          = false;
            restart_text.enabled = false;

            clock.StartCountdown();
        }
    }