// Calculate a rockets difficulty public static float GetDifficulty(WaveEntry _entry, float _timeSinceLastSpawn, float _lowRange, float _highRange) { float diff = RocketDifficulty[_entry.Type]; // The base difficulty. diff += (1 - ((_timeSinceLastSpawn - _lowRange) / (_highRange - _lowRange))) * diff; // The difficulty increases the shorter the time between them. return(diff); }
public bool GetByName(string name, out WaveEntry wave) { if (!entriesByName.TryGetValue(name, out wave)) { Debug.LogError($"Invalid name {name}"); return(false); } return(true); }
private void StartWave() { // Remove all items to be spawned waveCache.Clear(); // Get the wave entry WaveEntry entry = waves[waveIndex]; // Populate the wave cache with the items for the wave waveCache.Populate(entry); }
// Spawn a rocket. public void SpawnRocket(WaveEntry _entry) { // Get the correct prefab. GameObject prefab = (GameObject)Resources.Load("Prefabs/Rockets/" + _entry.Type, typeof(GameObject)); Vector3 position = Camera.main.transform.position + (_entry.Position * Camera.main.orthographicSize * 2); position.y = 0; GameObject rocket = (GameObject)Instantiate(prefab, position, Quaternion.LookRotation(-_entry.Position)); rocket.GetComponent <Rigidbody>().velocity = GameObject.FindGameObjectWithTag("Player").GetComponent <Rigidbody>().velocity; }
public void Populate(WaveEntry entry) { // Fetch the wave data and populate the spawn queue List <WaveEntryData> waveEntries = entry.Enemies; foreach (WaveEntryData data in waveEntries) { for (int i = 0; i < data.Count; i++) // Queue the number of enemies for the wave data { spawnQueue.Enqueue(data.ID); } } }
/// <summary> /// Create a Nitro Studio 2 Instrument. /// </summary> /// <param name="inst">The instrument.</param> /// <param name="s">Sound archive.</param> /// <param name="war0">Wave archive 0.</param> /// <param name="war1">Wave archive 1.</param> /// <param name="war2">Wave archive 2.</param> /// <param name="war3">Wave archive 3.</param> public NitroStudio2Instrument(Instrument inst, SoundArchive s, ushort war0, ushort war1, ushort war2, ushort war3) { //Set instrument. Inst = inst; //No archive. if (s == null) { return; } //Load waves. Waves = new List <WaveEntry>(); foreach (var n in inst.NoteInfo) { WaveEntry w = new WaveEntry(); w.WaveId = n.WaveId; if (n.InstrumentType != InstrumentType.PCM) { continue; } switch (n.WarId) { case 0: n.WarId = w.WarId = war0; break; case 1: n.WarId = w.WarId = war1; break; case 2: n.WarId = w.WarId = war2; break; case 3: n.WarId = w.WarId = war3; break; } if (n.WarId != 0xFFFF) { var war = s.WaveArchives.Where(x => x.Index == (int)n.WarId).FirstOrDefault(); if (war != null) { w.Wave = war.File.Waves[n.WaveId]; } } Waves.Add(w); } }
public void Load(BinaryReader _reader) { // Clear the entries entries.Clear(); // Read how many entries there are int count = _reader.ReadInt32(); // Loop through all of the entries and read them. for (int i = 0; i < count; ++i) { WaveEntry entry = new WaveEntry(); entry.Load(_reader); entries.Add(entry); } }
public void AddProgramData(WaveEntry we, int index) { //fix up vectors int wSize = mWaveList.Length; for (int w = 0; w < wSize; w++) { int eSize = we.mProgramList [w].mLaunchEntry.entry.Length; for (int e = 0; e < eSize; e++) { we.mProgramList [w].mLaunchEntry.entry [e].startingPointV3 = we.mProgramList [w].mLaunchEntry.entry [e].startingPointRaw.transform.position; } } mWaveList[index] = we; }
private void spawnEntry(WaveEntry entry) { List <Enemy> availableEnemies = null; switch (entry.EnemyLevel) { case 1: availableEnemies = EnemiesL1; break; case 2: availableEnemies = EnemiesL2; break; case 3: availableEnemies = EnemiesL3; break; } spawn(availableEnemies[Random.Range(0, availableEnemies.Count)], entry.X, entry.Y); }
// Generate a wave worth a certain point. public static Wave GenerateRandomWave(float _num) { System.Random detRand = new System.Random(1337 + waveNum); //determanistic random number // Using the difficulty number, calculate a few values // How closely the rockets will be spawned together. float spawnDensity = (1 / (_num + 1)) * 50; if (spawnDensity < 0.01f) { spawnDensity = 0.01f; } float lowRange = spawnDensity - (spawnDensity / 4); float highRange = spawnDensity + (spawnDensity / 4); // The max difficulty of a single rocket. float maxDiff = _num / 2; // Start calculating the wave. Wave wave = new Wave(); float time = 5.0f; bool firstRocket = true; while (_num > 0) { WaveEntry entry = new WaveEntry(); float angle = RandInRange(detRand, -Mathf.PI, Mathf.PI); entry.Position = new Vector3(Mathf.Sin(angle), 0, Mathf.Cos(angle)); // Get a random rocket type. int type = detRand.Next(0, 4); switch (type) { case 0: entry.Type = "PointAtRocket"; break; case 1: entry.Type = "ProportionalRocket"; break; case 2: entry.Type = "Leading"; break; case 3: entry.Type = "ClusterRocket"; break; default: entry.Type = "PointAtRocket"; break; } // Get a random time. float extraTime = RandInRange(detRand, lowRange, highRange); // Calculate the difficulty of this rocket. float diff = GetDifficulty(entry, extraTime, lowRange, highRange); // Check if we can spawn this rocket. while (diff > maxDiff) { // Try increasing the time to spawn it. extraTime += (highRange - lowRange) / 10; // If we are at the max extratime if (extraTime > highRange) { extraTime = highRange; // Try making the rocket easier. bool found = false; foreach (KeyValuePair <string, float> pair in RocketDifficulty) { if (pair.Value < RocketDifficulty[entry.Type]) { entry.Type = pair.Key; found = true; break; } } if (found == false) { // Nothing else we can do to make it any easier, just set _num to 0 and start the next wave. _num = 0; return(wave); } } // Recalculate the difficulty diff = GetDifficulty(entry, extraTime, lowRange, highRange); } // Take the diff away. _num -= diff; // Add to the wave if (firstRocket) { // If this is the first rocket, then spawn it first regardless of the time that was previously calculated. firstRocket = false; } else { time += extraTime; } entry.Time = time; wave.Entries.Add(entry); } return(wave); }