Ejemplo n.º 1
0
    private float waitingAcceleration; // sum of position movements while waiting for cue.

    #endregion Fields

    #region Methods

    /*
     * Resets trial, timer and state. increments number of trials passed.
     * */
    public void Reset()
    {
        testTimer = null;
        TrainingMain.numTrials++;
        leftCenter = false;
        averageAcceleration = 0.0f;
        waitingAcceleration = 0.0f;
        numMeasures = 0;
        accelerated = false;
        accelerationTime = "-1";
        coordinateRecording = false;

        if( playerMovementScript.GetZ() > endZ ) {
            state = "complete";
            //Main.state = "complete";
        }
        else {
            state = "centering";
        }

        coords.Clear();
    }
Ejemplo n.º 2
0
        public virtual void CheckTraining(Mobile from, Mobile target)
        {
            if (from == null || from.Deleted || target == null || target.Deleted)
            {
                if (TrainingTimer != null)
                {
                    TrainingTimer.Stop();
                    TrainingTimer = null;
                }

                return;
            }

            if (TrainingTimer == null)
            {
                TrainingLocation = from.Location;

                TrainingTimer = PollTimer.CreateInstance(
                    TimeSpan.FromSeconds(1.0),
                    () =>
                {
                    if (from.Location != TrainingLocation)
                    {
                        TrainingTimer.Stop();
                        TrainingTimer = null;
                        return;
                    }

                    BeginThrow(from, target);
                });
            }
            else if (from.Location != TrainingLocation)
            {
                TrainingTimer.Stop();
                TrainingTimer = null;
            }
        }
Ejemplo n.º 3
0
    // Update is called once per frame
    public void Run()
    {
        switch( state )
        {
        case "initialize":
            state = "centering";
            break;

        case "centering":
            if( centerScriptL.Test(this.player) && centerScriptR.Test(this.player) )
            {
                centerScriptL.SetCenteredMaterial(true);
                centerScriptR.SetCenteredMaterial(true);

                if( CallTimer( delayDur ) )
                {
                    goto case "set variables";
                }
                else
                {
                    numMeasures += 2;
                    waitingAcceleration +=
                        Mathf.Sqrt( Mathf.Pow( (lastXLeft - leftPointer.transform.position.x), 2 ) + Mathf.Pow( (lastYLeft - leftPointer.transform.position.y), 2 ) ) +
                        Mathf.Sqrt( Mathf.Pow( (lastXRight - rightPointer.transform.position.x), 2 ) + Mathf.Pow( (lastYRight - rightPointer.transform.position.y), 2 ) );

                    UpdatePreviousCoordinates();
                    break;
                }
            }
            else
            {
                centerScriptL.SetCenteredMaterial(false);
                centerScriptR.SetCenteredMaterial(false);

                testTimer = null;
                break;
            }
        case "set variables":
            varis = new TrainingVariables( signalRadius, center.position );
            //thisCue = Instantiate( cue, Main.center, cylQuat ) as GameObject;
            thisCue = Instantiate( cue, center.position, cylQuat ) as GameObject;

            thisCue.renderer.material = cueMaterials[varis.cueIndex];
            state = "cue";
            goto case "cue";
        case "cue":
            if( centerScriptL.Test(this.player) && centerScriptR.Test(this.player) )
            {
                if( CallTimer( cueDur ) )
                {
                    Destroy( thisCue );
                    state = "wait";
                    goto case "wait";
                }
                else
                {
                    break;
                }
            }
            else
            {
                testTimer = null;
                Destroy( thisCue );
                state = "centering";
                break;
            }
        case "wait":

            if( centerScriptL.Test(this.player) && centerScriptR.Test(this.player) )
            {
                // wait for random range time and show signal.
                if( CallTimer( Random.Range(1.25f, 1.75f) ) )
                {
                    averageAcceleration = waitingAcceleration / numMeasures;
                    state = "signal";
                    goto case "signal";
                }
                else
                {
                    break;
                }
            }
            else // user moved after cue and before signal.
            {
                ErrorFeedback(new Vector3(0.0f, 0.0f, 0.0f));
                WriteData( false, "0", -0.001F, rt );
                StoreJSONTrial( false, "0", -0.001F, rt );
                Reset();
                break;
            }
        case "signal":
            thisSig = Instantiate(signal, varis.signalVec, Quaternion.identity) as GameObject;
            thisSig.GetComponent<TrainingSignal>().SetTestingScript(this.gameObject);
            if( !varis.valid )
            {
                thisSig.GetComponent<TrainingSignal>().setValid(false);
            }
            signalTime = Time.time;
            state = "testing";

            UpdatePreviousCoordinates();

            goto case "testing";
        case "testing":

            DetectAcceleration();
            UpdatePreviousCoordinates();

            if( (!centerScriptL.Test(this.player) || !centerScriptR.Test(this.player) ) && varis.valid && !leftCenter) // user moved on a valid signal, count reaction time
            {
                rt = Time.time - signalTime;
                leftCenter = true;
            }

            coordinateRecording = true;

            if( CallTimer( reactDur ) )
            {
                // valid signal that user didn't touch
                if( varis.valid ) {
                    ErrorFeedback(thisSig.transform.position);

                    WriteData( false, "1", -0.001F, rt );
                    StoreJSONTrial( false, "1", -0.001F, rt );
                }
                // user did not move on an invalid signal -> OK
                else {
                    ValidMovePopup(new Vector3(0.0f, 0.0f, 0.0f));
                    // apply acceleration equal to 0.5f RT
                    playerMovementScript.SetSpeeds(0.8f);
                    playerMovementScript.ThrusterFeedback(0.8f);
                    this.audio.PlayOneShot(thrusterSound);

                    WriteData( true, "0", -0.001F, -0.001F );
                    StoreJSONTrial( true, "0", -0.001F, -0.001F );
                }
                Destroy( thisSig );
                Reset();
                break;
            }
            else if( !centerScriptL.Test(this.player) || !centerScriptR.Test(this.player) ) // user left center
            {
                if( !varis.valid ) // user moved on invalid signal, count as a full trial
                {
                    ErrorFeedback(thisSig.transform.position);

                    WriteData( false, "0", -0.001F, Time.time - signalTime );
                    StoreJSONTrial( false, "0", -0.001F, Time.time - signalTime );

                    Destroy( thisSig );
                    Reset();
                    break;
                }
            }
            break;
        case "complete":
                GracefulGoodbye();
                break;
        default:
            break;
        }
    }
Ejemplo n.º 4
0
 bool CallTimer( float dur )
 {
     if( testTimer == null )
     {
         testTimer = new TrainingTimer( Time.time, dur );
         return false;
     }
     else
     {
         if( testTimer.Check( Time.time ) )
         {
             testTimer = null;
             return true;
         }
         else
         {
             return false;
         }
     }
 }