Ejemplo n.º 1
0
 //If we got something wrong in practice, update the screens
 private bool set_wrong_practice_screen(practice_screen p)
 {
     if (p != practice_screen.None)
     {
         if (p == practice_screen.Target)
         {
             practice_wrong_target.SetActive(true);
         }
         else
         {
             practice_wrong_catch.SetActive(true);
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
    //starting routines
    void Awake()
    {
        listening             = false;
        practice              = true;
        endGame               = false;
        wrong_practice        = practice_screen.None;
        reaction_times_catch  = new List <float>();
        reaction_times_search = new List <float>();
        start_time            = 0;
        end_time              = 0;

        //initialize list of child sprites
        child_sprites = new List <Image>();
        foreach (Transform child in transform)
        {
            child_sprites.Add(child.GetComponent <Image>());
        }
    }
Ejemplo n.º 3
0
    //Main coroutine that listens for button presses during the game
    IEnumerator listen()
    {
        while (true)
        {
            //Update time
            time += Time.deltaTime;

            //If game should be over
            if (endGame)
            {
                //First set wrong practice screen
                if (set_wrong_practice_screen(wrong_practice))
                {
                    this.gameObject.SetActive(false);
                    break;
                }

                //Next check if we should turn off practice
                if (practice)
                {
                    endGame  = false;
                    practice = false;
                    visited.clear();
                    outro_practice.SetActive(true);
                    this.GetComponent <target_picker>().ClearGens();
                    //remove all listeners
                }

                //Else, game is totally finished, go to outro
                else
                {
                    outro.SetActive(true);
                    end_time = Time.time;
                }

                //Don't need me anymore :(
                this.gameObject.SetActive(false);
                break;
            }

            //Check if we have a timeout
            if (time >= max_time)
            {
                if (practice)
                {
                    redX.SetActive(true);
                }
                else
                {
                    crosshair.SetActive(true);
                }

                //hide sprites from view
                foreach (Image i in child_sprites)
                {
                    i.sprite = null;
                }

                //display image for one second
                yield return(new WaitForSeconds(1f));

                //update data fields (if in-game)
                if (!practice)
                {
                    if (random_gen.isTarget)
                    {
                        timeout_target++;
                        reaction_times_search.Add(max_time);
                    }
                    else
                    {
                        timeout_catch++;
                        reaction_times_catch.Add(max_time);
                    }
                }

                //call listener function using default value
                input_out.Invoke(hand.NotPresent);

                //reset time
                time = 0;
            }

            //If player indicates there is no target
            else if (Input.GetKeyDown(NotPresent))
            {
                //If practice is wrong
                if (practice && random_gen.isTarget)
                {
                    wrong_practice = practice_screen.Target;
                    redX.SetActive(true);
                }
                else  //we are in-game or practice is correct
                {
                    crosshair.SetActive(true);
                }

                //hide sprites from view
                foreach (Image i in child_sprites)
                {
                    i.sprite = null;
                }

                //display image for one second
                yield return(new WaitForSeconds(1f));

                //update data fields (if in-game)
                if (!practice)
                {
                    if (random_gen.isTarget)
                    {
                        wrong_target++;
                        reaction_times_search.Add(time);
                    }
                    else
                    {
                        corr_catch++;
                        reaction_times_catch.Add(time);
                    }
                }

                //call listener function using default value
                input_out.Invoke(hand.NotPresent);

                //reset time
                time = 0;
            }

            //If players indicates there is a target
            else if (Input.GetKeyDown(Present))
            {
                //If practice is wrong
                if (practice && !(random_gen.isTarget))
                {
                    wrong_practice = practice_screen.Catch;
                    redX.SetActive(true);
                }
                else  //we are in-game or practice was correct
                {
                    crosshair.SetActive(true);
                }

                //hide sprites from view
                foreach (Image i in child_sprites)
                {
                    i.sprite = null;
                }

                //display image for one second
                yield return(new WaitForSeconds(1f));

                //update data fields (if in-game)
                if (!practice)
                {
                    if (random_gen.isTarget)
                    {
                        corr_target++;
                        reaction_times_search.Add(time);
                    }
                    else
                    {
                        wrong_catch++;
                        reaction_times_catch.Add(time);
                    }
                }

                //call listener function using default value
                input_out.Invoke(hand.Present);

                //reset time
                time = 0;
            }

            //Disable all on-screen items
            redX.SetActive(false);
            crosshair.SetActive(false);

            //Check if we are in practice mode and got a wrong answer
            if (set_wrong_practice_screen(wrong_practice))
            {
                wrong_practice = practice_screen.None;
                this.gameObject.SetActive(false);
                break;
            }

            yield return(null);
        } //end while loop
    }     //end coroutine