IEnumerator SpawnWaves() { waveNum = 0; while (true) { waveNum++; if (waveEvents.ContainsKey(waveNum)) { waveEvents[waveNum].Invoke(); } WaveSetting wave = SelectWave(waveNum); Debug.Log("Begin Wave " + waveNum + " (" + wave.Name + ")"); OnRoundBegin?.Invoke(waveNum); waveInfoController.WaveNum = waveNum; //AlertText(wave.Name, Color.magenta); wave.WaveCallable?.Invoke(); ScaledWave scaledWave = new ScaledWave(wave, Mathf.Pow(enemyScaleBase, waveNum - 1)); while (scaledWave.HasEnemies) { List <GameObject> nextSet = scaledWave.GetNextSpawn(); // single tick foreach (GameObject prefab in nextSet) { // single spawn GameObject newEnemy = Instantiate(prefab, Vector3.zero, Quaternion.identity); enemiesSpawnedInWave.Enqueue(newEnemy); yield return(new WaitForSeconds((timePerTick * Mathf.Pow(tickScaleBase, waveNum - 1)) / nextSet.Count)); } yield return(new WaitForSeconds(timeBetweenTicks * Mathf.Pow(tickScaleBase, waveNum - 1))); } while (enemiesSpawnedInWave.Count > 0) { while (enemiesSpawnedInWave.Count > 0 && enemiesSpawnedInWave.Peek() == null) { enemiesSpawnedInWave.Dequeue(); } yield return(new WaitForSeconds(.5f)); } OnRoundEnd?.Invoke(waveNum); waveInfoController.StartTimer(timeBetweenWaves); yield return(new WaitForSeconds(timeBetweenWaves)); } }
IEnumerator thr_waveSpawn(int waveNum) { WaveSetting ws = FindWaveSetting(waveNum); float spawnCooltime = ws.waveSpawnCooltime; isOnWave = true; passCount = 0; heroDeathCount = 0; remainCountTextMesh.text = "(" + heroDeathCount.ToString() + " /" + ws.passCount.ToString() + ")"; while (heroDeathCount < ws.passCount) { if (passCount >= PassMaxNum) { currentWave--; break; } spawnCooltime -= Time.deltaTime; if (spawnCooltime <= 0) { spawnCooltime = ws.waveSpawnCooltime; int index = Random.Range(0, ws.spawnHeroForms.Count); Spawn(ws.spawnHeroForms[index]); } yield return(null); } currentWave++; isOnWave = false; currentWaveTextMesh.text = "Wave " + currentWave.ToString(); yield return(null); }
private static Vector2d CalculateOffset(WaveSetting setting, Vector2d position, double time) { var periodic = Math.Cos(Vector2d.Dot(setting.Frequency * setting.Direction, position) + setting.PhaseConstant * time); var x = setting.Q * setting.Amplitude * setting.Direction.X * periodic; var y = setting.Q * setting.Amplitude * setting.Direction.Y * periodic; return(new Vector2d(x, y)); }
private static Vector2d CalculateOffset(WaveSetting setting, Vector2d position, double time) { var periodic = Math.Cos(Vector2d.Dot(setting.Frequency * setting.Direction, position) + setting.PhaseConstant * time); var x = setting.Q * setting.Amplitude * setting.Direction.X * periodic; var y = setting.Q * setting.Amplitude * setting.Direction.Y * periodic; return new Vector2d(x, y); }
//=== public void HeroPassTheGoal() { passCount++; WaveSetting ws = FindWaveSetting(currentWave); float scoreGiven = scorePerHero * ws.scoreMult * 10; int score = (int)scoreGiven; GameManager.Instance.playerData.score -= score; //EffectHandler.Instance.TextPopup("-" + score.ToString(), deadHero.transform, Color.red, 1f); }
public void HeroDead() { List <Hero> newList = new List <Hero>(); Hero deadHero = null; foreach (Hero hero in heroes) { if (hero.isAlive) { newList.Add(hero); } else { deadHero = hero; } } heroes = newList; if (isOnWave) { heroDeathCount++; remainCountTextMesh.text = "(" + heroDeathCount.ToString() + " /" + FindWaveSetting(currentWave).passCount.ToString() + ")"; } if (!noReward) { WaveSetting ws = FindWaveSetting(currentWave); float scoreGiven = scorePerHero * ws.scoreMult; int score = (int)scoreGiven; GameManager.Instance.playerData.score += score; if (deadHero != null) { float goldGiven = goldGivenPerHero * GoldGivenExtraMult * deadHero.form.goldGivenMult; int gold = (int)goldGiven; GameManager.Instance.playerData.gold += gold; EffectHandler.Instance.TextPopup("<sprite=3>+" + gold.ToString(), spriteAsset_gold, deadHero.transform, Color.yellow, 1.2f); float percent = Random.Range(0, 100); if (percent >= 50 - gemObtainPercent && percent <= 50 + gemObtainPercent) { GameManager.Instance.playerData.gem += 1; EffectHandler.Instance.TextPopup("<sprite=0>+" + 1.ToString(), spriteAsset_gem, deadHero.transform, Color.blue, 1.4f); } } } }
IEnumerator thr_normalSpawn(int waveNum) { WaveSetting ws = FindWaveSetting(waveNum); enemyList.DisplayEnemyList(ws.spawnHeroForms); float spawnCooltime = ws.normalSpawnCooltime; while (true) { spawnCooltime -= Time.deltaTime; if (spawnCooltime <= 0) { spawnCooltime = ws.normalSpawnCooltime; int index = Random.Range(0, ws.spawnHeroForms.Count); Spawn(ws.spawnHeroForms[index]); } yield return(null); } }
private static double CalculateHeight(WaveSetting setting, Vector2d position, double time) { return(setting.Amplitude * Math.Sin(Vector2d.Dot(setting.Frequency * setting.Direction, position) + setting.PhaseConstant * time)); }
public ScaledWave(WaveSetting setting, float enemyCountScale) { this.flattenedWave = Flatten(Scale(setting.EnemySets, enemyCountScale)); this.waveSetting = setting; }
//=== IEnumerator thr_spawnRoutine() { bool startWithWave = false; if (isOnWave) { startWithWave = true; } Coroutine waveSpawn = null; Coroutine normalSpawn = null; currentWaveTextMesh.text = "Wave " + currentWave.ToString(); while (true) { if (!startWithWave) { normalSpawn = StartCoroutine(thr_normalSpawn(currentWave)); if (waveSpawn != null) { StopCoroutine(waveSpawn); } } else { WaveSetting ws = FindWaveSetting(currentWave); enemyList.DisplayEnemyList(ws.spawnHeroForms); OnClick_PlayWave(); startWithWave = false; } while (!isOnWave) { yield return(null); } if (normalSpawn != null) { StopCoroutine(normalSpawn); } noReward = true; foreach (Hero delHr in heroes) { delHr.DeadWithEffect("disappear"); } noReward = false; waveSpawn = StartCoroutine(thr_waveSpawn(currentWave)); while (isOnWave) { yield return(null); } UIHandler.Instance.floorBuilder.UpdateUI(); if (passCount >= PassMaxNum) { noReward = true; } foreach (Hero delHr in heroes) { delHr.DeadWithEffect("disappear"); } GameManager.Instance.SaveGame(); wavePlayButton.gameObject.SetActive(true); remainCountTextMesh.gameObject.SetActive(false); yield return(null); } }
private static double CalculateHeight(WaveSetting setting, Vector2d position, double time) { return setting.Amplitude * Math.Sin(Vector2d.Dot(setting.Frequency * setting.Direction, position) + setting.PhaseConstant * time); }