/// <summary> /// Updates the value of the side health bar /// </summary> private IEnumerator UpdateSideHealth() { // Add the ongoing action MoveAttack.AddOngoingAction(); // Get the target amount to work towards float targetAm = ((float)CurHP) / MaxHP; // If we are lower than the current amount while (_sideSlider.value < targetAm) { _sideSlider.value += Time.deltaTime * _healthBarSpeed; yield return(null); } // If we are higher than the current amount while (_sideSlider.value > targetAm) { _sideSlider.value -= Time.deltaTime * _healthBarSpeed; yield return(null); } // Just set it to what it is supposed to be _sideSlider.value = targetAm; // Remove the ongoing action MoveAttack.RemoveOngoingAction(); yield return(null); }
/// <summary> /// Slowly increases the health bars visuals. Also tests if the enemy is going to die, if they are it calls Die. /// Also returns control to the correct autority if no one died /// </summary> /// <returns>IEnumerator</returns> private IEnumerator UpdateHealth() { // Signal MoveAttack that a character's health bar is currently being updated. // We will remove it here after this ends or in Ascend if the damage is fatal MoveAttack.AddOngoingAction(); // Get the target amount to work towards float targetAm = ((float)CurHP) / MaxHP; // If we are lower than the current amount while (_healthBarSlider.value < targetAm) { _healthBarSlider.value += Time.deltaTime * _healthBarSpeed; yield return(null); } // If we are higher than the current amount while (_healthBarSlider.value > targetAm) { _healthBarSlider.value -= Time.deltaTime * _healthBarSpeed; yield return(null); } // After we finish, just set it _healthBarSlider.value = targetAm; // If the character died. We call it here so that health goes down first if (_curHP == 0) { //sound effect _audManRef.PlaySound("Death"); Die(); } // Signal MoveAttack that a character's health bar is finished being updated else { MoveAttack.RemoveOngoingAction(); } yield return(null); }
/// <summary> /// Increments the position of the charToPush by a little bit /// </summary> /// <param name="charToPush">The transform we will be changing</param> /// <param name="pushToNode">The node we will be pushing the character to</param> /// <returns>IEnumerator</returns> private IEnumerator PushCharacter(Transform charToPush, Node pushToNode) { // Add an ongoing action MoveAttack.AddOngoingAction(); // Get the starting node so that we can change what's "there" after the push Node startNode = _mAContRef.GetNodeByWorldPosition(charToPush.transform.position); Vector2Int roundedPos = new Vector2Int(Mathf.RoundToInt(charToPush.transform.position.x), Mathf.RoundToInt(charToPush.transform.position.y)); Vector2Int pushDirVect = new Vector2Int(0, 0); // Determine direction to push the character, technically, it should only be one of them // X factor if (roundedPos.x < pushToNode.Position.x) { pushDirVect.x = 1; } else if (roundedPos.x > pushToNode.Position.x) { pushDirVect.x = -1; } else { pushDirVect.x = 0; } // Y factor if (roundedPos.y < pushToNode.Position.y) { pushDirVect.y = 1; } else if (roundedPos.y > pushToNode.Position.y) { pushDirVect.y = -1; } else { pushDirVect.y = 0; } // Get the amount we will increment by each push Vector3 incrementVect = new Vector3(pushDirVect.x, pushDirVect.y, 0) * Time.deltaTime * _pushSpeed; float distance = Mathf.Abs(charToPush.transform.position.x - pushToNode.Position.x + charToPush.transform.position.y - pushToNode.Position.y); float lastDist = distance; // Start pushing the character that way // When the distance between the tiles starts to grow, stop incrementing the character while (lastDist >= distance) { // Move the character a little charToPush.transform.position += incrementVect; // Set the last distance lastDist = distance; // Recalculate the distance distance = Mathf.Abs(charToPush.transform.position.x - pushToNode.Position.x + charToPush.transform.position.y - pushToNode.Position.y); yield return(null); } // Fix the character in place charToPush.transform.position = new Vector3(pushToNode.Position.x, pushToNode.Position.y, 0); // Update the node it came from and where it ended pushToNode.Occupying = startNode.Occupying; startNode.Occupying = CharacterType.None; // Remove the ongoing action MoveAttack.RemoveOngoingAction(); yield return(null); }