示例#1
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Current Pointer"))
     {
         PointerLabel fraction = other.gameObject.GetComponent <PointerLabel> ();
         fraction.SetValue(this.numerator, this.denominator);
     }
 }
    private IEnumerator MovePointer(float numeratorDestination, float denominatorDestination)
    {
        bool isCorrect = false;

//		pauseController.PauseGame ();
        GameController_v7.Instance.GetPauseController().Pause();
//		cameraZoom.ZoomTowards (gameObject.transform.position);
        this.AdjustCamera();
        highlightRenderer.enabled          = true;
        highlightRenderer.sortingLayerName = "Needle";
        highlightRenderer.sortingOrder     = (-1);
        highlightRenderer.SetPosition(0, pointer.transform.position);

        this.pointer.SetActive(true);
        this.pointer.GetComponent <PointerLabel> ().SetValue(0, (int)denominatorDestination);
        float pointerOriginalPosX = this.pointer.transform.localPosition.x;

        bool isPositiveMovement = (this.targetValNumerator > this.initialCurrentPointerNumerator);
        int  multiplier         = 1;

        if (isPositiveMovement)
        {
            multiplier = 1;
        }
        else
        {
            multiplier = -1;
        }

        this.currentPointerNumberLine.IsPositiveMovement(isPositiveMovement);
        this.currentPointerNumberLine.SetLineLength(this.lineLength);

        this.currentPointerNumberLine.ShowSmallerFraction();

        this.currentPointerNumberLine.Partition((int)denominatorDestination + 1);
        float xCoords = this.currentPointerNumberLine.GetSegments()[0].transform.localPosition.x + multiplier * (numeratorDestination * Vector2.Distance(this.currentPointerNumberLine.GetSegments()[0].transform.position, this.currentPointerNumberLine.GetSegments()[1].transform.position));
        float answer  = (this.initialCurrentPointerNumerator / this.initialCurrentPointerDenominator) + ((numeratorDestination * multiplier) / denominatorDestination);

        if (Mathf.Approximately(answer, (this.targetValNumerator / this.targetValDenominator)))
        {
            isCorrect = true;
        }

        float        startTime           = Time.time;
        Vector2      pos                 = new Vector2(xCoords, this.pointer.transform.localPosition.y);
        float        journeyLength       = Vector2.Distance(this.pointer.transform.localPosition, pos);
        PointerLabel currentPointerLabel = pointer.GetComponent <PointerLabel> ();
        int          currentMaxNumerator = Mathf.Abs(currentPointerLabel.GetDenominator());

        highlightRenderer.positionCount = 2;
        Vector3[] listPositions = new Vector3[2];

        Physics2D.autoSimulation = false;
        while (pos.x != this.pointer.transform.localPosition.x)
        {
            Physics2D.Simulate(POINTER_MOVEMENT_SPEED * Time.unscaledDeltaTime);
            this.pointer.transform.localPosition = Vector2.MoveTowards(this.pointer.transform.localPosition, pos, POINTER_MOVEMENT_SPEED * Time.unscaledDeltaTime);

            listPositions [0] = new Vector3(currentPointerNumberLine.GetComponent <LineRenderer>().GetPosition(0).x, highlightTransform.localPosition.y, -1.0f);

            listPositions [1] = new Vector3(pointer.transform.localPosition.x, highlightTransform.localPosition.y, -1.0f);             //pointer.transform.position.y, (float)-0.1);
            highlightRenderer.SetPositions(listPositions);



            Debug.Log("Numerator: " + Mathf.Abs(currentPointerLabel.GetNumerator()));
            Debug.Log("Max Numerator: " + currentMaxNumerator);

            if (Mathf.Abs(currentPointerLabel.GetNumerator()) >= currentMaxNumerator)
            {
                currentPointerNumberLine.ExtendLine();
                currentMaxNumerator++;
            }

            yield return(new WaitForSeconds(0.0f));
        }
        this.pointer.transform.localPosition = pos;
        this.pointer.GetComponent <PointerLabel> ().SetValue((int)numeratorDestination, (int)denominatorDestination);

        Physics2D.autoSimulation = true;
//		GameController_v7.Instance.GetPauseController ().Continue ();
//		cameraZoom.shouldZoomIn = false;
//		cameraZoom.shouldZoomOut = true;

//		if (Mathf.Approximately (this.pointer.transform.position.x, this.targetPointer.transform.position.x)) {
        if (isCorrect)
        {
//			StartCoroutine (this.UpdateHighlight ());
//			yield return new WaitForSeconds (CORRECT_DELAY); // If CORRECT
            yield return(new WaitForSecondsRealtime(CORRECT_DELAY));

            this.resultsUI.PlaySuccess();
//			GameController_v7.Instance.GetPauseController ().Continue ();
//			StopCoroutine (this.UpdateHighlight ());

            // TODO: uncomment on tally fix :(
//            if (entry.isSimilar == null)
//                entry.isSimilar = ((int)targetValDenominator == (int)denominatorDestination) ? true : false;
//            if (entry.isProper == null)
//                entry.isProper = ((int)numeratorDestination < (int)denominatorDestination) ? true : false;
//            if (entry.initialValue == null)
//                entry.initialValue = new Tuple<int, int>((int)initialCurrentPointerNumerator, (int)initialCurrentPointerDenominator);
//            if (entry.targetValue == null)
//                entry.targetValue = new Tuple<int, int>((int)targetValNumerator, (int)targetValDenominator);
//            if (entry.actualAnswer == null)
//                entry.actualAnswer = new Tuple<int, int>(Math.Abs((int)targetValNumerator - (int)initialCurrentPointerNumerator), (int)targetValDenominator);
//            if (entry.attemptedAnswers == null)
//                entry.attemptedAnswers = new List<Tuple<int, int>>();
//
//            entry.isDeadThroughLCD = isNumberLineUpdated;
//            entry.attemptedAnswers.Add(new Tuple<int, int>((int)numeratorDestination, (int)denominatorDestination));
//            entry.numberOfAttempts++;
//            entry.timeSolved = System.DateTime.Now;
//			if (initialCurrentPointerDenominator == targetValDenominator)
//				entry.topic = EnemyEntry.Topic.Similar;
//			else
//				entry.topic = EnemyEntry.Topic.Dissimilar;

            enemyHealth.Death();
            yield return(new WaitForSecondsRealtime(1.0f));

            this.ReturnCamera();
            GameController_v7.Instance.GetPauseController().Continue();
        }
        else
        {
            // TODO: temporarily commented out, conflict when hitting 2 enemies :'(
            isNumberLineUpdated = false;
//            if (entry.isSimilar == null)
//                entry.isSimilar = ((int)targetValDenominator == (int)denominatorDestination) ? true : false;
//            if (entry.isProper == null)
//                entry.isProper = ((int)numeratorDestination < (int)denominatorDestination) ? true : false;
//            if (entry.initialValue == null)
//                entry.initialValue = new Tuple<int, int>((int)initialCurrentPointerNumerator, (int)initialCurrentPointerDenominator);
//            if (entry.targetValue == null)
//                entry.targetValue = new Tuple<int, int>((int)targetValNumerator, (int)targetValDenominator);
//            if (entry.actualAnswer == null)
//                entry.actualAnswer = new Tuple<int, int>(Mathf.Abs((int)targetValNumerator - (int)initialCurrentPointerNumerator), (int)targetValDenominator);
//            if (entry.attemptedAnswers == null)
//                entry.attemptedAnswers = new List<Tuple<int, int>>();
//            entry.isDeadThroughLCD = isNumberLineUpdated;
//            entry.attemptedAnswers.Add(new Tuple<int, int>((int)numeratorDestination, (int)denominatorDestination));
//            entry.numberOfAttempts++;


//            StartCoroutine (this.UpdateHighlight ());
            SoundManager.Instance.Play(AudibleNames.Results.MISTAKE, false);
            yield return(new WaitForSecondsRealtime(WRONG_DELAY));             // If WRONG

            this.ReturnCamera();
            GameController_v7.Instance.GetPauseController().Continue();
//			cameraZoom.shouldZoomIn = false;
//			cameraZoom.shouldZoomOut = true;
//			StopCoroutine (this.UpdateHighlight ());

            startTime     = Time.time;
            pos           = new Vector2(pointerOriginalPosX, this.pointer.transform.localPosition.y);
            journeyLength = Vector2.Distance(this.transform.localPosition, pos);
            listPositions = new Vector3[2];
            while (pos.x != this.pointer.transform.localPosition.x)
            {
                this.pointer.transform.localPosition = Vector2.MoveTowards(this.pointer.transform.localPosition, pos, 2 * POINTER_MOVEMENT_SPEED * Time.deltaTime);
                // Pointer movement speed of returning

                listPositions [0] = new Vector3(currentPointerNumberLine.GetComponent <LineRenderer>().GetPosition(0).x, highlightTransform.localPosition.y, -1.0f);
                listPositions [1] = new Vector3(pointer.transform.localPosition.x, highlightTransform.localPosition.y, highlightRenderer.transform.position.z);                 //pointer.transform.position.y, (float)-0.1);
                highlightRenderer.SetPositions(listPositions);

                yield return(new WaitForSeconds(0.0f));
            }
        }

        this.currentPointerNumberLine.PurgeSegments();
//		this.currentPointerNumberLine.gameObject.SetActive (false);
        this.currentPointerNumberLine.HideSmallerFraction();
//		this.pointer.SetActive (false);
        highlightRenderer.enabled = false;
        this.isPlaying            = false;
//        if (entry.timeWeaponRemoved == null)
//            entry.timeWeaponRemoved = new List<DateTime>();
//        entry.timeWeaponRemoved.Add(System.DateTime.Now);

//		DataManager.UpdateEnemyEntry(DataManager.GetEnemyLastKey(), entry);
//		Debug.Log ("<b>NUMBER OF ATTEMPTS: " + String.Join(",",DataManager.GetIntColumn (StringConstants.TableNames.ENEMY, StringConstants.ColumnNames.NUMBER_OF_ATTEMPTS)) + "</b>");
    }
示例#3
0
    private IEnumerator MovePointer(float numerator, float denominator)
    {
        fractionLabel.SetActive(true);
//		pauseController.PauseGame ();
        GameController_v7.Instance.GetPauseController().Pause();
        int i = (int)numerator;

        if (numerator > denominator)
        {
            for (int j = 0; j < (numerator - denominator); j++)
            {
                ExtendLine();
            }
        }

        PointerLabel label = lcdAnswerPointer.GetComponent <PointerLabel> ();

        float startTime     = Time.unscaledTime;
        float journeyLength = Vector2.Distance(this.lcdAnswerPointer.transform.position, segments[i].transform.position);
        float distCovered;
        float fracJourney;

        lineRenderer.positionCount = 2;
        Vector3[] listPositions = new Vector3[2];

        float distanceMultiplier = 0.25f;

        Physics2D.autoSimulation = false;
        while (this.lcdAnswerPointer.transform.position != segments[i].transform.position)
        {
            distCovered = (Time.unscaledTime - startTime) * distanceMultiplier;
            fracJourney = distCovered / journeyLength;
            Physics2D.Simulate(fracJourney);
            this.lcdAnswerPointer.transform.position = Vector3.MoveTowards(this.lcdAnswerPointer.transform.position, segments[i].transform.position, fracJourney);

            listPositions [0] = new Vector3(this.transform.position.x, this.transform.position.y, -1.0f);
            listPositions [1] = new Vector3(lcdAnswerPointer.transform.position.x, this.transform.position.y, -1.0f);             //pointer.transform.position.y, (float)-0.1);
            highlightRenderer.SetPositions(listPositions);

            yield return(null);
        }

        label.SetValue(segments [i].GetComponent <SegmentCollider> ().GetNumerator(), segments [i].GetComponent <SegmentCollider> ().GetDenominator());

        for (int j = 0; j < 2; j++)
        {
            yield return(new WaitForSecondsRealtime(1.0f));
        }

        while (this.lcdAnswerPointer.transform.position != this.segments [0].transform.position)
        {
            distCovered = (Time.unscaledTime - startTime) * distanceMultiplier;
            fracJourney = distCovered / journeyLength;
            Physics2D.Simulate(fracJourney);
            this.lcdAnswerPointer.transform.position = Vector3.MoveTowards(this.lcdAnswerPointer.transform.position, this.segments [0].transform.position, fracJourney);

            listPositions [0] = new Vector3(this.transform.position.x, this.transform.position.y, -1.0f);
            listPositions [1] = new Vector3(lcdAnswerPointer.transform.position.x, this.transform.position.y, -1.0f);             //pointer.transform.position.y, (float)-0.1);
            highlightRenderer.SetPositions(listPositions);

            yield return(null);
        }
        Physics2D.autoSimulation = true;
//		pauseController.ContinueGame ();
        GameController_v7.Instance.GetPauseController().Continue();
        Destroy(this.gameObject);
    }