/// <summary> /// Shoot will swap between players and check if a player has been killed. /// It also allows the current player to hit on the enemygrid. /// </summary> /// <param name="row">the row fired upon</param> /// <param name="col">the column fired upon</param> /// <returns>The result of the attack</returns> public AttackResult Shoot(int row, int col) { AttackResult newAttack; int otherPlayer = (_playerIndex + 1) % 2; newAttack = Player.Shoot(row, col); // Will exit the game when all players ships are destroyed if (_players[otherPlayer].IsDestroyed) { newAttack = new AttackResult(ResultOfAttack.GameOver, newAttack.Ship, newAttack.Text, row, col); } if (AttackCompleted != null) { AttackCompleted.Invoke(this, newAttack); } // change player if the last hit was a miss if (newAttack.Value == ResultOfAttack.Miss) { _playerIndex = otherPlayer; } return(newAttack); }
IEnumerator AttackRoutine(float beforeDelay, float activeDuration, float endDelay, SFXOneShot sfx, GameObject collisionObject, string animationName) { // start animation before hit, in case there's windup _playerAnimator.PlayAnimation(animationName); MeleeAttackState = MeleeAttackState.BeforeAttack; yield return(new WaitForSeconds(beforeDelay)); MeleeAttackState = MeleeAttackState.DuringAttack; AttackActivated?.Invoke(EquippedWeapon); //TODO: check/deal damage here CurrentWeaponCollision.SetActive(true); //_weaponAnimator.Play(animationName); sfx.PlayOneShot(transform.position); yield return(new WaitForSeconds(activeDuration)); CurrentWeaponCollision.SetActive(false); AttackDeactivated?.Invoke(); MeleeAttackState = MeleeAttackState.AfterAttack; //_weaponAnimator.Stop(); //TODO: this could be a window for followup/combo attacks yield return(new WaitForSeconds(endDelay)); MeleeAttackState = MeleeAttackState.NotAttacking; AttackCompleted?.Invoke(); }