/// <summary> /// Spawn a hand object. /// </summary> /// <param name="movementType">Movement type for hand. Defaults to random selection</param> private void SpawnHand(HandMovement movementType = HandMovement.RANDOM) { // TODO: Have this method attach the spawned hand to the guy, put it at a reasonable starting position, etc. int handObj; switch (movementType) { case HandMovement.HYDRA: handObj = 2; break; case HandMovement.FIST: handObj = 3; break; default: handObj = Random.Range(0f, 1f) < ringHandSpawnRate ? 1 : 0; break; } Hand h = Instantiate(HandObjects[handObj], handParent.transform).GetComponentInChildren <Hand>(); Arm a = h.GetComponentInParent <Arm>(); bool left; a.Shoulder = handParent.GetShoulderTransform(h.transform.position, out left, true); float size = Mathf.Clamp(possibleHandSizes[Random.Range(0, possibleHandSizes.Length)], handSizeRange.x, handSizeRange.y); h.Initialize(size, acceptableStrengthRange, perfectStrengthRange, left, handObj, movementType); ActiveHands.Add(h); }
//probably this should go to rulesAnalizer or at least be invoqued there public void calcIsMovingArms() //TODO { if (areHandsMoving) { if (isMoving == false) { isMoving = true; TimeSpan now = new TimeSpan(DateTime.Now.Ticks); startedMoving = now.TotalMilliseconds; needToMoveMore = false; handMovement = HandMovement.good; } } else { if (isMoving) { isMoving = false; TimeSpan now = new TimeSpan(DateTime.Now.Ticks); stopMoving = now.TotalMilliseconds; } else { TimeSpan now = new TimeSpan(DateTime.Now.Ticks); if (now.TotalMilliseconds - stopMoving > ThresholdMovingTime) { needToMoveMore = true; handMovement = HandMovement.notEnough; } } } }
private void ActivateHand(Transform handTrans) { if (handTrans != null) { HandMovement hand = handTrans.gameObject.GetComponent <HandMovement>(); hand.Swing(); } }
private void SetupVariables() { _handController = this.GetComponent <HandMovement>(); _controlsCycleRight = Constants.CONTROLS_CYCLE_RIGHT + PlayerNumber.ToString(); _controlsCycleLeft = Constants.CONTROLS_CYCLE_LEFT + PlayerNumber.ToString(); _controlsOven = Constants.CONTROLS_OVEN_X + PlayerNumber.ToString(); _animator = this.GetComponentInChildren <Animator>(); }
/// <summary> /// initilizes hand by cpoying data from a given hand /// </summary> /// <param name="parentHand">hand to copy from</param> /// <param name="oppositeDir">go in the same direction or the opposite one?</param> public void Initialize(Hand parentHand, bool oppositeDir) { //get size information from parent hand this.left = parentHand.left; this.size = parentHand.size; this.handObj = parentHand.handObj; // set hand to appropriate position this.transform.position = parentHand.transform.position; //Rendering Setup transform.localScale = new Vector2(size * (left ? -1 : 1), size); GetComponentInParent <Arm>().AdjustWidthForHand(size); targetSize = size; // Strength parameter setup this.acceptableRange = parentHand.acceptableRange; this.perfectRange = parentHand.perfectRange; targetStrength = HandManager.Instance.HandSizetoTargetStrength(size); // initialize time variables timePassed = moveInterval - parentHand.timePassed; //get movement information from parent hand this.movementType = parentHand.movementType; this.moveInterval = parentHand.moveInterval; this.TransitionInterval = parentHand.TransitionInterval; this.armRadius = parentHand.armRadius; if (oppositeDir) { //move opposite direction this.angleStart = parentHand.currentAngle; this.angleEnd = parentHand.currentAngle + 120; MoveHand(this.angleStart); parentHand.angleStart = parentHand.currentAngle; parentHand.angleEnd = parentHand.currentAngle - 120; timePassed = 0; parentHand.timePassed = 0; } else { //move in the same direction this.angleStart = parentHand.angleStart; this.angleEnd = parentHand.angleEnd; this.currentAngle = parentHand.currentAngle; ////initialize time variables timePassed = moveInterval - parentHand.timePassed; } }
private void RespawnPlayer() { PlayerMovement playerMov = GetComponentInParent <PlayerMovement>(); PlayerContainers playerCont = playerMov.GetComponent <PlayerContainers>(); HandMovement playerHand = playerMov.GetComponentInChildren <HandMovement>(); playerMov.ChangeControl(true); playerCont.ChangeControl(true); playerHand.ChangeControl(true); }
void Start() { _movement = GetComponent <HandMovement>(); // Set the reference. _player = FindObjectOfType <PlayerMovement>(); // Get the current device. Sets the positions for the hand to move to and from. currentDevice = (int)GameManager.Instance.currentAspect; if (currentDevice > 2) { currentDevice = 2; } }
public static void HandMovementUpdater(HandMovement handMovement, int handSpeed) { try { piHandMovementPortSwSender.AutoFlush = true; piHandMovementPortSwSender.Write(Convert.ToString(Convert.ToInt32(handMovement)) + "," + Convert.ToString(handSpeed)); } catch (Exception ex) { HandMovementPortEnabler(); } }
private void OnNotePress(int note, int channel) { //HandMovement hand = note >= NoteLeftRightThreshold ? handRight : handLeft; HandMovement hand = channel == 1 ? handLeft : handRight; // Determine with algorithm to use, based on interval and chord state int interval = Mathf.Abs(note - hand.LastPlayedNote); if (interval < 12 && hand.GetOccupiedFingerCount() <= 1) { OnNotePressWithHand(note, hand); } else { OnNotePressWithHandSingle(note, hand); } }
public void attachBall(Collider2D col) { //ballGameObject.transform.parent = col.transform; basketballSprite.sortingOrder = 4; ballGameObject.transform.position = col.transform.position; ballGameObject.transform.rotation = Quaternion.Euler(0, 0, 0); ballGameObject.GetComponent <Rigidbody2D>().bodyType = (RigidbodyType2D)2; ballGameObject.GetComponent <Rigidbody2D>().gravityScale = 0; attachName = col.transform.parent.name; //contains hand name i.e PAHand or PBHand attachParentName = col.transform.parent.transform.parent.name; //Contains super-1 parent name i.e Pbody1,2,3 attachTagName = col.transform.parent.transform.parent.tag; //Contains super parent tag i.e TeamA( of PBody tag name) or TeamB ballGameObject.GetComponent <CircleCollider2D>().isTrigger = true; attached = true; attachedIllusion = true; upperBound = false; handMovement = GameObject.Find(attachName).GetComponent <HandMovement>(); StartCoroutine("BallHoldFoul"); }
public void Death() { if (dead == false) { audioS.PlayOneShot(deathSound); dead = true; anim.SetBool("Dead", true); PlayerMovement playerMov = GetComponentInParent <PlayerMovement>(); PlayerContainers playerCont = playerMov.GetComponent <PlayerContainers>(); HandMovement playerHand = playerMov.GetComponentInChildren <HandMovement>(); playerMov.ChangeControl(false); playerCont.ChangeControl(false); playerHand.ChangeControl(false); StartCoroutine(RespawnPlayerCR(deathSound.length)); } }
private void OnNoteRelease(int note, int channel) { //HandMovement hand = note >= NoteLeftRightThreshold ? handRight : handLeft; HandMovement hand = channel == 1 ? handLeft : handRight; if (useRightHandOnly) { hand = handRight; } //int finger = (note - hand.CurrentBaseNote) + 2; int finger = hand.CurrentFingerNotes.IndexOf(note); if (finger == -1) { return; } hand.CurrentFingerNotes[finger] = -1; hand.FingerUp(finger); }
public void SetPlayerControl(bool hasControl) { playerHasControl = hasControl; Cursor.visible = !hasControl; // TODO: Disable all player contrables at once. PlayerMovement playerMov = FindObjectOfType <PlayerMovement>(); PlayerContainers playerCont = playerMov.GetComponent <PlayerContainers>(); HandMovement playerHand = playerMov.GetComponentInChildren <HandMovement>(); ProjectilePath playerProjectile = playerMov.GetComponentInChildren <ProjectilePath>(); playerMov.ChangeControl(hasControl); playerCont.ChangeControl(hasControl); playerHand.ChangeControl(hasControl); playerProjectile.ChangeControl(hasControl); //TODO: Check this one out. // It highlights the first button in the menu if there is no mouse. //StartCoroutine(HighLightBtnCR()); }
public static void RoveArmStatusUpdater(MotorName motorName, HandMovement handMovement) { try { RoverConsole.ArcEyeAiContent("Uploading Rover Arm Command : Motor Name-" + motorName.ToString() + ", Hand Movement-" + handMovement.ToString()); pi1Port2SwSender.AutoFlush = true; pi1Port2SwSender.Write(Convert.ToString(Convert.ToInt32(motorName)) + "," + Convert.ToInt32(handMovement)); RoverConsole.ArcEyeAiContent("Command Uploaded to Pi1 via port2"); if (ConnectorOne.pi1Port2ConnectedStatusEvent != null) { ConnectorOne.pi1Port2ConnectedStatusEvent(new object(), new EventArgs()); } } catch (Exception ex) { RoverConsole.ArcEyeAiContentThreadSafe(ex.ToString()); RoverConsole.ArcEyeAiContentThreadSafe("Trying To Reconnect"); if (ConnectorOne.pi1Port2DisconnectedStatusEvent != null) { ConnectorOne.pi1Port2DisconnectedStatusEvent(new object(), new EventArgs()); } } }
private void OnNotePressWithHandSingle(int note, HandMovement hand) { if (useRightHandOnly) { hand = handRight; } HandMovement otherHand = hand == handLeft ? handRight : handLeft; int mult = hand == handRight ? 1 : -1; int handBase = hand == handRight ? 0 : 4; // Which finger to start on // Get White key positions int whiteNote = player.GetKeyPosByNoteIndex(note); int whiteBaseNote = player.GetKeyPosByNoteIndex(hand.CurrentBaseNote); // Is note in current reach of the hand? if (whiteNote >= whiteBaseNote && whiteNote <= whiteBaseNote + 7) { // If yes, determine the finger int finger; int lowerNote = hand.LastPlayedNote; int upperNote = note; if (note < hand.LastPlayedNote) { lowerNote = note; upperNote = hand.LastPlayedNote; } if (lowerNote != upperNote && upperNote - lowerNote <= 12) { finger = fingering.GetOptimalFinger(hand.CurrentFinger + 1, lowerNote, upperNote, note < hand.LastPlayedNote) - 1; } else { // Repeated note -> stay on same finger finger = hand.CurrentFinger; } //finger = whiteNote - whiteBaseNote; // Check if a cross-over should be performed player.GetUpcomingNoteBuffer(upcomingNoteBuffer); if (finger == 3 && upcomingNoteBuffer[0] > note && upcomingNoteBuffer[1] > upcomingNoteBuffer[0]) { finger = 0; hand.CurrentBaseNote = note; } // Check if it requires a greater hand span if (finger > 4) { // Use full octave span, but use different finger depending on actual note if (finger == 5) { finger = 3; } else if (finger == 6) { finger = 4; } else if (finger == 7) { finger = 4; } // Set hand to span an entire octave and move it accordingly hand.SetOctaveSpan(1.0f); int octaveMovement = hand == handLeft ? 3 : 4; float zPos = player.GetNoteWorldPosition(hand.CurrentBaseNote, octaveMovement).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); //hand.CurrentBaseNote = note; // Leave at old base note ?? } else { // Reset hand span float zPos = player.GetNoteWorldPosition(hand.CurrentBaseNote, 2).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); hand.SetOctaveSpan(0.0f); } int actualFinger = Mathf.Abs(handBase - finger); hand.FingerDown(actualFinger); hand.LastPlayedNote = note; hand.CurrentFingerNotes[actualFinger] = note; } else { // If not, move hand to the according position // Check first, if hand can be moved -> otherwise try to use the other hand /*if (!useRightHandOnly && handSwitches < 2 && hand.IsOccupied() && !otherHand.IsOccupied()) * { * handSwitches++; * OnNotePressWithHandSingle(note, otherHand); * return; * } * else * { * handSwitches = 0; * }*/ float zPos = player.GetNoteWorldPosition(note, 2).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); hand.CurrentBaseNote = note; // Start with thumb or pinky - depending on the upcoming note(s) int nextNote = player.GetUpcomingNote(); int finger = handBase; if (nextNote < note) { // Start with pinky finger = 4 - handBase; zPos = player.GetNoteWorldPosition(note, -2).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); hand.CurrentBaseNote = note - 7; } hand.FingerDown(finger); hand.LastPlayedNote = note; hand.CurrentFingerNotes[finger] = note; // Reset hand span hand.SetOctaveSpan(0.0f); } // Handle Black Keys if (player.IsBlackKey(note)) { var pos = hand.TargetPosition; pos.x = initHandX + BlackKeyOffsetX; hand.TargetPosition = pos; } else { var pos = hand.TargetPosition; pos.x = initHandX; hand.TargetPosition = pos; } }
// Update is called once per frame private void Update() { if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl)) { if (!(Camera.main is null)) { _ray = Camera.main.ScreenPointToRay(Input.mousePosition); } if (Physics.Raycast(_ray, out _hit, 100.0f) && !_hit.transform.gameObject.name.Equals("Plane")) { if (_hit.transform) { //If an object was already selected change it to it's original color if (_go != null) { //Look after the child if the object is a hand if (HandChecker.IsAnyHand(_go)) { _mRendererChild.material.color = _originalColor; _child = null; } //Change of the material if the object is a moveTarget else if (MoveTargetChecker.IsMoveTarget(_go)) { _mRenderer.material = _defaultMaterial; } _mRenderer.material.color = _originalColor; } //Get object and Hit Point _hitPoint = _hit.point; _hitPointNormal = _hit.normal; _go = _hit.transform.gameObject; //Mark the selected object as red _mRenderer = _go.GetComponent <MeshRenderer>(); _originalColor = _mRenderer.material.color; _addObjectMenu.ObjectSelected(_go); //Look after the child if the object is a hand if (HandChecker.IsAnyHand(_go)) { _child = _go.transform.GetChild(0); _mRendererChild = _child.GetComponent <MeshRenderer>(); _mRendererChild.material.color = _selectColor; } //Change of the material if the object is a moveTarget else if (MoveTargetChecker.IsMoveTarget(_go)) { _defaultMaterial = _mRenderer.material; _mRenderer.material = _materialTransparent; } //Standard procedure for normal GameObjects else { _mRenderer.material.color = _selectColor; } _dragAndRotate = new DragAndRotate(_go, lockY); if (HandChecker.IsHand(_go)) { _handMovement = new HandMovement(_go); } } } else { //If an object was already selected change it to it's original color and set the object to null if (_go != null) { //Look after the child if the object is a hand if (HandChecker.IsAnyHand(_go)) { _mRendererChild.material.color = _originalColor; _child = null; _mRendererChild = null; } //Change of the material if the object is a moveTarget else if (MoveTargetChecker.IsMoveTarget(_go)) { _mRenderer.material = _defaultMaterial; } _mRenderer.material.color = _originalColor; _go = null; _mRenderer = null; _addObjectMenu.ObjectSelected(_go); } } } try { if (HandChecker.IsHand(_go)) { //Handle rotate OR Drag for a hand object if (Input.GetKey(KeyCode.M) || Input.GetKey(KeyCode.X)) { _moving = true; } else { _moving = false; } if (!Input.GetKey(KeyCode.X)) { _handMovement.CastRayFromObject(); } if (!Input.GetKey(KeyCode.M)) { _handMovement.HandleRotateHand(); } } else { //handle Rotate OR Drag if (!Input.GetKey(KeyCode.M)) { _dragAndRotate.HandleRotate(); } if (!Input.GetKey(KeyCode.X) && !Input.GetKey(KeyCode.Y) && !Input.GetKey(KeyCode.Z)) { _dragAndRotate.HandleDrag(); } } } catch (Exception) { //Catch if no object is selected } }
void OnTriggerEnter(Collider other) { if (other.CompareTag("Target")) // Check if player has arrived at target. { arrivedAtTarget = true; } if (other.CompareTag("Hand")) // If the hand has grabbed the player. The GAME IS OVER! { gameOver = true; GameManager.Instance.gameSettings.gameStart = false; GameManager.Instance.gameSettings.ZeroSpeed(); HandMovement hand = other.gameObject.GetComponentInParent <HandMovement>(); transform.parent.position = hand.GetGrabPosition().position; hand.SetGrabAnim(); hand.SetGameOver(true); m_Animations.Play(PlayerAnimation.PlayerStates.Caught); m_PlayerAudio.PlaySound(3); AttachToHand(hand.yogurtGrabPos); StartCoroutine(FadeOutSprite(shadowSprite)); m_CurrentState = State.EndGame; if (m_GameController != null) { m_GameController.SetGameOver(true); } else if (m_GC != null) { m_GC.SetGameOver(true); } } if (other.CompareTag("KillBox")) { gameOver = true; GameManager.Instance.gameSettings.gameStart = false; GameManager.Instance.gameSettings.ZeroSpeed(); m_PlayerAudio.PlaySound(3); StartCoroutine(FadeOutSprite(shadowSprite)); m_CurrentState = State.EndGame; if (m_GameController != null) { m_GameController.SetGameOver(true); } else if (m_GC != null) { m_GC.SetGameOver(true); } } if (other.CompareTag("Collectable")) // Pick up a collectable that gives you points { //Debug.Log("CANDY!"); effectController.Collected(); if (m_GameController != null) { m_GameController.IncrementScore(125); // Increment score [NOTE: there is a better way to do this.] } else if (m_GC != null) { m_GC.IncrementScore(125); } m_PlayerAudio.PlaySound(1); } if (other.CompareTag("Obstacle")) // Hit an obstacle { effectController.Hit(); //Debug.Log("OBSTACLE!"); m_PlayerAudio.PlaySound(2); GetHit(); } if (other.CompareTag("ObstacleLarge")) // Hit a large obstacle { effectController.Hit(); //Debug.Log("OBSTACLE!"); m_PlayerAudio.PlaySound(2); GetBigHit(); } if (other.CompareTag("SpeedModifier")) // Collectable that slows down the speed { if (!speedModifierChecker) { StartCoroutine(SpeedModifierEffect(speedModifierDuration, speedModifierAmount)); } } if (other.CompareTag("Spoon")) { Surf(true); } if (other.CompareTag("JumpHeight")) // If the player hits the "ceiling" of it's jump { isFallingDown = true; } }
/// <summary> /// Initialize the hand object. /// </summary> /// <param name="size">Size to scale the hand by.</param> /// <param name="acceptableRange">Range (+-) of strength of an input to accept as a success.</param> /// <param name="movementType">Movement type. Defaults to oscillating</param> public void Initialize(float size, float acceptableRange, float perfectRange, bool left, int handObj, HandMovement movementType = HandMovement.RANDOM) { //Rendering Setup transform.localScale = new Vector2(size * (left ? -1 : 1), size); GetComponentInParent <Arm>().AdjustWidthForHand(size); targetSize = size; //set copying reference variables this.size = size; this.left = left; this.handObj = handObj; // Strength parameter setup this.acceptableRange = acceptableRange; this.perfectRange = perfectRange; targetStrength = HandManager.Instance.HandSizetoTargetStrength(size); if (movementType == HandMovement.RANDOM) { //randomly determines movement type if (Random.Range(0, 2) == 0) { targetMovement = HandMovement.OSCILLATE; } else { targetMovement = HandMovement.JUMP; } } else { targetMovement = movementType; } this.movementType = HandMovement.GROW; // initialize time variables timePassed = 0.0f; //initialize movement variables switch (targetMovement) { case HandMovement.HYDRA: case HandMovement.OSCILLATE: moveInterval = Random.Range(1.0f, 5.0f); angleStart = Random.Range(0, 360); int deltaAngle = 120; if (Random.Range(0, 2) == 0) { angleEnd = angleStart - deltaAngle; } else { angleEnd = angleStart + deltaAngle; } currentAngle = angleStart; break; case HandMovement.JUMP: moveInterval = Random.Range(0.25f, 1.0f) + 1f; currentAngle = angleEnd = angleStart = Random.Range(0, 360); break; case HandMovement.FIST: moveInterval = Random.Range(0.25f, 1.0f) + 2f; currentAngle = angleEnd = angleStart = Random.Range(0, 360); break; } //modify speed based on difficulty moveInterval *= DifficultyManager.Instance.currentSpeedMod; //determine arm radius float vertExtent = Camera.main.orthographicSize * 2f; float horzExtent = vertExtent * (Screen.width / (float)Screen.height); armRadius = (horzExtent / 2f) - (1f - Random.Range(0, 25) / 100f); //half screen width - padding }
/// <summary> /// changes movement type and resets timer /// </summary> /// <param name="newMovement"></param> private void ChangeMovementType(HandMovement newMovement) { timePassed = 0.0f; movementType = newMovement; }
IEnumerator spawnAnimation() { if (this.gameObject.tag == "skeleton") { SkeletonMovement moveComponent = this.gameObject.GetComponent <SkeletonMovement>(); moveComponent.canMove = false; } if (this.gameObject.tag == "boomerang") { BoomerangMovement moveComponent = this.gameObject.GetComponent <BoomerangMovement>(); moveComponent.canMove = false; } if (this.gameObject.tag == "bat") { BatMovement moveComponent = this.gameObject.GetComponent <BatMovement>(); moveComponent.canMove = false; } if (this.gameObject.tag == "gel") { GelMovement moveComponent = this.gameObject.GetComponent <GelMovement>(); moveComponent.canMove = false; } if (this.gameObject.tag == "hand") { HandMovement moveComponent = this.gameObject.GetComponent <HandMovement>(); moveComponent.canMove = false; } if (this.gameObject.tag == "dragon") { DragonMovement moveComponent = this.gameObject.GetComponent <DragonMovement>(); moveComponent.canMove = false; } Animator hold = GetComponent <Animator>(); if (hold != null) { hold.enabled = false; } GetComponent <Rigidbody>().velocity = new Vector3(0.0f, 0.0f, 0.0f); GetComponent <SpriteRenderer>().sprite = GameController.instance.explosionOne; yield return(new WaitForSeconds(0.2f)); GetComponent <SpriteRenderer>().sprite = GameController.instance.explosionTwo; yield return(new WaitForSeconds(0.2f)); GetComponent <SpriteRenderer>().sprite = startingSprite; if (this.gameObject.tag == "skeleton") { SkeletonMovement moveComponent = this.gameObject.GetComponent <SkeletonMovement>(); moveComponent.canMove = true; } if (this.gameObject.tag == "boomerang") { BoomerangMovement moveComponent = this.gameObject.GetComponent <BoomerangMovement>(); moveComponent.canMove = true; } if (this.gameObject.tag == "bat") { BatMovement moveComponent = this.gameObject.GetComponent <BatMovement>(); moveComponent.canMove = true; } if (this.gameObject.tag == "gel") { GelMovement moveComponent = this.gameObject.GetComponent <GelMovement>(); moveComponent.canMove = true; } if (this.gameObject.tag == "hand") { HandMovement moveComponent = this.gameObject.GetComponent <HandMovement>(); moveComponent.canMove = true; } if (this.gameObject.tag == "dragon") { DragonMovement moveComponent = this.gameObject.GetComponent <DragonMovement>(); moveComponent.canMove = true; } if (hold != null) { hold.enabled = true; } }
private void OnNotePressWithHand(int note, HandMovement hand) { if (useRightHandOnly) { hand = handRight; } HandMovement otherHand = hand == handLeft ? handRight : handLeft; int mult = hand == handRight ? 1 : -1; int handBase = hand == handRight ? 0 : 4; // Which finger to start on // Get White key positions int whiteNote = player.GetKeyPosByNoteIndex(note); int whiteBaseNote = player.GetKeyPosByNoteIndex(hand.CurrentBaseNote); // Is note in current reach of the hand? if (whiteNote >= whiteBaseNote && whiteNote <= whiteBaseNote + 7) { // If yes, determine the finger int finger; int lowerNote = hand.LastPlayedNote; int upperNote = note; if (note < hand.LastPlayedNote) { lowerNote = note; upperNote = hand.LastPlayedNote; } int interval = upperNote - lowerNote; finger = optimalFingers[player.CurrentNoteIndex] - 1; /*if (interval > 0 && interval <= 12) * { * finger = fingering.GetOptimalFinger(hand.CurrentFinger + 1, lowerNote, upperNote, note < hand.LastPlayedNote) - 1; * } * else * { * // Repeated note -> stay on same finger * finger = hand.CurrentFinger; * } * //finger = whiteNote - whiteBaseNote;*/ // Crossover bool crossover = false; int crossoverDownFinger = -1; int nextNote = -1; if ((nextNote = player.GetUpcomingNote()) != -1) { int lowerFinger = finger; int upperFinger = optimalFingers[player.CurrentNoteIndex + 1] - 1; if (nextNote < note) { // Next up a decreasing interval lowerFinger = upperFinger; upperFinger = finger; crossoverDownFinger = lowerFinger; } if ((lowerFinger == 1 || lowerFinger == 2 || lowerFinger == 3) && upperFinger == 0) { // Crossover with index, middle or ring finger crossover = false; } } // Check if it requires a greater hand span if (finger > 4) { // Use full octave span, but use different finger depending on actual note if (finger == 5) { finger = 3; } else if (finger == 6) { finger = 4; } else if (finger == 7) { finger = 4; } // Set hand to span an entire octave and move it accordingly hand.SetOctaveSpan(1.0f); int octaveMovement = hand == handLeft ? 3 : 4; float zPos = player.GetNoteWorldPosition(hand.CurrentBaseNote, octaveMovement).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); //hand.CurrentBaseNote = note; // Leave at old base note ?? } else { if (interval > 2) { // Determine unusual finger spans float octaveSpan = 0.0f; int fingerDiff = Mathf.Abs(finger - hand.CurrentFinger); // Difference between the two current fingers if (interval <= 4) { if (fingerDiff == 1) { octaveSpan = 0.5f; } else { octaveSpan = 0.0f; //hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, 0); } } else // if (interval <= 7) { if (fingerDiff <= 2) { octaveSpan = 1.0f; } else if (fingerDiff == 3) { octaveSpan = 0.5f; } else { octaveSpan = 0.0f; //hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -4); } } hand.SetOctaveSpan(octaveSpan); int octaveMovement = hand == handLeft ? 3 : 4; float zPos = player.GetNoteWorldPosition(hand.CurrentBaseNote, octaveMovement).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); } else { if (finger == 0) { hand.CurrentBaseNote = note; } else if (finger == 1) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -1); } else if (finger == 2) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -2); } else if (finger == 3) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -3); } if (finger == 4) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -4); } // Reset hand span float zPos = player.GetNoteWorldPosition(hand.CurrentBaseNote, 2).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); hand.SetOctaveSpan(0.0f); } } int actualFinger = Mathf.Abs(handBase - finger); hand.FingerDown(actualFinger, crossover, crossoverDownFinger); hand.LastPlayedNote = note; hand.CurrentFingerNotes[actualFinger] = note; } else { // If not, move hand to the according position int finger = optimalFingers[player.CurrentNoteIndex] - 1; // Check first, if hand can be moved -> otherwise try to use the other hand /*int interval = Mathf.Abs(note - hand.LastPlayedNote); * if (!useRightHandOnly && handSwitches < 2 && hand.IsFingerOccupied(finger) && !otherHand.IsOccupied() && interval > 12) * { * handSwitches++; * OnNotePressWithHand(note, otherHand); * return; * } * else * { * handSwitches = 0; * }*/ if (finger == 0) { hand.CurrentBaseNote = note; } else if (finger == 1) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -1); } else if (finger == 2) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -2); } else if (finger == 3) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -3); } if (finger == 4) { hand.CurrentBaseNote = player.GetWhiteNoteWithOffset(note, -4); } // Reset hand span float zPos = player.GetNoteWorldPosition(hand.CurrentBaseNote, 2).z; hand.TargetPosition = new Vector3(hand.transform.position.x, hand.transform.position.y, zPos); hand.SetOctaveSpan(0.0f); hand.FingerDown(finger); hand.LastPlayedNote = note; hand.CurrentFingerNotes[finger] = note; } // Handle Black Keys if (player.IsBlackKey(note)) { var pos = hand.TargetPosition; pos.x = initHandX + BlackKeyOffsetX; hand.TargetPosition = pos; } else { var pos = hand.TargetPosition; pos.x = initHandX; hand.TargetPosition = pos; } }
public static void MasterUpdater(MovementObject movementObject, RoverAndArmRoverMovement roverMovement, RoverCameraMovement cameraMovement, HandMovement handMovement, double RoverPwm, int CameraSpeed, int handSpeed) { try { piMasterPortSwSender.AutoFlush = true; piMasterPortSwSender.Write(Convert.ToString(Convert.ToInt32(movementObject)) + "," + Convert.ToString(Convert.ToInt32(roverMovement)) + "," + Convert.ToString(Convert.ToInt32(cameraMovement)) + "," + Convert.ToString(Convert.ToInt32(handMovement)) + "," + Convert.ToString(RoverPwm) + "," + Convert.ToString(CameraSpeed) + "," + Convert.ToString(handSpeed)); } catch (Exception ex) { MasterPortEnabler(); } }