/// <summary> /// Gets the number of each type of food in the scene /// </summary> /// <param name="fc"></param> private void GetFoodCount(FoodColoring fc) { switch (fc) { case FoodColoring.Red: RedCount++; break; case FoodColoring.Blue: BlueCount++; break; case FoodColoring.Green: GreenCount++; break; case FoodColoring.Ultra: UltraCount++; break; case FoodColoring.Digested: break; //case FoodColoring.Stale: // break; case FoodColoring.Nibbled: break; } }
/// <summary>GetFoodType: /// Determines which SnakeKibble object to look for based on the currentpattern; /// </summary> public FoodColoring GetFoodType(int i) { FoodColoring temp = FoodColoring.Red; switch (i) { case 0: temp = FoodColoring.Red; break; case 1: temp = FoodColoring.Blue; break; case 2: temp = FoodColoring.Green; break; case 3: temp = FoodColoring.Ultra; break; } ; return(temp); }
/// <summary> /// /// </summary> /// <param name="other"></param> private void OnTriggerEnter(Collider other) { GameObject collisionGO = other.gameObject; if (collisionGO.GetComponent <Snake>() != null) { if (collisionGO.GetComponent <Snake>().AcquiredTarget == this.gameObject) { EventManager.CallFoodEaten(collisionGO.GetComponent <Snake>(), isStale); typeofFood = FoodColoring.Digested; EventManager.CallFoodDespawn(this.gameObject); wasEaten = true; } } else if (collisionGO.GetComponent <Bullet>() != null) { if (!isStale) { isStale = true; EventManager.CallBulletHit(collisionGO, isStale); EventManager.CallBulletHitScore(scoreAmountForShootingFood); EventManager.CallDisplayScore(transform.position); EventManager.CallDisplayMultiplier(0, transform.position); staleFoodVisual.SetActive(true); hitByProjectileAudioSource.Stop(); hitByProjectileAudioSource.clip = hitByProjectileClip; hitByProjectileAudioSource.loop = false; hitByProjectileAudioSource.Play(); } else { collisionGO.GetComponent <Bullet>().HasHitFood = true; } } }
private void OnTriggerStay(Collider other) { if (!wasEaten) { GameObject collisionGO = other.gameObject; if (collisionGO.GetComponent <Snake>() != null) { if (collisionGO.GetComponent <Snake>().AcquiredTarget == this.gameObject) { EventManager.CallFoodEaten(collisionGO.GetComponent <Snake>(), isStale); typeofFood = FoodColoring.Digested; EventManager.CallFoodDespawn(this.gameObject); } } } }
/// <summary> RandomizeColor: /// Determines food type /// Called in awake method and will be used by snake to determine what food to eat next. /// </summary> private void RandomizeColor() { Renderer rend = GetComponent <Renderer>(); rend.material.shader = Shader.Find("Specular"); int i = UnityEngine.Random.Range(0, 4); switch (i) { default: typeofFood = FoodColoring.Red; prevtypeofFood = FoodColoring.Red; rend.material.SetColor("_Color", Color.red); break; case 0: typeofFood = FoodColoring.Red; prevtypeofFood = FoodColoring.Red; rend.material.SetColor("_Color", Color.red); break; case 1: typeofFood = FoodColoring.Blue; prevtypeofFood = FoodColoring.Blue; rend.material.SetColor("_Color", Color.blue); break; case 2: typeofFood = FoodColoring.Green; prevtypeofFood = FoodColoring.Green; rend.material.SetColor("_Color", Color.green); break; case 3: typeofFood = FoodColoring.Ultra; prevtypeofFood = FoodColoring.Ultra; rend.material.SetColor("_Color", Color.magenta); break; } snakeKibbleVisuals[i].SetActive(true); EventManager.CallTypeOfFoodChoosen(targetedFoodLayerChange, snakeKibbleVisuals[i]); EventManager.CallFoodTypeChoice(this.gameObject); }
/// <summary> /// EdgeCase control for when a food count is higher than it should be /// called by CheckTrue() in the case that a pattern is available when it shouldn't be. /// Will need to be modified /// </summary> /// <param name="fc"></param> private void RemoveFood(FoodColoring fc) { switch (fc) { case FoodColoring.Red: if (RedCount > 0) { AvailableFoodTypes.Remove(FoodColoring.Red); RedCount--; } break; case FoodColoring.Blue: if (BlueCount > 0) { AvailableFoodTypes.Remove(FoodColoring.Blue); BlueCount--; } break; case FoodColoring.Green: if (GreenCount > 0) { AvailableFoodTypes.Remove(FoodColoring.Green); GreenCount--; } break; case FoodColoring.Ultra: if (UltraCount > 0) { AvailableFoodTypes.Remove(FoodColoring.Ultra); UltraCount--; } break; } }
/// <summary> Hunt: /// This function is used to determine what food type to go after and whether or not it has eaten /// that type of food and should move on to the next food type in the pattern. /// </summary> public virtual void Hunt() { if (FM.tempTarget[0] == false) { TargetFoodType = FM.GetFoodType(CurrentPattern[0]); FindNextFood(); } else if (FM.tempTarget[0] == true && FM.tempTarget[1] == false) { TargetFoodType = FM.GetFoodType(CurrentPattern[1]); FindNextFood(); } else if (FM.tempTarget[0] == true && FM.tempTarget[1] == true && FM.tempTarget[2] == false) { TargetFoodType = FM.GetFoodType(CurrentPattern[2]); FindNextFood(); } else { ChangePattern(); FM.TemporaryTargetReset(); } }