Пример #1
0
    // Use this for initialization
    private void Start()
    {
        // Initialize text values
        TimerText.text = "Time: " + Mathf.Round(_timeLeft);
        ScoreText.text = "Score: " + _score;

        // Set done button listener
        Button btn = DoneButton.GetComponent <Button>();

        btn.onClick.AddListener(DoneButtonOnClick);

        AudioManager.Play("easy");
        _currentSong = "easy";

        XOffset = _camera.pixelWidth / 2.0f;
        YOffset = _camera.pixelHeight / 2.0f;

        // TODO: make these positions relative to camera size
        float ratiox = _camera.pixelWidth / 1920.0f;
        float ratioy = _camera.pixelHeight / 1920.0f;

        _postItSpawnPosition  = new Vector3(-700 * ratiox + XOffset, -280 * ratioy + YOffset, 0);
        _paperTargetPosition  = new Vector3(630 * ratiox + XOffset, 60 * ratioy + YOffset, 0);
        _paperSpawnPosition   = new Vector3(630 * ratiox + XOffset, 1040 * ratioy + YOffset, 0);
        _paperDespawnPosition = new Vector3(630 * ratiox + XOffset, -960 * ratioy + YOffset, 0);

        // Generate first post it
        _postItGenerator = new PostItGenerator();

        // Generate first paper
        StartCountDownText.text = Mathf.Round(_countdown - 1).ToString(CultureInfo.InvariantCulture);
        system = EventSystem.current;
    }
Пример #2
0
    // Update is called once per frame
    private void Update()
    {
        if (_gameStarted) // Game has started
        {
            if (!_gameOver)
            {
                // Update timer
                _timeLeft     -= Time.deltaTime;
                TimerText.text = "Time: " + Mathf.Round(_timeLeft);

                // Check if time has run out
                if (_timeLeft <= 0.0f)
                {
                    // Display game over screen with score
                    AudioManager.Stop(_currentSong);
                    AudioManager.Stop("slice");
                    AudioManager.Play("yooo");
                    _gameOver = true;
                    return;
                }

                if (Input.GetKeyDown(KeyCode.Return))
                {
                    _doneButtonClicked = true;
                }

                // Check if done button is clicked
                if (_doneButtonClicked && !_animatingPapers)
                {
                    if (IsPaperCorrect())
                    {
                        AudioManager.Play("paper");
                        // Update score
                        _score++;
                        if (_score == 7)
                        {
                            AudioManager.Stop("easy");
                            AudioManager.Play("medium");
                            _currentSong = "medium";
                        }
                        else if (_score == 15)
                        {
                            AudioManager.Stop("medium");
                            AudioManager.Play("hard");
                            _currentSong = "hard";
                        }

                        ScoreText.text = "Score: " + _score;

                        _timeLeft += 10 * (1 - 1 / (1 + Mathf.Exp(-0.1f * (_score - 15))));
                    }
                    else
                    {
                        //User submitted a form which was incorrect
                        // Decrement lives by one
                        _livesRemaining--;

                        CameraShake.ShakeCamera(Amount, Duration);

                        switch (_livesRemaining)
                        {
                        case 4:
                            Instantiate(Blood, new Vector3(-4.61f, -4.63f, -100.0f), Quaternion.identity);
                            AudioManager.Play("slice");
                            break;

                        case 3:
                            Instantiate(Blood, new Vector3(-3.91f, -3.49f, -100.0f), Quaternion.identity);
                            AudioManager.Play("slice");
                            break;

                        case 2:
                            Instantiate(Blood, new Vector3(-3.15f, -2.98f, -100.0f), Quaternion.identity);
                            AudioManager.Play("slice");
                            break;

                        case 1:
                            Instantiate(Blood, new Vector3(-2.08f, -2.98f, -100.0f), Quaternion.identity);
                            AudioManager.Play("slice");
                            break;

                        case 0:
                            Instantiate(Blood, new Vector3(-0.44f, -4.72f, -100.0f), Quaternion.identity);
                            AudioManager.Stop(_currentSong);
                            AudioManager.Stop("slice");
                            AudioManager.Play("yooo");
                            _gameOver = true;
                            break;
                        }


                        //Change the input source image of the hand to remove a finger.
                        HandSprite.GetComponent <SpriteRenderer>().sprite =
                            Resources.Load <Sprite>("images/" + "pixelated_hand_" + _livesRemaining + "lives");
                    }

                    // Remove old post it
                    Destroy(_currentPostIt.gameObject);
                    if (!_gameOver)
                    {
                        // Get new post it
                        GeneratePostIt();

                        // Create new paper
                        GeneratePaper();

                        _animatingPapers = true;
                    }
                }

                // If animating incoming and leaving papers
                if (_animatingPapers)
                {
                    // Move both papers down until incoming is in correct position, then delete old paper
                    float step = 8000.0f * Time.deltaTime;
                    _currentPaper.GetComponent <RectTransform>().position =
                        Vector3.MoveTowards(_currentPaper.GetComponent <RectTransform>().position,
                                            _paperTargetPosition, step);
                    _leavingPaper.GetComponent <RectTransform>().position =
                        Vector3.MoveTowards(_leavingPaper.GetComponent <RectTransform>().position,
                                            _paperDespawnPosition, step);

                    // At target position
                    if (_currentPaper.GetComponent <RectTransform>().position == _paperTargetPosition)
                    {
                        _animatingPapers = false;

                        Destroy(_leavingPaper.gameObject);

                        _doneButtonClicked = false;
                        DoneButton.enabled = true;
                    }
                }
            }
            else
            {
                // Game over
                GameOverMenu.SetActive(true);
                GameOverScreen.SetActive(true);
                if (_currentPaper != null)
                {
                    Destroy(_currentPaper.gameObject);
                }
                if (DoneButton != null)
                {
                    Destroy(DoneButton.gameObject);
                }
            }
        }
        else // Doing countdown timer
        {
            _countdown -= Time.deltaTime;

            if (_countdown > 1.5f)
            {
                StartCountDownText.text = Mathf.Round(_countdown - 1).ToString(CultureInfo.InvariantCulture);
            }
            else if (_countdown > 0.0f)
            {
                StartCountDownText.text = "Start";
            }
            else
            {
                _gameStarted = true;
                StartCountDownText.gameObject.SetActive(false);

                // Generate first post it
                _postItGenerator = new PostItGenerator();
                GeneratePostIt();

                // Generate first paper
                GeneratePaper();
                _currentPaper.GetComponent <RectTransform>().position = _paperTargetPosition;
            }
        }
    }