public void Grow() { if (_health != HealthStates.Dry) { switch (_age) { case PlantStates.Seeds: _age = PlantStates.Young; seedsPrefab.SetActive(false); youngPrefab.SetActive(true); break; case PlantStates.Young: _age = PlantStates.Adult; youngPrefab.SetActive(false); adultPrefab.SetActive(true); break; default: break; } } _health = HealthStates.Dry; wateredPlot.SetActive(false); overWateredPlot.SetActive(false); drownedPlot.SetActive(false); }
/// <summary> /// Changes the players health by the value passed in. If positive value, player takes damage. /// If negative value, player heals. Damage will only be taken if the player has no invincibility /// frames left. /// </summary> /// <param name="damage"></param> private void TakeDamage(int damage) { if (!damageTaken && damage > 0) { soundEffectSource.clip = damageClip; soundEffectSource.Play(); currentHealth -= damage; if (currentHealth > maxHealth) { currentHealth = maxHealth; } else if (currentHealth <= 0) { currentHealthState = deadHealthState; } healthBar.value = currentHealth; damageTaken = true; ChangeState(damage); } else if (damage < 0) { currentHealthState.PlayerHealed(); } }
override public void ImpactHandler(Vector3 pos, Vector3 hitDirection, Vector3 hitNormal, bool isFatal = false) { HealthStates hState = HealthProcessing(); switch (hState) { // When head was damaged we will hide external skin and show head internals case HealthStates.damaged: damagedSkin.gameObject.SetActive(true); healthySkin.gameObject.SetActive(false); headPartialSkin.gameObject.SetActive(true); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; // head kaaBoooM! case HealthStates.fatal: damagedSkin.gameObject.SetActive(false); healthySkin.gameObject.SetActive(false); headPartialSkin.gameObject.SetActive(true); // head explosion StartCoroutine(headExplosion(hitDirection)); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; default: base.ImpactHandler(pos, hitDirection, hitNormal); return; } }
public void Water() { switch (_health) { case HealthStates.Dry: _health = HealthStates.Watered; wateredPlot.SetActive(true); break; case HealthStates.Watered: _health = HealthStates.OverWatered; wateredPlot.SetActive(false); overWateredPlot.SetActive(true); break; case HealthStates.OverWatered: _health = HealthStates.Drowned; overWateredPlot.SetActive(false); drownedPlot.SetActive(true); break; default: break; } }
/// <summary> /// Updates the entity's health state based on its current HP /// </summary> protected void UpdateHealthState() { HealthStates newHealthState = HealthState; if (CurHP > BattleGlobals.MaxDangerHP) { newHealthState = HealthStates.Normal; } else if (CurHP >= BattleGlobals.MinDangerHP) { newHealthState = HealthStates.Danger; } else if (CurHP == BattleGlobals.PerilHP) { newHealthState = HealthStates.Peril; } else { newHealthState = HealthStates.Dead; } //Change health states if they're no longer the same if (newHealthState != HealthState) { OnHealthStateChange(newHealthState); HealthStateChangedEvent?.Invoke(newHealthState); //Change to the new health state HealthState = newHealthState; } }
/// <summary> /// Changes the player's state based on how much health they have. /// </summary> /// <param name="dam"></param> private void ChangeState(int dam) { if (currentHealth > maxHealth / 2) { currentHealthState = fullHealthState; } else if (currentHealth <= maxHealth / 2 && currentHealth > maxHealth / 4) { currentHealthState = halfHealthState; } else if (currentHealth > 0 && currentHealth <= maxHealth / 4) { currentHealthState = quarterHealthState; } if (dam > 0) { currentHealthState.TakeDamage(); } else if (dam < 0) { currentHealthState.PlayerHealed(); } }
public void HealthTestMethod() { var HealthStates = new HealthStates(); HealthState healthState = HealthState.good; var expectedResult = "good"; HealthState result = HealthStates.GetHealthState(expectedResult); Assert.AreEqual(healthState, result); }
public void HealthTestMethod2() { var HealthStates2 = new HealthStates(); HealthState healthState2 = HealthState.good; var expectedResult2 = "good"; HealthState result2 = HealthStates.GetHealthState(expectedResult2); Assert.AreEqual(healthState2, result2); }
public void HealthTestMethod3() { var HealthStates3 = new HealthStates(); HealthState healthState3 = HealthState.good; var expectedResult3 = "good"; HealthState result3 = HealthStates.GetHealthState(expectedResult3); Assert.AreEqual(healthState3, result3); }
//public bool startedLevel; void Start() { fm = FindObjectOfType <FindMatch>(); display = FindObjectOfType <DisplayEndUI>(); //nm = FindObjectOfType<NotificationManager>(); criteria = GameObject.Find("Criteria").GetComponent <Criteria>(); currentHealth = min_neutralHealth; healthState = HealthStates.Sick; healthBar.SetHealth(min_neutralHealth); anim = GetComponent <Animator>(); audiosrc = GetComponent <AudioSource>(); }
override public void ImpactHandler(Vector3 pos, Vector3 hitDirection, Vector3 hitNormal, bool isFatal = false) { HealthStates hState = HealthProcessing(); switch (hState) { case HealthStates.damaged: damagedArm.gameObject.SetActive(true); skinsToHide[0].gameObject.SetActive(false); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; case HealthStates.fatal: // enable physical object elbowPhys.gameObject.SetActive(true); elbowPhys.transform.position = elbowLimb.position; // - 0.04f * palmLimb.right + 0.035f * palmLimb.forward + 0.04f * palmLimb.up; elbowPhys.transform.rotation = elbowLimb.rotation; // if palm is active if (palmPhys.gameObject.activeSelf) { //elbowPhys.GetComponent<Rigidbody>().AddForce(10f * hitDirection, ForceMode.Impulse); elbowPhys.GetComponent <Rigidbody>().AddTorque(10f * Random.onUnitSphere, ForceMode.Impulse); } else { palmHandler.DestroyPalm(pos, hitDirection, hitNormal); palmPhys.transform.position = elbowPhys.transform.position - 0.25f * palmShiftDirection * elbowPhys.transform.right; palmPhys.transform.rotation = Quaternion.LookRotation(-elbowPhys.transform.forward, -elbowPhys.transform.up); elbowPhys.gameObject.AddComponent <FixedJoint>().connectedBody = palmPhys.GetComponent <Rigidbody>(); //elbowPhys.GetComponent<Rigidbody>().AddForce(15f * hitDirection, ForceMode.Impulse); elbowPhys.GetComponent <Rigidbody>().AddTorque(10f * Random.onUnitSphere, ForceMode.Impulse); //Debug.Break(); } // hide skinned meshes for (int i = 0; i < skinsToHide.Length; i++) { skinsToHide[i].gameObject.SetActive(false); } damagedArm.gameObject.SetActive(false); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; default: base.ImpactHandler(pos, hitDirection, hitNormal); return; } }
void Start() { _age = PlantStates.Empty; _health = HealthStates.Dry; seedsPrefab.SetActive(true); youngPrefab.SetActive(true); adultPrefab.SetActive(true); wateredPlot.SetActive(true); overWateredPlot.SetActive(true); drownedPlot.SetActive(true); seedsPrefab.SetActive(false); youngPrefab.SetActive(false); adultPrefab.SetActive(false); wateredPlot.SetActive(false); overWateredPlot.SetActive(false); drownedPlot.SetActive(false); }
void Update() { if (_health == 3) { HealthState = HealthStates.full; } else if (_health == 2) { HealthState = HealthStates.first; } else if (_health == 1) { HealthState = HealthStates.second; } else if (_health <= 0) { HealthState = HealthStates.third; } Health(); }
override public void ImpactHandler(Vector3 pos, Vector3 hitDirection, Vector3 hitNormal, bool isFatal = false) { HealthStates hState = HealthProcessing(); switch (hState) { case HealthStates.damaged: damagedForearm.gameObject.SetActive(true); skinsToHide[0].gameObject.SetActive(false); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; case HealthStates.fatal: // hide skinned meshes for (int i = 0; i < skinsToHide.Length; i++) { skinsToHide[i].gameObject.SetActive(false); } damagedForearm.gameObject.SetActive(false); // enable physical object palmPhys.transform.position = palmLimb.position; // - 0.04f * palmLimb.right + 0.035f * palmLimb.forward + 0.04f * palmLimb.up; palmPhys.transform.rotation = palmLimb.rotation; //Debug.Break(); palmPhys.gameObject.SetActive(true); //palmPhys.GetComponent<Rigidbody>().AddForce(10f * hitDirection, ForceMode.Impulse); palmPhys.GetComponent <Rigidbody>().AddTorque(10f * Random.onUnitSphere, ForceMode.Impulse); // destroy this collider Destroy(transform.GetComponent <Joint>()); Destroy(transform.GetComponent <Collider>()); Destroy(transform.GetComponent <Rigidbody>()); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; default: base.ImpactHandler(pos, hitDirection, hitNormal); return; } }
override public void ImpactHandler(Vector3 pos, Vector3 hitDirection, Vector3 hitNormal, bool isFatal = false) { HealthStates hState = HealthProcessing(); switch (hState) { case HealthStates.damaged: damagedSkin.gameObject.SetActive(true); healthySkin.gameObject.SetActive(false); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; case HealthStates.fatal: damagedSkin.gameObject.SetActive(false); healthySkin.gameObject.SetActive(false); base.ImpactHandler(pos, hitDirection, hitNormal, true); break; default: base.ImpactHandler(pos, hitDirection, hitNormal); return; } }
private void SetBonus(HealthStates states) //function that changes the bonus health for the matches based on the specific state, as well as changing the health decrease rate { switch (states) { case HealthStates.Sick: //if state is sick, then matching water and sleep gives bonus health //bonusTag = "Water"; //bonusTag1 = "Sleeping"; rateOfDecrease = 1.0f; //changes the rate of decrease to 1 break; case HealthStates.Neutral: //if state is neutral, then matching fruit and veg gives bonus health //bonusTag = "Fruit"; //bonusTag1 = "Vegetable"; rateOfDecrease = 1.25f; //changes the rate of decrease to 1.25 break; case HealthStates.Healthy: //if state is healthy, then matching running gives bonus health //bonusTag = "Running"; //bonusTag1 = "?"; rateOfDecrease = 1.5f; //changes the rate of decrease to 1.5 break; } }
// Start is called before the first frame update void Start() { damageTaken = false; currentCount = maxInvinceTime; healthBar.maxValue = maxHealth; healthBar.value = maxHealth; currentHealth = maxHealth; //Player states deadHealthState = this.GetComponent <Dead>(); fullHealthState = this.GetComponent <FullHealth>(); halfHealthState = this.GetComponent <HalfHealth>(); quarterHealthState = this.GetComponent <QuarterHealth>(); currentHealthState = fullHealthState; currentHealthState.ChangeMovementParticle(); gm = FindObjectOfType <GameManager>(); }
private void CheckState() //function to do things according to the state of the health { if (currentHealth >= 100 && criteria.clearTiles == true) //if currentHealth is greater than 100 and tile criteria is cleared, it means that the player won { display.DisplayWinUI(); //displays the Win UI if (criteria.currentLevel + 1 == Player.m3unlockedlevels) //check if playing level is same as unlocked level { if (Player.m3unlockedlevels < 6) //when completing levels 1-5 { Player.coins += 10; //award 10 coins for passing level (one time claim) Debug.Log("You got 10 coins for winning this level!"); StartCoroutine(Login.UpdateCoins()); coinsChange = true; } else if (Player.m3unlockedlevels < 11) //when completing levels 6-10 { Player.coins += 30; //award 30 coins for passing level (one time claim) Debug.Log("You got 30 coins for winning this level!"); StartCoroutine(Login.UpdateCoins()); coinsChange = true; } else if (Player.m3unlockedlevels < 16) //when completing levels 11-15 { Player.coins += 50; //award 50 coins for passing level (one time claim) Debug.Log("You got 50 coins for winning this level!"); StartCoroutine(Login.UpdateCoins()); coinsChange = true; } else if (Player.m3unlockedlevels < 21) //when completing levels 16-20 { Player.coins += 60; //award 60 coins for passing level (one time claim) Debug.Log("You got 60 coins for winning this level!"); StartCoroutine(Login.UpdateCoins()); coinsChange = true; } else if (Player.m3unlockedlevels < 26) //when completing levels 21-25 { if (Player.m3unlockedlevels == 25) { Player.dateEndM3 = System.DateTime.Now; Player.m3Duration = (Player.dateEndM3 - Player.dateStartM3).ToString(); } Player.coins += 80; //award 80 coins for passing level (one time claim) Debug.Log("You got 80 coins for winning this level!"); StartCoroutine(Login.UpdateCoins()); coinsChange = true; } Player.m3unlockedlevels += 1; //increase unlocked level Player.Save(); StartCoroutine(Login.UpdateCoins()); StartCoroutine(Login.UpdateLives()); } } else if (currentHealth < 1) //if currentHealth is lesser than 1, meaning 0, it means that the player lost { display.DisplayDeathUI(); //displays the Death UI } else if (currentHealth < min_neutralHealth && currentHealth > 1) //red health, sick state { healthState = HealthStates.Sick; //nm.DisplayNotification(0); sr.sprite = sprites[0]; bannerSleep.SetActive(true); bannerEat.SetActive(false); bannerRun.SetActive(false); SetBoolActiveSleep(); SetBoolInactiveRun(); SetBoolInactiveEat(); if (!audiosrc.isPlaying) { audiosrc.Play(); } } else if (currentHealth >= min_neutralHealth && currentHealth < min_healthyHealth) //yellow health, neutral health { healthState = HealthStates.Neutral; //nm.DisplayNotification(1); sr.sprite = sprites[1]; if (audiosrc.isPlaying) { audiosrc.Stop(); } bannerSleep.SetActive(false); bannerEat.SetActive(true); bannerRun.SetActive(false); SetBoolActiveEat(); SetBoolInactiveRun(); SetBoolInactiveSleep(); } else if (currentHealth >= min_healthyHealth && currentHealth < 100f) //green health, healthy state { healthState = HealthStates.Healthy; //nm.DisplayNotification(2); sr.sprite = sprites[2]; if (audiosrc.isPlaying) { audiosrc.Stop(); } bannerSleep.SetActive(false); bannerEat.SetActive(false); bannerRun.SetActive(true); SetBoolActiveRun(); SetBoolInactiveEat(); SetBoolInactiveSleep(); } SetBonus(healthState); }
public void SetHealth(HealthStates health) { _health = health; }
/// <summary> /// What occurs when an entity changes HealthStates /// </summary> /// <param name="newHealthState">The new HealthState of the entity</param> protected virtual void OnHealthStateChange(HealthStates newHealthState) { }