public Prototype Exclude(LevelPrototype prototypeForExclude) { return(new Prototype(_context, PrototypeItems .Where(itemPrototype => !prototypeForExclude .PrototypeItems .Contains(itemPrototype)))); }
public Prototype Exclude(LevelPrototype prototypeForExclude) { return new Prototype(_context, PrototypeItems .Where(itemPrototype => !prototypeForExclude .PrototypeItems .Contains(itemPrototype))); }
private void NewMap() { // Chance to increase difficulty if (difficultyLevel <= 0) { difficultyLevel++; } else if (Level % 8 == 0) // UnityEngine.Random.Range(1, 20) == 1 { difficultyLevel++; MessageLog_Manager.NewMessage("Monsters become stronger...", Color.red); if (difficultyLevel > 10) { // Game win Debug.Log("You won the game!"); Global.GameWin gameWin = new GameWin(); gameWin.FireEvent(); return; } } // TODO: PICK PROTOTYPE ACCORDING TO DIFFICULTY! if (difficultyLevel > 0) { List <LevelPrototype> potentialLevels = new List <LevelPrototype>(); for (int i = 0; i < levelPrototypes.Length; i++) { if (levelPrototypes[i].difficultyLevel >= difficultyLevel - 1 && levelPrototypes[i].difficultyLevel <= difficultyLevel) { potentialLevels.Add(levelPrototypes[i]); } } curLevelPrototype = potentialLevels[UnityEngine.Random.Range(0, potentialLevels.Count)]; } if (curLevelPrototype.Name == string.Empty) { curLevelPrototype = levelPrototypes[1]; } Debug.Log("New Map: diff=" + difficultyLevel + " curlvlProto name=" + curLevelPrototype.Name); mapManager.NewMap(Vector2.zero, Level, curLevelPrototype.darknessLevel); }
void StartGame() { Level = 0; difficultyLevel = -1; curLevelPrototype = levelPrototypes[0]; new TurnManager(); //TurnManager.instance.Init(); mapManager = new MapManager(); EntityActionManager.instance.Init(); Global.PlayerReachedExit.RegisterListener(OnPlayerExit); Global.OnMapCleared.RegisterListener(OnMapCleared); Global.OnMapCreated.RegisterListener(LoadEntities); NewMap(); }
public static void GenerateLevel(LevelPrototype levelData) { /*Summary of the platform generation: * This function is static, do not make objects of this class, only call it. * * How this code works: * 1. A list is declared to store all the platforms that are spawned * 2. A 2 dimensional int array is declared to store each tile position (this is important for rope spawning) * 3. Enter a while loop that will execute until the length of the platforms list is > our defined platform max count, * or the code exceeds a max iteration count * 4. A random point is generated within the size of the map * 5. The code now checks if the random point is valid against the perlin noise field (if the value of the nosie field * at that point is greater than the PerlinThreshold (defined in LevelData), then the code will continue) * 6. The random width of the platform is generated * 7. The random position of the platform is tested against all other platforms that exist, if it is too close, the point * is thrown away, and the while loop will start over * 8. If the platform has passed all the previous tests, it will now be added to the list of platforms * 9. The appropriate points in the 2D int array are set to 1 to store the platform tiles * 10. The ropes are generated (see summary below), and this class returns an array of platforms */ LevelPrototype ld = levelData; List <PlatformBase> platforms = new List <PlatformBase> (); int[,] levelArray = new int[ld.MapRadius, ld.MapRadius]; int iterationCount = 0; //prevent an infinite loop while (platforms.Count < ld.PlatformCount) { if (iterationCount >= ld.PlatformCount * 100) { // Debug.Log ("Stopping platform generation at " + platforms.Count); break; } Vector2 randomPoint = new Vector2(Random.Range(0, ld.MapRadius / 2), Random.Range(0, ld.MapRadius)); if (Mathf.PerlinNoise(randomPoint.x / ld.PerlinScale, randomPoint.y / ld.PerlinScale) < ld.PerlinThreshold) { continue; } int platformWidth = Random.Range(5, 40); bool tooClose = false; foreach (PlatformBase pb in platforms) { if (Vector2.Distance(pb.Pivot + Vector2.right * platformWidth / 2f, randomPoint) < ld.MinDistance || Mathf.Abs(randomPoint.y - pb.Pivot.y) < 3) { tooClose = true; break; } } if (!tooClose) { PlatformBase pb = new PlatformBase(randomPoint, platformWidth); #region Temporary Gate spawning stuff List <PlatformObjectData> po = new List <PlatformObjectData> (); //make start gate if (platforms.Count == 0) { PlatformObjectData startGate = ScriptableObject.CreateInstance <PlatformObjectData> (); startGate.position = new Vector2(pb.Pivot.x + Random.Range(1, platformWidth) + 0.5f, pb.Pivot.y + 1.5f); startGate.Object = levelData.PlatformObjects[0].Object; Level.StartGate = startGate; } //make end gate if (platforms.Count == 1) { PlatformObjectData endGate = ScriptableObject.CreateInstance <PlatformObjectData>(); endGate.position = new Vector2(pb.Pivot.x + Random.Range(1, platformWidth) + 0.5f, pb.Pivot.y + 1.5f); endGate.Object = levelData.PlatformObjects[1].Object; Level.EndGate = endGate; } pb.PlatformObjects = po.ToArray(); #endregion platforms.Add(pb); for (int i = 0; i < pb.Width; i++) { levelArray [(int)pb.Pivot.x + i, (int)pb.Pivot.y] = 1; } } iterationCount++; } Level.platforms = GenerateRopes(platforms.ToArray(), levelArray); }