private void checkRelease() { updateLine(); if (twoFingerInput) { if (Input.GetMouseButtonUp(1)) { checkForRelease = false; twoFingerInput = false; lastTimeStamp = Time.time; lastPath = null; lastGesture = gesture.other; } } else { if (Input.GetMouseButtonUp(0)) { checkForRelease = false; addGesture(Input.mousePosition.x, Input.mousePosition.y); setGesture(); } else if (checkUpdateDistanceReached(Input.mousePosition)) { addGesture(Input.mousePosition.x, Input.mousePosition.y); } } }
private void SetRandomSealGesture() { var gestures = Enum.GetValues(typeof(gesture)); sealGesture = (gesture)gestures.GetValue(new System.Random().Next(gestures.Length)); spriteRenderer.sprite = spriteResources[(int)sealGesture]; }
// Use this for initialization void Start() { laserRenderer = leapTeleport.handLaser; currentGesture = gesture.none; oneHV = false; twoHV = false; LaT = false; HFE = false; LHC = false; LH = false; RH = false; TC = false; RHP = false; }
// Update is called once per frame void Update() { // for touch input for (int i = 0; i < Input.touchCount; i++) { gesture currentTouch = detectTouch(Input.GetTouch(i)); Debug.Log(currentTouch + "(" + Input.GetTouch(i).deltaPosition.sqrMagnitude + ")"); Debug.Log(Input.GetTouch(i).deltaPosition.sqrMagnitude); switch (currentTouch) { case gesture.swipeLeft: transform.Translate(Vector2.left * movementSpeed); break; case gesture.swipeRight: transform.Translate(Vector2.right * movementSpeed); break; case gesture.tap: SendMessage("shoot"); break; default: break; } } // keyboard input if (Input.GetKeyDown(KeyCode.Space)) { SendMessage("shoot"); } if (Input.GetKey(KeyCode.LeftArrow) && transform.position.x > leftBoundaries) { transform.Translate(Vector2.left * movementSpeed); } if (Input.GetKey(KeyCode.RightArrow) && transform.position.x <= rightBoundaries) { transform.Translate(Vector2.right * movementSpeed); } }
private void setGesture() { lastTimeStamp = Time.time; lastPath = removeDuplicates(path); if (Time.time - timer < TAP_TIME) { lastGesture = gesture.tap; } else if (lastPath.Count == 1) { switch (lastPath.First.Value) { case direction.up: lastGesture = gesture.up; break; case direction.down: lastGesture = gesture.down; break; case direction.left: lastGesture = gesture.left; break; case direction.right: lastGesture = gesture.right; break; } } else if (lastPath.Count == 2) { switch (lastPath.First.Value) { case direction.up: switch (lastPath.First.Next.Value) { case direction.down: lastGesture = gesture.upDown; break; case direction.left: lastGesture = gesture.upLeft; break; case direction.right: lastGesture = gesture.upRight; break; } break; case direction.down: switch (lastPath.First.Next.Value) { case direction.up: lastGesture = gesture.downUp; break; case direction.left: lastGesture = gesture.downLeft; break; case direction.right: lastGesture = gesture.downRight; break; } break; case direction.left: switch (lastPath.First.Next.Value) { case direction.up: lastGesture = gesture.leftUp; break; case direction.down: lastGesture = gesture.leftDown; break; case direction.right: lastGesture = gesture.leftRight; break; } break; case direction.right: switch (lastPath.First.Next.Value) { case direction.up: lastGesture = gesture.rightUp; break; case direction.down: lastGesture = gesture.rightDown; break; case direction.left: lastGesture = gesture.rightLeft; break; } break; } } else { lastGesture = gesture.other; if (lastPath.Count == 4 || lastPath.Count == 5) { direction[] pathArray = new direction[5]; LinkedListNode <direction> next = lastPath.First; for (int i = 0; i < 5; i++) { if (next != null) { pathArray[i] = next.Value; next = next.Next; } else { print("???"); pathArray[i] = direction.none; break; } } if (pathArray[0] == direction.left && pathArray[1] == direction.down && pathArray[2] == direction.right && pathArray[3] == direction.up && (pathArray[4] == direction.left || pathArray[4] == direction.none)) { lastGesture = gesture.circleLeft; } else if (pathArray[0] == direction.right && pathArray[1] == direction.down && pathArray[2] == direction.left && pathArray[3] == direction.up && (pathArray[4] == direction.right || pathArray[4] == direction.none)) { lastGesture = gesture.circleRight; } } } }
// Update is called once per frame void Update() { mobile(); // determine which phase the touch is in switch (phase) { // init values when touch begins case myPhase.BEGAN: swipe = false; hold = true; startPos = t.position; startTime = Time.time; dir = gesture.NONE; break; // check for possible type of touch while moving case myPhase.MOVED: float time = Time.time - startTime; if (hold && (time > touchLength)) { touch = gesture.HOLD; } gesture temp; // check that its not a tap if (Vector2.Distance(t.position, startPos) > minDist) { hold = false; // determine what direction touch is in if (Mathf.Abs(t.position.x - startPos.x) > Mathf.Abs(t.position.y - startPos.y)) { if (t.position.x - startPos.x > 0) { temp = gesture.RIGHT; } else { temp = gesture.LEFT; } } else { if (t.position.y - startPos.y > 0) { temp = gesture.UP; } else { temp = gesture.DOWN; } } // touch is not a swipe if it changes directions if (dir != gesture.NONE) { if (dir != temp) { swipe = false; } } // otherwise it is a swipe else { swipe = true; dir = temp; } } break; // determine type of touch as touch ends case myPhase.ENDED: if (touch == gesture.HOLD) { touch = gesture.NONE; } else if (swipe) { touch = dir; } else if (t.tapCount > 1) { touch = gesture.DOUBLE; } else { touch = gesture.NONE; } break; case myPhase.NONE: touch = gesture.NONE; break; } }
// coroutine for setting commands IEnumerator setCommand() { // set up conditions for game to start endGame = false; float r = -0.5f; int chance = 0; checking_command = false; swipeIt.currentScore = 0; scoreText.text = ""; startText.text = ""; Time.timeScale = 1 - increaseAmount; _audio.music.pitch = 1 - increaseAmount; StartCoroutine(setSpeed()); // start game _audio.music.Play(); yield return(new WaitForSeconds(waitTime)); // give commands until game ends while (!endGame) { switch (swipeIt.mode) { case swipeIt.gameMode.single: // pick a random command except pass it r = Random.Range(0, 5); break; case swipeIt.gameMode.multi: // pick a random command including pass it r = Random.Range(0, 5); if (chance >= 5) { r = 5; chance = 0; } else { chance += Random.Range(1, 6); } break; case swipeIt.gameMode.tutorial: r += 0.5f; if (r > 4f) { endGame = true; } break; default: // pick a random command except pass it r = Random.Range(0, 5); break; } switch (Mathf.FloorToInt(r)) { case 0: command = gesture.DOUBLE; chosenCommand = _audio.doubleTap; chosenSprite = doubleTap; break; case 1: command = gesture.DOWN; chosenCommand = _audio.down; chosenSprite = arrowDown; break; case 2: command = gesture.LEFT; chosenCommand = _audio.left; chosenSprite = arrowLeft; break; case 3: command = gesture.RIGHT; chosenCommand = _audio.right; chosenSprite = arrowRight; break; case 4: command = gesture.UP; chosenCommand = _audio.up; chosenSprite = arrowUp; break; case 5: command = gesture.NONE; chosenCommand = _audio.passIt; chosenSprite = passIt; break; default: command = gesture.UP; chosenCommand = _audio.perfect; chosenSprite = arrowUp; break; } // play the audio for the command _audio.command.PlayOneShot(chosenCommand); // 0.4 is average audio clip length. wait to try to sync audio with visual yield return(new WaitForSecondsRealtime(0.4f)); if (command == gesture.NONE) { scoreText.text = "PASS IT"; } else { scoreText.text = command.ToString(); } image.sprite = chosenSprite; checking_command = true; perfect = true; yield return(new WaitForSeconds(0.8f * turnTime)); perfect = false; yield return(new WaitForSeconds(0.2f * turnTime)); if (checking_command) { checking_command = false; _audio.rating.PlayOneShot(_audio.bad); if (swipeIt.mode != swipeIt.gameMode.tutorial) { endGame = true; } Handheld.Vibrate(); Handheld.Vibrate(); } scoreText.text = ""; image.sprite = null; yield return(new WaitForSeconds(waitTime)); } // play game over sound and stop music _audio.rating.PlayOneShot(_audio.gameOver); _audio.music.Stop(); yield return(new WaitForSeconds(_audio.gameOver.length + 0.5f)); if (swipeIt.mode == swipeIt.gameMode.tutorial) { swipeIt.mode = swipeIt.gameMode.single; } SceneManager.LoadScene("gameover"); }
private void setGesture() { lastTimeStamp = Time.time; lastPath = removeDuplicates(path); if (Time.time - timer < TAP_TIME) { lastGesture = gesture.tap; } else if (lastPath.Count == 1) { switch (lastPath.First.Value) { case direction.up: lastGesture = gesture.up; break; case direction.down: lastGesture = gesture.down; break; case direction.left: lastGesture = gesture.left; break; case direction.right: lastGesture = gesture.right; break; } } else if (lastPath.Count == 2) { switch (lastPath.First.Value) { case direction.up: switch (lastPath.First.Next.Value) { case direction.down: lastGesture = gesture.upDown; break; case direction.left: lastGesture = gesture.upLeft; break; case direction.right: lastGesture = gesture.upRight; break; } break; case direction.down: switch (lastPath.First.Next.Value) { case direction.up: lastGesture = gesture.downUp; break; case direction.left: lastGesture = gesture.downLeft; break; case direction.right: lastGesture = gesture.downRight; break; } break; case direction.left: switch (lastPath.First.Next.Value) { case direction.up: lastGesture = gesture.leftUp; break; case direction.down: lastGesture = gesture.leftDown; break; case direction.right: lastGesture = gesture.leftRight; break; } break; case direction.right: switch (lastPath.First.Next.Value) { case direction.up: lastGesture = gesture.rightUp; break; case direction.down: lastGesture = gesture.rightDown; break; case direction.left: lastGesture = gesture.rightLeft; break; } break; } } else { lastGesture = gesture.other; if (lastPath.Count == 4 || lastPath.Count == 5) { direction[] pathArray = new direction[5]; LinkedListNode<direction> next = lastPath.First; for (int i = 0; i < 5; i++) { if (next != null) { pathArray[i] = next.Value; next = next.Next; } else { print("???"); pathArray[i] = direction.none; break; } } if (pathArray[0] == direction.left && pathArray[1] == direction.down && pathArray[2] == direction.right && pathArray[3] == direction.up && (pathArray[4] == direction.left || pathArray[4] == direction.none)) { lastGesture = gesture.circleLeft; } else if (pathArray[0] == direction.right && pathArray[1] == direction.down && pathArray[2] == direction.left && pathArray[3] == direction.up && (pathArray[4] == direction.right || pathArray[4] == direction.none)) { lastGesture = gesture.circleRight; } } } }