//creates a new big bubbles using two bubbles in game and their pair private GameObject CreateNewBigBubble(GameObject bubbleA, GameObject bubbleB, IntPair pair) { GameObject BiggestBubble = (GameObject)Instantiate(biggerBubble, new Vector3(xvalues, yvalues, 0f), Quaternion.identity); //giving bubble context BiggestBubble.AddComponent <hasSmallBubbles>(); hasSmallBubbles item = BiggestBubble.GetComponent <hasSmallBubbles>(); Vector3 size = new Vector3(0.008f, 0.008f, 0f); BiggestBubble.transform.localScale = size; item.spriteNum = 0; item.colorNum = 0; item.bubbleA = bubbleA; item.bubbleB = bubbleB; item.pair = pair; bigBubsCreated.Add(BiggestBubble); return(BiggestBubble); }
//Remove dead bubbles - kinect bug workaround private void clearDeadBubbles() { for (int t = 0; t < bigBubsCreated.Count; t++) { // Get context of bigBubsCreated[t] hasSmallBubbles item = bigBubsCreated[t].GetComponent <hasSmallBubbles> (); GameObject bubbleA; GameObject bubbleB; bubbleA = item.bubbleA; bubbleB = item.bubbleB; if ((bubbleA == null) || (bubbleB == null)) { //Destory Big Bubble Destroy(bigBubsCreated[t]); //Reshow Smaller Bubble if still exists if (bubbleA != null) { bubbleA.GetComponent <SpriteRenderer> ().enabled = true; } if (bubbleB != null) { bubbleB.GetComponent <SpriteRenderer> ().enabled = true; } //Remove things from activated arrays activatedSmlBubs.Remove(bubbleA); activatedSmlBubs.Remove(bubbleB); bigBubsCreated.Remove(bigBubsCreated[t]); t--; } } }
} // End checkHighFive public void checkHandShake() { //Check through BigBubs to see if they are hand shaking for (int k = 0; k < bigBubsCreated.Count; k++) { //Get each bubble from big bubble hasSmallBubbles item = bigBubsCreated[k].GetComponent <hasSmallBubbles>(); GameObject BubbleA = item.bubbleA; GameObject BubbleB = item.bubbleB; //create list of kinect bodies List <Body> trackedIDs = new List <Body>(); foreach (Body body in bodies) { if (body == null) { continue; } if (body.IsTracked) { trackedIDs.Add(body); } } //Get Kinect objects of Bubble A and Bubble B for (int i = 0; i < trackedIDs.Count; i++) { if (Convert.ToInt64(trackedIDs[i].TrackingId) == Int64.Parse(BubbleA.name)) { KinectA = trackedIDs[i]; } } for (int i = 0; i < trackedIDs.Count; i++) { if (Convert.ToInt64(trackedIDs[i].TrackingId) == Int64.Parse(BubbleB.name)) { KinectB = trackedIDs[i]; } } //Get Hand and shoulder of Bubble A and Bubble B Windows.Kinect.Joint KinectA_Hand = KinectA.Joints[JointType.HandRight]; Windows.Kinect.Joint KinectB_Hand = KinectB.Joints[JointType.HandRight]; Windows.Kinect.Joint KinectB_Shoulder = KinectB.Joints[JointType.ShoulderRight]; Windows.Kinect.Joint KinectA_Shoulder = KinectA.Joints[JointType.ShoulderRight]; bool handshakeDetected = false; //Check if they are highshaking if (KinectA_Hand.Position.Y < KinectA_Shoulder.Position.Y && KinectB_Hand.Position.Y < KinectB_Shoulder.Position.Y && ObjectDistanceKinectJoint(KinectA_Hand, KinectB_Hand) < 0.1f) { handshakeDetected = true; } //if highshaking do something (floor bubble change color) if (handshakeDetected) { //startColor = colors[0]; //for(int i = 0; i<colors.Length; i++) { // currentColor = Color.Lerp(startColor, colors[i], Mathf.PingPong(Time.time, 5)); //} Renderer renderer = bigBubsCreated[k].GetComponent <Renderer>(); //renderer.material.color = currentColor; //What is the current sprite if (bigBubsCreated[k].GetComponent <hasSmallBubbles>().delay < 0) { if (bigBubsCreated[k].GetComponent <hasSmallBubbles>().colorNum == colors.Length - 1) { bigBubsCreated[k].GetComponent <SpriteRenderer>().color = colors[0]; bigBubsCreated[k].GetComponent <hasSmallBubbles>().colorNum = 0; renderer.material.color = colors[0]; Debug.Log("I am in the last color list " + colors[0]); } else { bigBubsCreated[k].GetComponent <hasSmallBubbles>().colorNum++; int changeme = bigBubsCreated[k].GetComponent <hasSmallBubbles>().colorNum; bigBubsCreated[k].GetComponent <SpriteRenderer>().color = colors[changeme]; renderer.material.color = colors[changeme]; Debug.Log("I am in going through the list " + colors[changeme]); } bigBubsCreated[k].GetComponent <hasSmallBubbles>().delay = 0.5f; } } } } // End checkHandShake
public void checkHighFive() { //Check through BigBubs to see if they are high fiving for (int k = 0; k < bigBubsCreated.Count; k++) { //Get each bubble from big bubble hasSmallBubbles item = bigBubsCreated[k].GetComponent <hasSmallBubbles>(); GameObject BubbleA = item.bubbleA; GameObject BubbleB = item.bubbleB; //create list of kinect bodies List <Body> trackedIDs = new List <Body>(); foreach (Body body in bodies) { if (body == null) { continue; } if (body.IsTracked) { trackedIDs.Add(body); } } //Get Kinect objects of Bubble A and Bubble B for (int i = 0; i < trackedIDs.Count; i++) { if (Convert.ToInt64(trackedIDs[i].TrackingId) == Int64.Parse(BubbleA.name)) { KinectA = trackedIDs[i]; } } for (int i = 0; i < trackedIDs.Count; i++) { if (Convert.ToInt64(trackedIDs[i].TrackingId) == Int64.Parse(BubbleB.name)) { KinectB = trackedIDs[i]; } } //Get Hand and shoulder of Bubble A and Bubble B Windows.Kinect.Joint KinectA_Hand = KinectA.Joints[JointType.HandRight]; Windows.Kinect.Joint KinectA_LeftHand = KinectA.Joints[JointType.HandLeft]; Windows.Kinect.Joint KinectB_Hand = KinectB.Joints[JointType.HandRight]; Windows.Kinect.Joint KinectB_LeftHand = KinectB.Joints[JointType.HandLeft]; Windows.Kinect.Joint KinectB_Shoulder = KinectB.Joints[JointType.ShoulderRight]; Windows.Kinect.Joint KinectA_Shoulder = KinectA.Joints[JointType.ShoulderRight]; bool highfiveDetected = false; //Check if they are highfiving if ((KinectA_Hand.Position.Y > KinectA_Shoulder.Position.Y || KinectA_LeftHand.Position.Y > KinectA_Shoulder.Position.Y) && (KinectB_Hand.Position.Y > KinectB_Shoulder.Position.Y || KinectB_LeftHand.Position.Y > KinectB_Shoulder.Position.Y) && (ObjectDistanceKinectJoint(KinectA_Hand, KinectB_Hand) < 0.1f || ObjectDistanceKinectJoint(KinectA_Hand, KinectB_LeftHand) < 0.1f || ObjectDistanceKinectJoint(KinectA_LeftHand, KinectB_Hand) < 0.1f || ObjectDistanceKinectJoint(KinectA_LeftHand, KinectB_LeftHand) < 0.1f)) { highfiveDetected = true; } //if highfiving do something (loop through list of different shapes) if (highfiveDetected) { //GameObject person = (GameObject)Instantiate (star, new Vector3 (0f, 0f, 0f), Quaternion.identity); //What is the current sprite if (bigBubsCreated [k].GetComponent <hasSmallBubbles> ().delay < 0) { if (bigBubsCreated [k].GetComponent <hasSmallBubbles> ().spriteNum == sprites.Length - 1) { bigBubsCreated [k].GetComponent <SpriteRenderer> ().sprite = sprites [0]; bigBubsCreated [k].GetComponent <hasSmallBubbles> ().spriteNum = 0; } else { bigBubsCreated [k].GetComponent <hasSmallBubbles> ().spriteNum++; int changeme = bigBubsCreated [k].GetComponent <hasSmallBubbles> ().spriteNum; bigBubsCreated [k].GetComponent <SpriteRenderer> ().sprite = sprites [changeme]; } bigBubsCreated [k].GetComponent <hasSmallBubbles> ().delay = 0.5f; } } } } // End checkHighFive
private void distanceStuff() { //Create/Update list of all possible pairs grabbingPairs(); for (int k = 0; k < pairs.Count; k++) { IntPair pair = pairs[k]; int pairFirstDigit = pair.firstDigit; int pairSecondDigit = pair.secondDigit; GameObject bubbleA = bubblesInGame[pairFirstDigit]; GameObject bubbleB = bubblesInGame[pairSecondDigit]; float distab = objectDistance(bubbleA, bubbleB); float firstPosx = (bubbleA.transform.position.x); float secondPosx = (bubbleB.transform.position.x); float firstPosy = (bubbleA.transform.position.y); float secondPosy = (bubbleB.transform.position.y); xvalues = ((firstPosx + secondPosx) / 2f); yvalues = ((firstPosy + secondPosy) / 2f); //if distance is close enough(simulated collision) if (distab <= 0.9f) { //Disables GameObject childs for lineRenderer //bubbleA.transform.GetChild(pairFirstDigit).GetComponent<SpriteRenderer>().enabled = false; //bubbleB.transform.GetChild(pairSecondDigit).GetComponent<SpriteRenderer>().enabled = false; //check if already activated small bubbles bool alreadyPaired = false; for (int t = 0; t < activatedSmlBubs.Count; t++) { if (activatedSmlBubs[t] == bubbleA || activatedSmlBubs[t] == bubbleB) { alreadyPaired = true; } } //If small bubbles in pair are not activated, active pair them! if (!alreadyPaired) { //Check if Big Bubble already exists bool existsAlready = false; for (int t = 0; t < bigBubsCreated.Count; t++) { //get bigBubsCreated[t] context hasSmallBubbles item = bigBubsCreated [t].GetComponent <hasSmallBubbles> (); IntPair bigBubsPair = item.pair; if (pair.Equals(bigBubsPair)) { existsAlready = true; } } //If Big Bubble doesn't already exist, create it if (!existsAlready) { CreateNewBigBubble(bubbleA, bubbleB, pair); //add smaller bubbles to activatedSmBubs activatedSmlBubs.Add(bubbleA); activatedSmlBubs.Add(bubbleB); //remove smaller bubbles bubbleA.GetComponent <SpriteRenderer> ().enabled = false; bubbleB.GetComponent <SpriteRenderer> ().enabled = false; for (int p = 0; p < 6; p++) { LineRenderer lrA = bubbleA.transform.GetChild(p).GetComponent <LineRenderer>(); lrA.enabled = false; LineRenderer lrB = bubbleB.transform.GetChild(p).GetComponent <LineRenderer>(); lrB.enabled = false; } } } } else { //Destroy Big Bubble bool isEmpty = !bigBubsCreated.Any(); if (!isEmpty) { for (int t = 0; t < bigBubsCreated.Count; t++) { // Get context of bigBubsCreated[t] hasSmallBubbles item = bigBubsCreated [t].GetComponent <hasSmallBubbles> (); IntPair bigBubsPair = item.pair; //Check if bigBubsCreated[t] is this pair or not, if not leave it, if yes destroy it if (pair.Equals(bigBubsPair)) { //Destory Big Bubble Destroy(bigBubsCreated[t]); //Remove things from activated arrays bigBubsCreated.Remove(bigBubsCreated[t]); activatedSmlBubs.Remove(bubbleA); activatedSmlBubs.Remove(bubbleB); //Show small bubbles again bubbleA.GetComponent <SpriteRenderer>().enabled = true; bubbleB.GetComponent <SpriteRenderer>().enabled = true; } } } //Draw line between pair if small bubbles not already in a big bubble #nolinesluts bool bubblesCanLine = true; for (int p = 0; p < activatedSmlBubs.Count; p++) { if (bubbleA == activatedSmlBubs [p] || bubbleB == activatedSmlBubs [p]) { bubblesCanLine = false; } } if (bubblesCanLine) { drawLineRenderer(pair); } } } }