Пример #1
0
    public static FizzyoDevice Instance()
    {
        if (instance == null)
        {
            lock (threadLock)
            {
                if (instance == null)
                {
                    instance = GameObject.FindObjectOfType <FizzyoDevice>();
                }

                if (instance == null)
                {
                    instance = (new GameObject("EasySingleton")).AddComponent <FizzyoDevice>();
                }
            }
        }
        return(instance);
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        //get the pressure value of our fizzyo device communicated as a joystick axis 0-1 blow out -1-0 breath in
        //float fizzyoVal = Input.GetAxisRaw("Horizontal");

        //get the pressure value from our fizzyo device or logged pressure data if useRecordedData is set to true.
        float pressure = FizzyoDevice.Instance().Pressure();

        float destHeight = maxHeight * Mathf.Min((pressure / maxFizzyoPressure), 1);

        float y;

        if (smoothMovement)
        {
            y = transform.position.y + ((destHeight - transform.position.y) * smoothing);
        }
        else
        {
            y = destHeight;
        }

        float x = transform.position.x;

        if (y > 0.15f)
        {
            xSpeed += (destXSpeed - xSpeed) * smoothing;
            x      += xSpeed;
        }
        else
        {
            xSpeed = 0;
        }
        transform.position = new Vector3(x, y, transform.position.z);

        if (FizzyoDevice.Instance().ButtonDown() || Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("Fire1"))
        {
            var pos = transform.position;
            pos.y += 0.5f;
            Instantiate(missilePrefab, pos, transform.rotation);
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        float pressure = FizzyoDevice.Instance().Pressure();


        //animate breath particles
        //particleSystem.startSpeed = pressure * 500;
        //particleSystem.startLifetime = pressure * 1;

        ////set pressure bar height
        //float destHeight = -20 * pressure;
        //float y = pressureBar.transform.localPosition.y + ((destHeight - pressureBar.transform.localPosition.y) * smoothing);
        //pressureBar.transform.localPosition = new Vector3(pressureBar.transform.localPosition.x, y, pressureBar.transform.localPosition.z);


        if (pressure > minPressureThreshold)
        {
            maxPressureReading = pressure;
            blowingStopwatch.Start();
            int timeToStart = (int)(countdownToStart - (blowingStopwatch.ElapsedMilliseconds / 1000));
            //Debug.Log("Time To Start = " + timeToStart);
            if (timeToStart > 0)
            {
                //startText.text = "" + timeToStart;
            }
            else
            {
                //Save the max recorded pressure to use to scale sensor input during gameplay.
                PlayerPrefs.SetFloat("Max Fizzyo Pressure", maxPressureReading);
            }
        }
        else
        {
            blowingStopwatch.Stop();
        }
        Debug.Log("Pressure =" + pressure);
    }
Пример #4
0
 // Use this for initialization
 void Start()
 {
     LevelGenerator.LevelGenerate();
     rb2d = GetComponent <Rigidbody2D>();
     fd   = new FizzyoDevice();
 }
Пример #5
0
    // Use this for initialization
    void Start()
    {
        pressures  = new List <float>();
        this.isBad = true;
        FizzyoDevice insatnce = FizzyoDevice.Instance();

        this.gameObject.GetComponent <SpriteRenderer>().enabled = false;

        if (PlayerPrefs.HasKey("Max Fizzyo Pressure"))
        {
            maxFizzyoPressure = PlayerPrefs.GetFloat("Max Fizzyo Pressure");
        }

        breath = new BreathRecogniser(maxFizzyoPressure, 11f);
        breath.ExhalationComplete += ExhalationCompleteHandler;
        //apply default material
        if (lineMaterial == null)
        {
            lineMaterial = new Material(Shader.Find("Sprites/Default"));
        }
        // Store inital position
        respawn = this.transform.position;


        // spawn trajectoryPoints
        if (trajectoryPointPrefab != null)
        {
            for (int i = 0; i < noOfTrajectoryPoints; i++)
            {
                GameObject dot = (GameObject)Instantiate(trajectoryPointPrefab);
                //dot.tag = "trajectoryPoint";
                dot.GetComponent <Renderer>().enabled = false;
                trajectoryPoints.Insert(i, dot);
            }

            for (int i = 0; i < noOfTrajectoryPoints; i++)
            {
                GameObject dot = (GameObject)Instantiate(trajectoryPointPrefab);
                //dot.tag = "trajectoryPoint";
                dot.GetComponent <Renderer>().enabled = false;
                oldTrajectoryPoints.Insert(i, dot);
            }
        }
        else
        {
            Debug.LogWarning("Trajectory prefab is null. Please choose one.");
        }

        // Setup a line renderer
        if (enableSolidLine)
        {
            GameObject m_line_object = new GameObject("line");
            m_line_object.AddComponent <LineRenderer>();
            m_line = m_line_object.GetComponent <LineRenderer>();
            m_line.positionCount     = noOfTrajectoryPoints;
            m_line.colorGradient     = lineColour;
            m_line.numCornerVertices = cornerVerts;
            m_line.numCapVertices    = endVerts;
            m_line.widthCurve        = widthCurve;
            m_line.textureMode       = textureMode;
            m_line.material          = lineMaterial;
            m_line.material.SetFloat("RepeatX", tileAmount);
        }
    }
Пример #6
0
 private bool ShouldClear()
 {
     return(FizzyoDevice.Instance().Pressure() >= breathThreshold);
 }