private void HitOpponent(Collider2D otherPlayer, string rival) { if (otherPlayer.tag == rival) { rivalCharacter = otherPlayer.gameObject.GetComponent <CharacterFeatures>(); float attackValue = currentCharacter.DoDamage() * CurrentFightStats.GetDamage(); ///Moves hit character rivalCharacter.HitDone(); switch (currentCharacter.GetIsFlipped()) { case true: otherPlayer.gameObject.GetComponent <Rigidbody2D>().velocity = Vector2.left * 40f; break; case false: otherPlayer.gameObject.GetComponent <Rigidbody2D>().velocity = Vector2.right * 40f; break; } if (rivalCharacter.GetIsBlocking()) { rivalSoundEffect.PlayCharacterSoundEffect("Block"); rivalCharacter.TakeDamage(attackValue / 4); PlayBlockAnimation(); blockSprite.GetComponent <BlockBehaviour>().ActivateBlockSprite(otherPlayer.gameObject.GetComponent <BoxCollider2D>(), rivalCharacter.GetIsFlipped()); } else { rivalSoundEffect.PlayCharacterSoundEffect("Hit"); rivalCharacter.TakeDamage(attackValue); PlayHitAnimation(); hitSparks.GetComponent <SparksBehaviour>().ActivateHitSparks(gameObject.GetComponent <BoxCollider2D>().bounds.center); } } }
private float characterJumpFinalPosition; ///Needed to assess the final position of a jump void Start() { currentCharacter = this.GetComponent <CharacterFeatures>(); characterActions = this.GetComponent <CharacterActions>(); animator = currentCharacter.GetAnimator(); rigidBody = this.GetComponent <Rigidbody2D>(); }
public CharacterFeatures GetEnemy(CharacterFeatures fighter) { CharacterFeatures enemy; if (fighter is Pretre) { enemy = Fighters.FirstOrDefault(x => x.IsUndead); if (enemy != null) { return(enemy); } } do { var otherFighters = Fighters .Where(x => x.Id != fighter.Id && !x.IsDead() && x.CurrentLife > 0 && !x.IsHide).ToList(); //AfficherListeEnnemi(otherFighters); if (otherFighters.Count == 0) { otherFighters = Fighters .Where(x => x.Id != fighter.Id && !x.IsDead() && x.CurrentLife > 0 && x.IsHide).ToList(); } var randomEnemy = Random.Next(otherFighters.Count(f => f.Id != fighter.Id && !f.IsDead())); enemy = otherFighters[randomEnemy]; } while (enemy.Id == fighter.Id); return(enemy); }
// Use this for initialization void Start() { currentCharacter = this.GetComponent <CharacterFeatures>(); rivalCharacter = rivalCharacters.transform.GetChild(0).gameObject; characterSoundEffect = characterSoundEffectPlayer.GetComponent <CharacterSoundEffect>(); boxCollider = this.GetComponent <BoxCollider2D>(); characterSides = boxCollider.bounds.extents; rigidBody = this.GetComponent <Rigidbody2D>(); }
public static void CheckCharacterStates(CharacterFeatures currentCharacter) { if (currentCharacter.GetIsJumping()) { conditions |= AIConditions.characterStateAir; } else { conditions &= ~AIConditions.characterStateAir; } }
protected void Death(CharacterFeatures deadGuy) { deadGuy.AttackTimer.Stop(); deadGuy.PowerTimer.Stop(); if (DeadFighters.All(dead => deadGuy != null && dead.Id != deadGuy.Id)) { DeadFighters.Add(deadGuy); Fighters.Remove(deadGuy); } }
IEnumerator SwapCharacterWhenDead(GameObject playerCharacter) { CharacterFeatures character = playerCharacter.transform.GetChild(0).GetComponent <CharacterFeatures>(); if (character.GetIsDead() && !character.GetAnimator().enabled&& !swappingCharacter) { swappingCharacter = true; yield return(new WaitForSeconds(0.5f)); playerCharacter.GetComponent <CharacterAssist>().Swap("Assist1", true); swappingCharacter = false; } }
public CharacterFeatures GetDeadEnemy(CharacterFeatures fighter) { CharacterFeatures enemy; do { var otherFighters = Fighters.Where(x => x.Id != fighter.Id && x.IsDead() && !x.IsDevoured).ToList(); var randomEnemy = Random.Next(otherFighters.Count(f => f.Id != fighter.Id)); enemy = otherFighters[randomEnemy]; } while (enemy.Id == fighter.Id); return(enemy); }
public void Swap(string assist, bool characterDied) { if (SwapAvailable() || characterDied) { StartCoroutine(SwappingTimeout()); GameObject characterSwap; GameObject pointCharacter = transform.GetChild(0).gameObject; bool assistFound = false; switch (assist) { case "Assist1": for (int i = 1; i < transform.childCount && !assistFound; i++) { if (!transform.GetChild(i).gameObject.GetComponent <CharacterFeatures>().GetIsDead()) { assistFound = true; characterSwap = transform.GetChild(i).gameObject; pointCharacter.transform.SetSiblingIndex(transform.GetChild(i).transform.GetSiblingIndex()); characterSwap.transform.SetSiblingIndex(0); SwapLifeBars(characterSwap, pointCharacter, i); SetCharacterSwapped(characterSwap, pointCharacter); UnsetCharacterSwapped(pointCharacter); currentCharacter = characterSwap.GetComponent <CharacterFeatures>(); } } break; case "Assist2": for (int i = transform.childCount - 1; i > 0 & !assistFound; i--) { if (!transform.GetChild(i).gameObject.GetComponent <CharacterFeatures>().GetIsDead()) { assistFound = true; characterSwap = transform.GetChild(i).gameObject; pointCharacter.transform.SetSiblingIndex(transform.GetChild(i).transform.GetSiblingIndex()); characterSwap.transform.SetSiblingIndex(0); SwapLifeBars(characterSwap, pointCharacter, i); SetCharacterSwapped(characterSwap, pointCharacter); UnsetCharacterSwapped(pointCharacter); currentCharacter = characterSwap.GetComponent <CharacterFeatures>(); } } break; } currentCharacter.SetIsBlocked(false); } }
// Use this for initialization void Start() { currentCharacter = this.GetComponent <CharacterFeatures>(); rivalCharacter = rivalCharacters.transform.GetChild(0).GetComponent <CharacterFeatures>(); characterActions = this.GetComponent <CharacterActions>(); characterAssist = characters.GetComponent <CharacterAssist>(); animator = currentCharacter.GetAnimator(); rigidBody = this.GetComponent <Rigidbody2D>(); boxCollider = this.GetComponent <BoxCollider2D>(); /*AddRulesRivalAttacks(); * AddRulesRivalIsHit(); * AddRulesRivalIsBlock(); * AddRulesRivalBackwards(); * AddRulesRivalJumpingBackwards(); * AddRulesRivalForwards(); * AddRulesRivalJumpingForwards(); * AddRulesRivalIdle(); * AddRulesSwapCharacter();*/ }
public static void CheckCharacterSwap(CharacterAssist assist, CharacterFeatures currentCharacter, GameObject characters) { if (!assist.GetSwapped()) { float lifePercentage = (float)currentCharacter.GetHealthBar().getHP() / currentCharacter.GetHealthBar().getMaxHP(); float pointCharacterHealth = currentCharacter.GetHealthBar().getHP(); float secondCharacterHealth = characters.transform.GetChild(1).GetComponent <CharacterFeatures>().GetHealthBar().getHP(); float thirdCharacterHealth = characters.transform.GetChild(2).GetComponent <CharacterFeatures>().GetHealthBar().getHP(); if (lifePercentage < 0.4) { if (pointCharacterHealth > secondCharacterHealth) { if (pointCharacterHealth > thirdCharacterHealth) { ////Leave point character conditions &= ~AIConditions.changeSecondCharacter; conditions &= ~AIConditions.changeThirdCharacter; conditions |= AIConditions.leavePointCharacter; } else { ///Change to third character conditions &= ~AIConditions.leavePointCharacter; conditions &= ~AIConditions.changeSecondCharacter; conditions |= AIConditions.changeThirdCharacter; } } else { if (secondCharacterHealth >= thirdCharacterHealth) { ///Change to second character conditions &= ~AIConditions.leavePointCharacter; conditions &= ~AIConditions.changeThirdCharacter; conditions |= AIConditions.changeSecondCharacter; } else { /// Change to third character conditions &= ~AIConditions.leavePointCharacter; conditions &= ~AIConditions.changeSecondCharacter; conditions |= AIConditions.changeThirdCharacter; } } } else { /// leave point character conditions &= ~AIConditions.changeSecondCharacter; conditions &= ~AIConditions.changeThirdCharacter; conditions |= AIConditions.leavePointCharacter; } } else { //// Reset all conditions conditions &= ~AIConditions.leavePointCharacter; conditions &= ~AIConditions.changeSecondCharacter; conditions &= ~AIConditions.changeThirdCharacter; } }
// Update is called once per frame void Update() { if ((currentCharacter.IsAnimationPlaying() && !currentCharacter.GetIsJumping() && !currentCharacter.GetIsHit()) || currentCharacter.GetAnimationStatus() == AnimationStates.STANDING) { //In case the animation goes from walking to other animation, prevents from sliding behaviour rigidBody.velocity = new Vector2(0, 0); } rivalCharacter = rivalCharacters.transform.GetChild(0).GetComponent <CharacterFeatures>(); //Has to be done constantly in case it changes if (!currentCharacter.GetIsBlocked() && !currentCharacter.GetIsDead()) { AIConditionChecking.CheckTimer(currentTimer.GetTimer()); AIConditionChecking.CheckCharacterStates(currentCharacter); AIConditionChecking.CheckDistance(characterActions); AIConditionChecking.CheckCharacterHealth(currentTimer.GetTimer(), characters, rivalCharacters); AIConditionChecking.CheckCharacterSwap(characterAssist, currentCharacter, characters); if (currentCharacter.GetAnimationStatus() != AnimationStates.WALK_BACKWARDS || characterAction != AnimationStates.BLOCKING_JUMPING || characterAction != AnimationStates.BLOCKING_CROUCHING) { characterActions.StopBlocking(); } PerformWalkState(); BugFixStandingIsJumping(); if (Array.IndexOf(AnimationStates.GetIdleMovements(), currentCharacter.GetAnimationStatus()) >= 0) { Invoke("PerformNewAction", 2); ExecuteRules(rulesEngineSwapCharacter); if (Array.IndexOf(AnimationStates.GetAttacks(), rivalCharacter.GetAnimationStatus()) >= 0) { ExecuteRules(rulesEngineRivalAttacks); } if (Array.IndexOf(AnimationStates.GetTakingDamageStates(), rivalCharacter.GetAnimationStatus()) >= 0) { ExecuteRules(rulesEngineRivalIsHit); } if (Array.IndexOf(AnimationStates.GetBlockingStates(), rivalCharacter.GetAnimationStatus()) >= 0) { ExecuteRules(rulesEngineRivalBlocks); } if (rivalCharacter.GetAnimationStatus() == AnimationStates.WALK_BACKWARDS) { ExecuteRules(rulesEngineRivalBackwards); } if (rivalCharacter.GetAnimationStatus() == AnimationStates.WALK_FORWARDS) { ExecuteRules(rulesEngineRivalForwards); } if (rivalCharacter.GetAnimationStatus() == AnimationStates.JUMPING_BACKWARDS) { ExecuteRules(rulesEngineRivalJumpingBackwards); } if (rivalCharacter.GetAnimationStatus() == AnimationStates.JUMPING_FORWARDS) { ExecuteRules(rulesEngineRivalJumpingForwards); } if (rivalCharacter.GetAnimationStatus() == AnimationStates.STANDING || rivalCharacter.GetAnimationStatus() == AnimationStates.CROUCHING || rivalCharacter.GetAnimationStatus() == AnimationStates.JUMPING_DOWN || rivalCharacter.GetAnimationStatus() == AnimationStates.JUMPING_UP || rivalCharacter.GetAnimationStatus() == AnimationStates.CROUCH) { ExecuteRules(rulesEngineRivalIdle); } } } }
// Use this for initialization void Start() { currentCharacter = this.GetComponent <CharacterFeatures>(); characterActions = this.GetComponent <CharacterActions>(); characterSoundEffect = CharacterSoundEffectPlayer.GetComponent <CharacterSoundEffect>(); }
void Awake() { currentCharacter = gameObject.GetComponentInParent <CharacterFeatures>(); }
void Start() { swapped = false; currentCharacter = transform.GetChild(0).gameObject.GetComponent <CharacterFeatures>(); }