/// <summary> /// Advance to the next level, create the next map, and readjust the size of /// the player as necessary. /// <para>Every other 5 levels alternates between daytime and nighttime, starting /// with levels 1-5 being daytime, and 6-10 being nighttime.</para> /// </summary> void NextLevel() { // Remove all active asteroids for (int i = 0; i < asteroidObjects.Count; i++) { RemoveAsteroid(i); } // Remove all active bullets for (int b = 0; b < bullets.Count; b++) { RemoveBullet(b); } // Set the next level type based on new level number if ((levelManager.Level / 5) % 2 == 0) { nextLevelType = LevelManager.LevelType.Normal; } //else if ((levelManager.Level / 5) % 2 == 1) //{ // nextLevelType = LevelManager.LevelType.Night; //} else { nextLevelType = LevelManager.LevelType.Normal; } NextLevel(nextLevelType); }
public override void OnInspectorGUI() { #if UNITY_EDITOR serializedObject.Update(); EditorGUILayout.PropertyField(type); LevelManager.LevelType ty = (LevelManager.LevelType)type.enumValueIndex; EditorGUILayout.PropertyField(cP); switch (ty) { case LevelManager.LevelType.Battleground: EditorGUILayout.PropertyField(serializedObject.FindProperty("targetKills")); EditorGUILayout.PropertyField(serializedObject.FindProperty("enemiesKilled")); break; } EditorGUILayout.PropertyField(vT); EditorGUILayout.PropertyField(lTL); serializedObject.ApplyModifiedProperties(); #endif }
/// <summary> /// Advance to the next level, create the next map, and readjust the size of /// the player as necessary. /// </summary> /// <param name="nextLevelType">Force set the level type of the next level /// generated</param> void NextLevel(LevelManager.LevelType nextLevelType) { // Reset level-specific stats timer = 0; levelTransitionTimer = 0 + transitionTime; levelScore = 0; openDoor = false; score += (levelManager.Level * 100); // Remove all active asteroids and bullets for (int i = 0; i < asteroidObjects.Count; i++) { RemoveAsteroid(i); i--; } for (int b = 0; b < bullets.Count; b++) { RemoveBullet(b); b--; } // Advance to the level and create the next map levelManager.AdvanceLevel( nextLevelType, Mathf.Clamp( ((levelManager.Level + 1) / 3) + 7, 7, 20)); // Set stats for map dependent on level and level type if (nextLevelType == LevelManager.LevelType.Tutorial) { maxAsteroidCount = 5; minAsteroidSpawnTimer = .4f; maxAsteroidSpawnTimer = 3f; chaserSpawnChance = 0; //lifeDropChance = 0; smallKeyDropChance = .3f; levelGoal = 1; } // Increment difficulty of next level else if (levelManager.Level <= 20) { // Level stats levelGoal = 2 + ((levelManager.Level - 1) * 4); maxAsteroidCount = 10 + (int)((levelManager.Level - 1) * .8f); minAsteroidSpawnTimer = .4f - (levelManager.Level * .015f); maxAsteroidSpawnTimer = 1.3f - (levelManager.Level * .05f); // Drop and Spawn Rarities if (levelManager.Level == 3) { chaserSpawnChance = .15f; // 150% chaser spawn chance } else { if (levelManager.Level == 2) { chaserSpawnChance = 0; } else { // 01.00% -> 4.00% chaser spawn chance chaserSpawnChance = .01f * (1f + (levelManager.Level * .15f)); } // 80.00% -> 40.00% chaser key drop chance chaserKeyDropChance = .01f * (80f - (levelManager.Level * 2f)); // 40.00% -> 01.00% small key drop chance smallKeyDropChance = .01f * (40f - (levelManager.Level * 1.95f)); // 01.00% -> 00.50% life drop chance //lifeDropChance = .01f * (1f - (levelManager.Level * .025f)); } } // Maximum difficulty for everything except minimum number of asteroids // needed to enable key drop else { levelGoal = (int)((levelManager.Level - 1) * 1.3f) + 52; // These should be the permanent final values for the following: maxAsteroidCount = 30; minAsteroidSpawnTimer = .1f; maxAsteroidSpawnTimer = .3f; chaserSpawnChance = .04f; // 4.00% chaser spawn chance chaserKeyDropChance = .4f; // 40.00% chaser key drop chance smallKeyDropChance = .01f; // 01.00% small key drop chance //lifeDropChance = .005f; // 00.50% life drop chance } // Three seconds before first asteroid spawns asteroidTime = 3f; player.ResetBulletCooldown(); // Scale key keyScale = LevelManager.GetScaleSpriteToTileSize( doorKey.GetComponent <SpriteInfo>(), levelManager.UnitsPerSquare * .75f); doorKey.GetComponent <SpriteInfo>().Radius = levelManager.UnitsPerSquare * .75f; #region Scale Player // Resize the player & their bounds based upon the new size of the map if (player.SpriteInfo != null && levelManager.LeveHeight > 4) { playerToTileScale = levelManager.GetScaleSpriteToTileSize(player.SpriteInfo); playerToTileScale.x *= PlayerToTileSizeRatio; playerToTileScale.y *= PlayerToTileSizeRatio; if (player.SpriteInfo.Shape == SpriteInfo.BoundingShape.Box) { player.SpriteInfo.Radius = levelManager.UnitsPerSquare * ((playerToTileScale.x + playerToTileScale.y / 2) / 2); } else { player.SpriteInfo.Radius = levelManager.UnitsPerSquare * PlayerToTileSizeRatio; } player.transform.localScale = playerToTileScale; player.transform.position = levelManager.GetRandomSpawnLocation(); player.ForceAngle(Random.Range(0, 4) * 90); } #endregion #region Scale Bullet // Resize the bullets shot by the player if (player.bullet != null && player.bullet.GetComponent <SpriteInfo>() != null && levelManager.LeveHeight > 4) { playerToTileScale = levelManager.GetScaleSpriteToTileSize( player.bullet.GetComponent <SpriteInfo>()); playerToTileScale.x *= PlayerToTileSizeRatio * .35f; playerToTileScale.y *= PlayerToTileSizeRatio * .35f; player.BulletScale = playerToTileScale; player.bullet.GetComponent <SpriteInfo>().Radius = levelManager.UnitsPerSquare * PlayerToTileSizeRatio * .35f; } #endregion // Rescale the asteroids and their radii with the new map size AsteroidBehavior.RescaleAsteroids(levelManager.UnitsPerSquare); }
// Use this for initialization void Start() { // Set timers and time limits to default values #region Timer Setup timer = 0; asteroidTime = 0; transitionTime = 0; // Asteroid spawn timer if (minAsteroidSpawnTimer < 0) { minAsteroidSpawnTimer = .15f; } if (maxAsteroidSpawnTimer <= 0) { maxAsteroidSpawnTimer = 4.5f; } if (maxAsteroidSpawnTimer > minAsteroidSpawnTimer) { maxAsteroidSpawnTimer = minAsteroidSpawnTimer + 1f; } if (maxAsteroidCount <= 0) { maxAsteroidCount = 40; } #endregion // Assign the player this object as the game manager player.GameManager = this; playerToTileScale = Vector3.one; AsteroidBehavior.player = player; scoreScreen.gameObject.SetActive(true); gameOverScreen.gameObject.SetActive(false); // Instantiate bullet list - all active bullets in scene bullets = new List <GameObject>(); // Ensure valid number of lives if (lives <= 0) { lives = 3; } asteroidObjects = new List <SpriteInfo>(); // Ensure all asteroids have proper components. If not a sprite, // don't keep track of it. #region Asteroid Setup foreach (GameObject asteroid in largeAsteroids) { if (asteroid.GetComponent <SpriteRenderer>() != null) { // Ensure the asteroid has the necessary scripts if (asteroid.GetComponent <SpriteInfo>() == null) { asteroid.AddComponent <SpriteInfo>(); } if (asteroid.GetComponent <AsteroidBehavior>() == null) { asteroid.AddComponent <AsteroidBehavior>(); asteroid.GetComponent <AsteroidBehavior>().AsteroidType = AsteroidBehavior.Asteroid.Large; } } else { largeAsteroids.Remove(asteroid); } } foreach (GameObject asteroid in miniAsteroids) { if (asteroid.GetComponent <SpriteRenderer>() != null) { // Ensure the asteroid has the necessary scripts if (asteroid.GetComponent <SpriteInfo>() == null) { asteroid.AddComponent <SpriteInfo>(); } if (asteroid.GetComponent <AsteroidBehavior>() == null) { asteroid.AddComponent <AsteroidBehavior>(); asteroid.GetComponent <AsteroidBehavior>().AsteroidType = AsteroidBehavior.Asteroid.Small; } } else { miniAsteroids.Remove(asteroid); } } foreach (GameObject asteroid in chaserAsteroids) { if (asteroid.GetComponent <SpriteRenderer>() != null) { // Ensure the asteroid has the necessary scripts if (asteroid.GetComponent <SpriteInfo>() == null) { asteroid.AddComponent <SpriteInfo>(); } if (asteroid.GetComponent <AsteroidBehavior>() == null) { asteroid.AddComponent <AsteroidBehavior>(); asteroid.GetComponent <AsteroidBehavior>().AsteroidType = AsteroidBehavior.Asteroid.Chaser; } } else { chaserAsteroids.Remove(asteroid); } } // Set the Asteroid class prefabs and other variables AsteroidBehavior.LargeAsteroids = largeAsteroids; AsteroidBehavior.SmallAsteroids = miniAsteroids; AsteroidBehavior.ChaserAsteroids = chaserAsteroids; if (maxAsteroidSplitAngle < 0) { maxAsteroidSplitAngle *= -1; } MaxAsteroidSplitAngle = maxAsteroidSplitAngle; #endregion // The indices of objects colliding with another object collidingIndices = new List <int>(asteroidObjects.Count); // Set up the first level #region Level Setup if (levelManager == null) { levelManager = new LevelManager(); } nextLevelType = LevelManager.LevelType.Tutorial; NextLevel(nextLevelType); #endregion }