Ejemplo n.º 1
0
    private void ProcessTouch()
    {
        // Don't let the player use multiple fingers, and don't run if there's no input.
        if (Input.touchCount > 1 || Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (touch.phase == TouchPhase.Began)
        {
            // Touch pos in world space.
            touchOrigin = Utility.ConvertToWorldPoint(touch.position);
            // Find closest cut based on world space touch pos.
            activeCut = FindClosestCutPoint(touchOrigin);
            // If no cuts available (list must be empty), don't select.
            if (activeCut != null)
            {
                activeCut.SetSelected();
            }
        }
        else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
        {
            // If no cut selected, don't do anything to avoid null error.
            if (activeCut == null)
            {
                return;
            }

            var touchVector = Utility.ConvertToWorldPoint(touch.position) - touchOrigin;
            // The touch has ended -- try to perform a cut -> doesn't mean that this cut will be a success.
            PerformCut(activeCut, touchVector);
        }
    }
Ejemplo n.º 2
0
    // Only here for debugging on PC.
    //private bool holding = false;
    private void ProcessMouse()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //holding = true;
            touchOrigin = Utility.ConvertToWorldPoint(Input.mousePosition);
            activeCut   = FindClosestCutPoint(touchOrigin);

            if (activeCut != null)
            {
                activeCut.SetSelected();
            }

            //Debug.DrawLine(touchOrigin, activeCut.transform.position, Color.red, 10f);
        }
        else if (Input.GetMouseButtonUp(0))
        {
            //holding = false;
            if (activeCut == null)
            {
                return;
            }

            var touchVector = Utility.ConvertToWorldPoint(Input.mousePosition) - touchOrigin;
            PerformCut(activeCut, touchVector);
        }
    }
Ejemplo n.º 3
0
    private void GameLoop()
    {
        // If it's time to spawn another cut.
        if (timeIntervalCounter > Mathf.Lerp(activeDifficultySettings.InitialSpawnInterval,
                                             activeDifficultySettings.EndSpawnInterval,
                                             activeDifficultySettings.SpawnCurve.Evaluate(timeCounter / CountdownObj.StartTime)) &&
            CutPrefab.SpawnTime < CountdownObj.CurrentTimeRemaining)
        {
            // TODO: maybe add a parent to keep the scene clean.
            var         cutPosition = GenerateNewCutPosition();
            NewCutPoint clone       = Instantiate(CutPrefab, cutPosition, Quaternion.identity, cutContainer.transform);
            // TODO: this is a bit messy, move GemObject calculation somewhere else.
            clone.CutVector          = -(cutPosition - GemSpawnManager.Gem.transform.position) * 1.8f;  // make the vector a bit longer.
            clone.onSpawnComplete   += cut => activeCuts.AddLast(cut);
            clone.onTimeoutComplete += cut => activeCuts.Remove(cut);
            SFX.Play("Cutting_circle_appears");

            timeIntervalCounter = 0;
        }

        // If player is struggling, show instructions again.
        if (missDurationCounter > MissDurationTimeout)
        {
            missDurationCounter = 0;
            InstructionManager.PushInstruction();
        }

        timeIntervalCounter += Time.deltaTime;
        timeCounter         += Time.deltaTime;
        missDurationCounter += Time.deltaTime;
    }
Ejemplo n.º 4
0
    // Find cut point closest to another position.
    private NewCutPoint FindClosestCutPoint(Vector3 worldPoint)
    {
        if (activeCuts.Count == 0)
        {
            return(null);
        }

        NewCutPoint closest     = null;
        float       minDistance = Mathf.Infinity;

        foreach (var cut in activeCuts)
        {
            float dist = Vector3.Distance(cut.transform.position, worldPoint);
            if (dist < minDistance)
            {
                closest     = cut;
                minDistance = dist;
            }
        }

        //SFX.Play("sound");
        return(closest);
    }
Ejemplo n.º 5
0
    private void PerformCut(NewCutPoint cut, Vector3 cutVector)
    {
        float val = CalculateCloseness(cut.CutVector, cutVector);

        //Debug.Log("Calculated a closeness value of: " + val);
        if (val < activeDifficultySettings.AcceptanceThreshold)
        {
            // TODO: animation.
            SFX.Play("Cutting_good_cut");
            missDurationCounter = 0;
            PushGem(cutVector, 1 - val);
            PointsManager.AddPoints((1 - val) * activeDifficultySettings.CutRewardMultiplier);
            //QualityBar.Add((1-val) * CutRewardMultiplier, true);
            activeCuts.Remove(cut);
            Destroy(cut.gameObject);
            activeCut = null;
        }
        else
        {
            // TODO: fail sound / animation.
            cut.UnsetSelected();
        }
    }