private void tracePathBetweenCoordinates(LevelGenMap.Coordinate coord1, LevelGenMap.Coordinate coord2) { int modifier = 1; List <LevelGenMap.Coordinate> corridor = new List <LevelGenMap.Coordinate>(); if (coord1.x != coord2.x) { int startX = coord1.x < coord2.x ? coord1.x + modifier : coord2.x + modifier; int endX = coord1.x < coord2.x ? coord2.x : coord1.x; for (int x = startX; x < endX; ++x) { fillCorridorTile(x, coord2.y, corridor); } modifier = 0; } if (coord1.y != coord2.y) { int startY = coord1.y < coord2.y ? coord1.y + modifier : coord2.y + modifier; int endY = coord1.y < coord2.y ? coord2.y + (1 - modifier) : coord1.y + (1 - modifier); for (int y = startY; y < endY; ++y) { fillCorridorTile(coord1.x, y, corridor); } } _corridorTiles.Add(corridor); }
private void spawnSimple(int enemiesSpawned, LevelGenOutput output, int[] guaranteedEnemiesPlaced, EnemySelector enemySelector, int difficulty, List <LevelGenMap.Coordinate> openTiles, bool spawnPlayers) { // Guaranteed enemies for (int i = 0; i < output.Input.GuaranteedEnemiesByDifficulty.Length; ++i) { while (guaranteedEnemiesPlaced[i] < output.Input.GuaranteedEnemiesByDifficulty[i]) { int enemyId = enemySelector.ChooseEnemyOfDifficulty(i); guaranteedEnemiesPlaced[i] = guaranteedEnemiesPlaced[i] + 1; ++enemiesSpawned; _enemySpawns.Add(new EnemySpawnGroup(findGoodOpenPosition(openTiles, output.Input.MinDistanceBetweenSpawns).integerVector, enemyId)); } } // Remaining enemies for (; enemiesSpawned < this.NumEnemies; ++enemiesSpawned) { int enemyId = enemySelector.ChooseEnemy(difficulty); _enemySpawns.Add(new EnemySpawnGroup(findGoodOpenPosition(openTiles, output.Input.MinDistanceBetweenSpawns).integerVector, enemyId)); } // Players if (spawnPlayers) { bool first = true; List <LevelGenMap.Coordinate> tiles = openTiles; for (int i = 0; i < DynamicData.MAX_PLAYERS; ++i) { if (DynamicData.GetSessionPlayer(i).HasJoined) { LevelGenMap.Coordinate playerSpawn = findGoodOpenPosition(tiles, 0); _playerSpawns.Add(playerSpawn.integerVector); if (first) { first = false; List <LevelGenMap.Coordinate> nearbySpawns = new List <LevelGenMap.Coordinate>(); foreach (LevelGenMap.Coordinate coord in openTiles) { if (Mathf.Abs(coord.x - playerSpawn.x) + Mathf.Abs(coord.y - playerSpawn.y) <= this.MaxPlayerSpawnDistance) { nearbySpawns.Add(coord); } } if (nearbySpawns.Count >= DynamicData.MAX_PLAYERS) { tiles = nearbySpawns; } } else { openTiles.Remove(playerSpawn); } } } } }
private bool isPositionFreeInArea(LevelGenMap.Coordinate position, int minDistance) { foreach (EnemySpawnGroup enemySpawn in _enemySpawns) { if (Vector2.Distance(position.integerVector, enemySpawn.Origin) < minDistance) { return(false); } } return(true); }
public void FillCavesPhase(int frames) { List <LevelGenMap.Coordinate> coords = this.Map.ListOfCoordinatesOfType(this.Bounds, CAVE_TYPE); List <List <LevelGenMap.Coordinate> > caves = new List <List <LevelGenMap.Coordinate> >(); // Gather all the caves while (coords.Count > 0) { LevelGenMap.Coordinate coord = coords[coords.Count - 1]; coords.RemoveAt(coords.Count - 1); List <LevelGenMap.Coordinate> cave = this.Map.FloodFill(coord, CAVE_TYPE); foreach (LevelGenMap.Coordinate caveCoord in cave) { coords.Remove(caveCoord); } caves.Add(cave); } // If there are too many caves, only keep the largest ones if (caves.Count > this.MaxCaves) { caves.Sort( delegate(List <LevelGenMap.Coordinate> cave1, List <LevelGenMap.Coordinate> cave2) { if (cave1.Count > cave2.Count) { return(-1); } if (cave1.Count < cave2.Count) { return(1); } return(0); }); for (int i = this.MaxCaves; i < caves.Count; ++i) { foreach (LevelGenMap.Coordinate caveCoord in caves[i]) { this.Map.Grid[caveCoord.x, caveCoord.y] = BASE_TYPE; } } caves.RemoveRange(this.MaxCaves, caves.Count - this.MaxCaves); } _caves = caves; this.NextPhase(); }