protected List <Vector2Int> GetBuffsSpawnPositions(GameMap map, Tileset tileset) { List <Vector2Int> spawnPositions = new List <Vector2Int>(); MapModifier mapModifier = new MapModifier(map); GameData gameData = new AssetProxy(typeof(GameData)).LoadAsset("Objects/Data.asset"); int buffsEntries = 0; for (int x = -map.sizeX / 2; x < map.sizeX / 2; x++) { for (int y = -map.sizeY / 2; y < map.sizeY / 2; y++) { if (tileset.GetIndoorTiles().Contains(mapModifier.GetGroundTile(new Vector3Int(x, y, 0))) && !tileset.GetStructureTiles().Contains(mapModifier.GetStructureTile(new Vector3Int(x, y, 0)))) { //spawn if (Random.value < gameData.GetSpawnRate()) { spawnPositions.Add(new Vector2Int(x, y)); buffsEntries++; } if (buffsEntries >= MAX_BUFFS_ENTRIES) { return(spawnPositions); } } } } Debug.Log("Buffs spawn rate:" + gameData.GetSpawnRate()); return(spawnPositions); }
protected Vector2 GetPlayerSpawnPosition(GameMap map, Tileset tileset) { //creating spawn rect for player Rect spawnArea = new Rect(new Vector2(-map.sizeX / 2, -map.sizeY / 2), new Vector2(map.sizeX, map.sizeY)); spawnArea.xMin += map.sizeX / 10; // map.sizeX / 10 is offsetX spawnArea.yMin += map.sizeY / 10; // map.sizeY / 10 is offsetY spawnArea.width -= map.sizeX / 5; spawnArea.height -= map.sizeY / 5; List <Vector2> spawnCorners = new List <Vector2>() { new Vector2(spawnArea.min.x, spawnArea.min.y), new Vector2(spawnArea.min.x, spawnArea.max.y), new Vector2(spawnArea.max.x, spawnArea.min.y), new Vector2(spawnArea.max.x, spawnArea.max.y) }; MapModifier mapModifier = new MapModifier(map); foreach (var corner in spawnCorners) { if (!tileset.GetStructureTiles().Contains(mapModifier. GetStructureTile(new Vector3Int((int)corner.x, (int)corner.y, 0)))) { Debug.Log(new Vector2((int)corner.x + 0.5f, (int)corner.y + 0.5f)); return(new Vector2((int)corner.x + 0.5f, (int)corner.y + 0.5f)); } } return(Vector2Int.zero); }
public void BuildExit() { AssetProxy pr = new AssetProxy(typeof(GameObject)); GameObject exitTile = Object.Instantiate(pr.LoadAsset("Objects/Tiles/ExitTile.prefab")); Vector2Int settings = StaticTestSettings.getMapSize(); int stX = settings.x; int stY = settings.y; List <Vector3> availabeleExitLocation = new List <Vector3>(); do { for (int i = -stX / 2; i < stX / 2; i++) { for (int j = -stY / 2; j < stY / 2; j++) { if (tiles.GetIndoorTiles().Contains(mapOperations.GetGroundTile(new Vector3Int(i, j, 0))) && !tiles.GetStructureTiles().Contains(mapOperations.GetStructureTile(new Vector3Int(i, j, 0)))) { if (Random.value < 0.1) { availabeleExitLocation.Add(new Vector3(i, j)); } } } } }while (availabeleExitLocation.Count == 0); int exitLocationIndex = Random.Range(0, availabeleExitLocation.Count); Vector3 exitLocation = availabeleExitLocation[exitLocationIndex]; exitTile.transform.Translate(exitLocation); exitTile.transform.Translate(new Vector3(0.5f, 0.5f)); }