public void Win() { Debug.Log("YOU WIN THE LEVEL"); Player.Instance.gameObject.SetActive(false); PlayerGUI.Instance.Disable(); StartCoroutine(VictoryCoroutine()); IEnumerator VictoryCoroutine() { float t = 0.0f; LoadingUI.SetActive(true); while (t < 3) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(t / 3.0f); yield return(null); } BoidsManager.ClearBoids(); PlayerGUI.Instance.Disable(); SceneManager.LoadScene(1); yield return(null); } }
protected virtual void Init() { //For Hierarchy management //All boids will appear under the a game object transform.SetParent(BoidAnchor, true); stats = GetComponent <BoidStats>(); BoidsManager.AddBoid(this); }
private void Start() { Velocity = Random.onUnitSphere * Settings.MaxSpeed; WanderTarget = transform.position; Collider = GetComponent <SphereCollider>(); GetComponent <Health>().onDeath += () => { BeeSound.Stop(); BoidsManager.DeleteBoid(this); }; }
protected void Awake() { if (s_instance != null) { Debug.LogError(name + " shouldn't have a BoidsManager referenced already."); } else { s_instance = this; } }
// Called before first frame update void Start() { // Components rigidbody = GetComponent <Rigidbody>(); // Flock boidsManager = GetComponentInParent <BoidsManager>(); // Initialise transform.position = new Vector3(Random.value * 200.0f, 0.5f, Random.value * 200.0f); rigidbody.velocity = new Vector3(Random.value * 2 - 1, Random.value * 2 - 1, Random.value * 2 - 1); }
private void KillTarget() { Hunger += 100; SoundManager.PlayAudio(SOUNDS.EAT_SOUND, 0.2f); KillCount++; BoidsManager.RemoveBoid(target.GetComponent <BoidsAgent>()); target = null; }
private void SaveBarracudas() { List <BoidsAgent> bCudaAgents = BoidsManager.GetBarracudas(); barracudasHunger = new int[bCudaAgents.Count]; barracudasKC = new int[bCudaAgents.Count]; for (int i = 0; i < bCudaAgents.Count; i++) { BaracudaScript cuda = bCudaAgents[i] as BaracudaScript; barracudasHunger[i] = (int)cuda.Hunger; barracudasKC[i] = cuda.killCount; } }
public void Buy() { if (ScoreManager.Score >= Price) { BoidsManager.Spawn(fishType); ScoreManager.Score -= Price; Debug.Log(fishType.ToString() + " bought!"); } else { Debug.Log("not enough money"); // SoundManager.PlayAudio(SOUNDS.INVALID_INPUT, 0.3f); } }
void Awake() { instance = this; }
private void Awake() { Instance = this; }
public void LoadLevel() { OnStartedLoad?.Invoke(); //Level data float level = PersistentData.Instance.Level / 10f; level = level > 1f ? 1f : level; //Segs int Segments = (int)Mathf.Lerp(SegmentsMinMax.x, SegmentsMinMax.y, level); //Sporadics float SporadicMax = Mathf.Lerp(SporadicMinMax.x, SporadicMinMax.y, Mathf.Clamp01(level + 0.3f)); float Sporadic = UnityEngine.Random.Range(SporadicMinMax.x, SporadicMax); //Noise size float NoiseScale = UnityEngine.Random.Range(NoiseScaleMinMax.x, NoiseScaleMinMax.y); //Boids _BoidsPerSegment = (int)Mathf.Lerp(BoidsPerSegmentMinMax.x, BoidsPerSegmentMinMax.y, level); //Walls float CaveWallAmountMax = Mathf.Lerp(CaveWallAmountMinMax.x, CaveWallAmountMinMax.y, Mathf.Clamp01(level + 0.5f)); float CaveWallAmount = UnityEngine.Random.Range(CaveWallAmountMinMax.x, CaveWallAmountMax); //Ohno things in the way float InternalCaveAmountMax = Mathf.Lerp(InternalCaveAmountMinMax.x, InternalCaveAmountMinMax.y, Mathf.Clamp01(level + 0.5f)); float InternalCaveAmount = UnityEngine.Random.Range(InternalCaveAmountMinMax.x, InternalCaveAmountMax); //Ohno things in the way noise float InternalCaveNoise = UnityEngine.Random.Range(InternalCaveNoiseMinMax.x, InternalCaveNoiseMinMax.y); //Safety hole float HoleSize = UnityEngine.Random.Range(HoleSizeMinMax.x, HoleSizeMinMax.y); StartCoroutine(buildLevel()); IEnumerator buildLevel() { PersistentData.Instance.Level++; PlayerGUI.Instance.Disable(); LoadingUI.SetActive(true); LoadingText.gameObject.SetActive(true); ProgressText.gameObject.SetActive(true); HighScoreText.gameObject.SetActive(true); LevelText.gameObject.SetActive(true); FadeImage.color = Color.black.withAlpha(1.0f); Player.Instance.gameObject.SetActive(false); ProgressText.text = $"Generated 0/{Segments} Segments"; LevelText.text = $"Level {PersistentData.Instance.Level}"; HighScoreText.text = $"Highscore: {PlayerPrefs.GetInt("Highscore", 0)}"; Tunnel.Progress += (i) => { ProgressText.text = $"Loaded {i+1}/{Segments} Segments"; }; yield return(Tunnel.createLevelSLowLike(Segments, Sporadic, NoiseScale, CaveWallAmount, InternalCaveAmount, InternalCaveNoise, HoleSize)); SplineNoise3D.Spline end = SplineNoise3D.SplineLine[SplineNoise3D.SplineLine.Count - 2]; GameObject go = Instantiate(VictoryZonePrefab, end.pos, Quaternion.identity); go.transform.localScale = new Vector3(end.radius, end.radius, end.radius); int count = 0; foreach (var s in SplineNoise3D.SplineHole) { if (count > 2 && count < SplineNoise3D.SplineHole.Count - 2) { BoidsManager.Spawn(s.pos, s.radius * 0.5f, _BoidsPerSegment, Player.Instance.transform); } count++; } Vector3 forward = (SplineNoise3D.SplineHole[1].pos - SplineNoise3D.SplineHole[0].pos).normalized; Player.Instance.transform.position = SplineNoise3D.SplineHole[0].pos + forward * 2f; Player.Instance.SetForward(forward); Player.Instance.gameObject.SetActive(true); PlayerGUI.Instance.Enable(); LoadingText.gameObject.SetActive(false); ProgressText.gameObject.SetActive(false); LevelText.gameObject.SetActive(false); HighScoreText.gameObject.SetActive(false); float t = 0.0f; while (t < FadeOutTime) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(1f - t / FadeOutTime); yield return(null); } LoadingUI.SetActive(false); Player.Instance.MovementMachine.TransitionTo <FlyingState>(); } }
public override Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids) { if (Weights.Length != Behaviours.Length) { Debug.LogError("WEIGHTS AND BEHAVIOURS ARE NOT THE SAME AMOUNTS"); return(Vector2.zero); } Vector2 Move = Vector2.zero; for (int i = 0; i < Behaviours.Length; i++) { Vector2 PartialMove = Behaviours[i].CalculateMove(Boid, NeighbourBoids, AllBoids) * Weights[i]; if (PartialMove != Vector2.zero) { if (PartialMove.sqrMagnitude > Weights[i] * Weights[i]) { PartialMove.Normalize(); PartialMove *= Weights[i]; } Move += PartialMove; } } return(Move); }
public void GameOver() { Debug.Log("You died"); Player.Instance.gameObject.SetActive(false); var volume = Camera.main.GetComponent <PostProcessVolume>(); volume.profile.TryGetSettings(out ChromaticAberration chromatic); chromatic.intensity.value = 0.0f; OnStartedLoad?.Invoke(); PersistentData.Instance.DecreaseLives(); if (PersistentData.Instance.Lives <= 0) { PersistentData.Instance.ResetLives(); PersistentData.Instance.ResetMultiplier(); PersistentData.Instance.Level = 0; StartCoroutine(GameOverRoutine()); return; } IEnumerator GameOverRoutine() { float t = 0.0f; LoadingUI.SetActive(true); PlayerGUI.Instance.Disable(); FadeImage.color = Color.black.withAlpha(0.0f); while (t < 3) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(t / 3.0f); yield return(null); } GameOverObject.SetActive(true); GameOverObject.GetComponentInChildren <TextMeshProUGUI>().text = $"GAME OVER\nYour Score Was\n{PersistentData.Instance.Score}"; if (PlayerPrefs.GetInt("Highscore", 0) == PersistentData.Instance.Score) { GameOverObject.GetComponentInChildren <TextMeshProUGUI>().text += "\nNEW HIGH SCORE!"; } PersistentData.Instance.ResetScore(); yield return(new WaitForSeconds(3f)); GameOverObject.SetActive(false); LoadingUI.SetActive(false); LoadLevel(); yield return(null); } StartCoroutine(DieRoutine()); IEnumerator DieRoutine() { LoadingUI.SetActive(true); PlayerGUI.Instance.Disable(); float t = 0.0f; while (t < 3) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(t / 3.0f); yield return(null); } FadeImage.color = Color.black.withAlpha(1.0f); Vector3 forward = (SplineNoise3D.SplineHole[1].pos - SplineNoise3D.SplineHole[0].pos).normalized; Player.Instance.transform.position = SplineNoise3D.SplineHole[0].pos + forward * 2f; Player.Instance.SetForward(forward); Player.Instance.gameObject.SetActive(true); Player.Instance.MovementMachine.TransitionTo <IdleState>(); BoidsManager.ClearBoids(); int count = 0; foreach (var s in SplineNoise3D.SplineHole) { if (count > 2) { BoidsManager.Spawn(s.pos, s.radius * 0.5f, _BoidsPerSegment, Player.Instance.transform); } count++; } t = 0.0f; PlayerGUI.Instance.Enable(); while (t < FadeOutTime) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(1f - t / FadeOutTime); yield return(null); } FadeImage.color = Color.black.withAlpha(0.0f); Player.Instance.MovementMachine.TransitionTo <FlyingState>(); LoadingUI.SetActive(false); } }
private void OnDestroy() { BoidsManager.RemoveBoid(this); }
public void SetBoidManager(BoidsManager a_manager) { boidManager = a_manager; }
private void OnTriggerExit(Collider other) { if (other.CompareTag("bounds")) { Vector3 bounds = other.GetComponent <Collider>().bounds.size; Vector3 otherPos = other.transform.position; bool wrapped = false; //If exit right if (transform.position.x > otherPos.x + (bounds.x / 2)) { transform.position = new Vector3(otherPos.x - (bounds.x / 2), transform.position.y, transform.position.z); wrapped = true; } else { //if exit left if (transform.position.x < otherPos.x - (bounds.x / 2)) { transform.position = new Vector3(otherPos.x + (bounds.x / 2), transform.position.y, transform.position.z); wrapped = true; } } if (transform.position.z > otherPos.z + (bounds.z / 2)) { //if exit forward transform.position = new Vector3( transform.position.x, transform.position.y, otherPos.z - (bounds.z / 2)); wrapped = true; } else { //if exit backwards if (transform.position.z < otherPos.z - (bounds.z / 2)) { transform.position = new Vector3( transform.position.x, transform.position.y, otherPos.z + (bounds.z / 2)); wrapped = true; } } //if exited bounds but none of the above //(they steer up and down to avoid bottom and top, but just in case) if (!wrapped) { Transform sP = BoidsManager.GetRandomSpawnPoint(); //Respawn this.transform.position = sP.position; this.transform.rotation = sP.rotation; #if DEBUG OobCount++; Debug.LogWarning( "Out of bound count: " + OobCount + " - total time: " + Time.time, gameObject); #endif } //invoke out of bounds event if not null onOutOfBounds?.Invoke(); } }
public override Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids) { if (NeighbourBoids.Count == 0) { return(Vector2.zero); } Vector2 CohesionMove = Vector2.zero; foreach (Transform Item in NeighbourBoids) { CohesionMove += (Vector2)Item.position; } CohesionMove /= NeighbourBoids.Count; CohesionMove -= (Vector2)Boid.transform.position; return(CohesionMove); }
public abstract Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids);
public void SetManager(BoidsManager argManager) { mManager = argManager; }
public override Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids) { if (TargetTrans == Vector2.zero) { return(Vector2.zero); } Vector2 TargetMove = TargetTrans; return(TargetMove); }
public override Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids) { if (NeighbourBoids.Count == 0) { return(Vector2.zero); } Vector2 SeparationMove = Vector2.zero; int AvoidObjects = 0; foreach (Transform Item in NeighbourBoids) { if (Vector2.SqrMagnitude(Item.position - Boid.transform.position) < AllBoids.SquareAvoidanceRadiusGet) { AvoidObjects++; SeparationMove += (Vector2)(Boid.transform.position - Item.position); } } if (AvoidObjects > 0) { SeparationMove /= AvoidObjects; } return(SeparationMove); }
public void Initialize(BoidsManager Boids) { GroupHandler = Boids; }
private void Awake() { Instance = this; boids = new List <BoidsAgent>(); }
public override Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids) { if (NeighbourBoids.Count == 0) { return(Vector2.zero); } Vector2 CohesionMove = Vector2.zero; List <Transform> FilterStuff = (Filter == null) ? NeighbourBoids : Filter.Filter(Boid, NeighbourBoids); foreach (Transform Item in FilterStuff) { CohesionMove += (Vector2)Item.position; } CohesionMove /= NeighbourBoids.Count; CohesionMove -= (Vector2)Boid.transform.position; if (float.IsNaN(CurrentVelocity.x) || float.IsNaN(CurrentVelocity.y)) { CurrentVelocity = Vector2.zero; } CohesionMove = Vector2.SmoothDamp(Boid.transform.up, CohesionMove, ref CurrentVelocity, BoidSmoothTime); return(CohesionMove); }
public override Vector2 CalculateMove(BoidObject Boid, List <Transform> NeighbourBoids, BoidsManager AllBoids) { if (NeighbourBoids.Count == 0) { return(Boid.transform.up); } Vector2 AlignmentMove = Vector2.zero; foreach (Transform Item in NeighbourBoids) { AlignmentMove += (Vector2)Item.transform.up; } AlignmentMove /= NeighbourBoids.Count; return(AlignmentMove); }