void Start() { // プレイヤーキャラ配置 var playerCharacterSpawnCoordinate = new Main_MapGenerator.Coordinate(1, 1); playerCharacter.transform.position = CoordinateToPosition(playerCharacterSpawnCoordinate); // マップ情報生成 var mapGenerator = new Main_MapGenerator(); var map = mapGenerator.Generate(13, 13, new Main_MapGenerator.Coordinate[] { playerCharacterSpawnCoordinate }); // マップ情報を元にマップ組み立て foreach (var cell in map) { var position = CoordinateToPosition(cell.coordinate); Instantiate(floorPrefab, position, Quaternion.identity); switch (cell.type) { case Main_MapGenerator.Cell.Types.StaticWall: var staticWall = Instantiate(staticWallPrefab, position, Quaternion.identity); staticWalls.Add(cell.coordinate, staticWall); break; case Main_MapGenerator.Cell.Types.Wall: var wall = Instantiate(wallPrefab, position, Quaternion.identity); walls.Add(cell.coordinate, wall); break; } } }
void Start() { // マップ情報生成 var mapGenerator = new Main_MapGenerator(); var roomSettings = new Main_MapGenerator.RoomSettings(); roomSettings.minWidth = 2; roomSettings.minHeight = 2; roomSettings.bigRoomRate = 1; roomSettings.maxWallThicknessInArea = 2; var width = Random.Range(20, 20 + gameLevel); var height = Random.Range(20, 20 + gameLevel); var map = mapGenerator.Generate(width, height, roomSettings); // プレイヤーキャラ配置 var emptyFloors = map.Where(x => x.type == Main_MapGenerator.Cell.Types.Floor).ToList(); var playerCell = emptyFloors[UnityEngine.Random.Range(0, emptyFloors.Count)]; playerCharacter.transform.position = CoordinateToPosition(playerCell.coordinate); emptyFloors.Remove(playerCell); // プレイヤー周囲のマスは何も置かない emptyFloors.RemoveAll(x => Mathf.Sqrt(Mathf.Pow(x.coordinate.x - playerCell.coordinate.x, 2f) + Mathf.Pow(x.coordinate.y - playerCell.coordinate.y, 2f)) < 5f); // マップ情報を元にマップ組み立て foreach (var cell in map) { var position = CoordinateToPosition(cell.coordinate); Instantiate(floorPrefab, position, Quaternion.identity); switch (cell.type) { case Main_MapGenerator.Cell.Types.StaticWall: var staticWall = Instantiate(staticWallPrefab, position, Quaternion.identity); staticWalls.Add(cell.coordinate, staticWall); break; case Main_MapGenerator.Cell.Types.Wall: var wall = Instantiate(wallPrefab, position, Quaternion.identity); walls.Add(cell.coordinate, wall); break; } } // 階段を配置 var stairsCell = emptyFloors[UnityEngine.Random.Range(0, emptyFloors.Count)]; stairs.transform.position = CoordinateToPosition(stairsCell.coordinate); emptyFloors.Remove(stairsCell); // 敵を配置 for (var i = 0; i < 5 + gameLevel / 2; i++) { var enemyCell = emptyFloors[UnityEngine.Random.Range(0, emptyFloors.Count)]; var enemy = Instantiate(enemySimplePrefab, CoordinateToPosition(enemyCell.coordinate), Quaternion.identity); enemy.Initialize(Random.Range(0.3f, 1f + (float)gameLevel / 10f)); emptyFloors.Remove(enemyCell); } for (var i = 0; i < gameLevel / 3; i++) { var enemyCell = emptyFloors[UnityEngine.Random.Range(0, emptyFloors.Count)]; var enemy = Instantiate(enemyHomingPrefab, CoordinateToPosition(enemyCell.coordinate), Quaternion.identity); enemy.Initialize(Random.Range(0.5f, 1f + (float)gameLevel / 10f)); emptyFloors.Remove(enemyCell); } for (var i = 0; i < gameLevel / 6; i++) { var enemyCell = emptyFloors[UnityEngine.Random.Range(0, emptyFloors.Count)]; var enemy = Instantiate(enemyIgnoreWallPrefab, CoordinateToPosition(enemyCell.coordinate), Quaternion.identity); enemy.Initialize(Random.Range(0.2f, 0.5f + (float)gameLevel / 30f)); emptyFloors.Remove(enemyCell); } gameLevelText.text = "Lv." + gameLevel; StartCoroutine(ReadyCoroutine()); }