예제 #1
0
    void FixedUpdate()
    {
        //************ POSITION METHOD *************
        int newData = bleReceiver.getData();

        // If requested movement is up and we aren't at the top of the screen
        if (newData == 1 && currentPos != 1)
        {
            rb2d.position = rb2d.position + new Vector2(0, OFFSET_VAL);
            currentPos++;
            // If requested movement is down and we aren't at the bottom of the screen
        }
        else if (newData == -1 && currentPos != -1)
        {
            rb2d.position = rb2d.position + new Vector2(0, -OFFSET_VAL);
            currentPos--;
        }

        //************ FORCE METHOD ****************
//		float data = (float) bleReceiver.getData ();
//		// If force too low, don't shift
//		if (Mathf.Abs (data) < 4.0f)
//			data = 0.0f;
//		Rigidbody2D rb2d = GetComponent<Rigidbody2D> ();
//		rb2d.AddForce ((new Vector2 (0.0f, data)) * 0.01f, ForceMode2D.Impulse);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        //************ POSITION METHOD *************
        int newData = bleReceiver.getData();

        // If requested movement is up and we aren't at the top of the screen
        if (newData == 1 && currentPos != 1)
        {
            rb2d.position = rb2d.position + new Vector2(0, OFFSET_VAL);
            currentPos++;
            // If requested movement is down and we aren't at the bottom of the screen
        }
        else if (newData == -1 && currentPos != -1)
        {
            rb2d.position = rb2d.position + new Vector2(0, -OFFSET_VAL);
            currentPos--;
        }

        //************ OLD METHOD ******************
//		//rb2d.position = new Vector2 (rb2d.position.x, (float) bleReceiver.getData ()/50.0f);
//		float data = (float)bleReceiver.getData ();
//		// If force too low, don't shift
//		if (Mathf.Abs (data) < 8.0f)
//			data = 0.0f;
//		rb2d.AddForce ((new Vector2 (0.0f, data)) * 0.01f, ForceMode2D.Impulse);
//
//		// Die by being off screen
//		Vector2 screenPosition = Camera.main.WorldToScreenPoint (transform.position);
//		if (screenPosition.y > Screen.height || screenPosition.y < 0) {
//			Die ();
//		}
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        // Get lilypad positions
        GameObject g         = GameObject.Find("ExtraPads");
        Generate   generator = g.GetComponent <Generate> ();

        padLocations = generator.pads;

//		// Get the bluetooth data
//		string strData = bleReceiver.getData ();
//		bleVal = int.Parse(strData);

        // Get the bluetooth data
        bleVal = bleReceiver.getData();

        if (bleVal < THRESHOLD && !isPreviousHigh && !jumpInProgress)
        {
            // Initiate a jump
            jumpInProgress = true;
            jumpNum++;
            isPreviousHigh = true;
            if (jumpNum == 1)
            {
                // Position of the first lilypad
                startPoint = new Vector2(0.64f, 0.1f);
            }
            else
            {
                // Position of a lilypad that is not the first lilypad (first one is
                // hard coded in Unity and is not in the dictionary).
                startPoint = padLocations[jumpNum - 2];
            }
        }
        else if (bleVal > THRESHOLD)
        {
            isPreviousHigh = false;
        }

        // If jump button pressed and we aren't already jumping
//		if (Input.GetKeyUp ("space") && !jumpInProgress) {
//			// Initiate a jump
//			jumpInProgress = true;
//			jumpNum++;
//		}

        if (jumpNum > 4)
        {
            // Give encouragement
            StartCoroutine("displayEncouragement");
            // Restart game
            transform.position = new Vector2(0.45f, 0.1f);
            jumpNum            = 0;
            jumpInProgress     = false;
        }

        if (jumpInProgress)
        {
            Debug.Log(padLocations [jumpNum - 1]);
            transform.position = CalculateCubicBezierPoint(t,
                                                           startPoint, (Vector2)startPoint + new Vector2(1.5f, 2.0f),
                                                           (Vector2)startPoint + new Vector2(3.0f, 2.0f),
                                                           padLocations[jumpNum - 1]);
            // Update time
            t += 0.02f;
            if (Mathf.Abs(1.0f - t) < 0.001f)
            {
                jumpInProgress = false;
                t = 0.0f;
            }
        }

        //Debug.Log ("Battery level is " + BatteryLevelPlugin.GetBatteryLevel());
        //Debug.Log ("Bluetooth Device found named: " + BatteryLevelPlugin.GetBleDeviceName ());
        //UnityToastExample.ScanDevices ();

        // We get the text property of our receiver
//		javaMessage = jc.GetStatic<string> ("text");
//		Debug.Log ("RECEIVED MESSAGE is: " + javaMessage);

        // Get the data from the ble module
        //Debug.Log ("Data value is: " + blerec.getData ());
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        // Get the bluetooth data
        bleVal = bleReceiver.getData();
        // Cap weight to 300
        int capVal = 300;

        if (bleVal > capVal)
        {
            bleVal = capVal;
        }
        // ********* POSITIONAL METHOD **************************************
        // Transform the data into a position coordinate y = (-7/50)x + 40
        // assuming max weight is the value 300 and min weight is zero,
        // max position is 40, min position is -2
        yCoordinate = (-7.0f / 50.0f) * bleVal + 40.0f;
        if (yCoordinate > 40.0f)
        {
            yCoordinate = 40.0f;
        }
        // Give encouragement
        if (yCoordinate > 25.0f)
        {
            encouragement.text = encouragementList[encouragementIdx];
            isHigh             = true;
        }
        else
        {
            if (isHigh)
            {
                isHigh = false;
                if (++encouragementIdx == encouragementList.Length)
                {
                    encouragementIdx = 0;
                }
            }
            encouragement.text = "";
        }
        transform.position = Vector2.Lerp(rb2d.position, new Vector2(rb2d.position.x, yCoordinate), Time.deltaTime * 5.0f);
        // Stop the rocket from shooting out of the top of the screen
//		if (rb2d.position.y > 42.0f) {
//			rb2d.position = new Vector2(-1.86f, 40.0f);
//		}
        // ********* END POSITIONAL METHOD **********************************


//		// ********* THRUST METHOD ******************************************
//		int inverseBleVal = capVal - bleVal;
//		// Check gradient
//		int gradient = inverseBleVal - lastProcessedVal;
//		// If small gradient / no data / rocket too high
//		if (gradient < GRADIENT_THRESH || bleVal == -1 || rb2d.position.y > 25) {
//			// apply no thrust
//			gradient = 0;
//		}
//		// Stop rocket from going off screen
//		if (rb2d.position.y > 42.0f) {
//			rb2d.position = new Vector2(-1.86f, 40.0f);
//		}
//		// Cap gradient if it is too extreme
//		if (gradient > MAX_GRADIENT)
//			gradient = MAX_GRADIENT;
//
//		Vector2 thrustForce = new Vector2 (0.0f, gradient*THRUST_CONSTANT);
//		rb2d.AddForce (thrustForce, ForceMode2D.Impulse);
//		lastProcessedVal = inverseBleVal;
//		// ********* END THRUST METHOD **************************************
    }