Функция для выбора расположения стартовой комнаты
This commit is contained in:
1 parent
458e0cc98b
commit
236fd9d9f6
10 files changed
+641
-577
No files matched your search
@@ -8,10 +8,11 @@ namespace _Project.Scripts.LevelGenerating
|
||||
[SerializeField] private int floorsCount;
|
||||
[SerializeField] private int lengthWallMin;
|
||||
[SerializeField] private int lengthWallMax;
|
||||
[SerializeField] private int lengthStartRoomA;
|
||||
[SerializeField] private int lengthStartRoomB;
|
||||
[SerializeField] private int lengthFloorMax;
|
||||
[SerializeField] private int lengthFloorMin;
|
||||
[SerializeField] private int lengthStartRoom;
|
||||
[SerializeField] private int lengthFloor;
|
||||
[SerializeField] private GameObject GameObjectA;
|
||||
[SerializeField] private GameObject GameObjectB;
|
||||
|
||||
|
||||
private int RoomCount;
|
||||
private LevelManager levelManager;
|
||||
@@ -19,12 +20,13 @@ namespace _Project.Scripts.LevelGenerating
|
||||
void Start()
|
||||
{
|
||||
levelManager = LevelManager.Instance;
|
||||
CreateStartRoom();
|
||||
}
|
||||
|
||||
void GenerateRooms()
|
||||
{
|
||||
RoomCount = Random.Range(roomCountMin, roomCountMax);
|
||||
LevelManager.Rooms.Add(new Room(Vector2.zero,lengthStartRoomA, lengthStartRoomB,RoomType.Start));
|
||||
LevelManager.Rooms.Add(new Room(Vector2.zero,lengthStartRoom, lengthStartRoom,RoomType.Start));
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +40,83 @@ namespace _Project.Scripts.LevelGenerating
|
||||
room.Length = a;
|
||||
room.Wigth = b;
|
||||
}
|
||||
|
||||
|
||||
void CreateStartRoom()
|
||||
{
|
||||
float randValue = Random.value;
|
||||
int xR, zR;
|
||||
Vector2Int posStartRoom = new Vector2Int();
|
||||
|
||||
Room room = new Room( lengthStartRoom, lengthStartRoom, RoomType.Start);
|
||||
if (randValue < 0.25f) //1 квадрант
|
||||
{
|
||||
xR = Random.Range(0,lengthFloor/2-lengthStartRoom);
|
||||
if (xR + lengthStartRoom <= lengthFloor / 4)
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.XAxisP);
|
||||
zR = Random.Range(0, lengthFloor/2-lengthStartRoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.ZAxisP);
|
||||
zR = Random.Range(0, lengthFloor/4-lengthStartRoom);
|
||||
}
|
||||
}
|
||||
else if (randValue < 0.5f) // 2 квадрант
|
||||
{
|
||||
xR = Random.Range(lengthFloor/2, lengthFloor-lengthStartRoom);//от половины до конца
|
||||
if (xR + lengthStartRoom <= lengthFloor * 3/4)
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.ZAxisP);
|
||||
zR = Random.Range(0, lengthFloor/4-lengthStartRoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.XAxisN);
|
||||
zR = Random.Range(0, lengthFloor/2-lengthStartRoom);
|
||||
}
|
||||
}
|
||||
else if (randValue < 0.75f)
|
||||
{
|
||||
xR = Random.Range(lengthFloor / 2, lengthFloor - lengthStartRoom);
|
||||
if (xR + lengthStartRoom <= lengthFloor * 3 / 4)
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.ZAxisN);
|
||||
zR = Random.Range(lengthFloor * 3 / 4, lengthFloor - lengthStartRoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.XAxisN);
|
||||
zR = Random.Range(lengthFloor / 2, lengthFloor - lengthStartRoom);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xR = Random.Range(0, lengthFloor / 2 - lengthStartRoom);
|
||||
if (xR + lengthStartRoom <= lengthFloor / 4)
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.XAxisP);
|
||||
zR = Random.Range(lengthFloor / 2, lengthFloor - lengthStartRoom);
|
||||
}
|
||||
else
|
||||
{
|
||||
room.exits.Add(ExitsInRoomType.ZAxisN);
|
||||
zR = Random.Range(lengthFloor * 3 / 4, lengthFloor - lengthStartRoom);
|
||||
}
|
||||
}
|
||||
|
||||
room.entrance = EntranceToRoomType.Null;
|
||||
LevelManager.Rooms.Add(room);
|
||||
Instantiate(GameObjectA, new Vector3(0,-1,0), Quaternion.identity);
|
||||
|
||||
Instantiate(GameObjectB, new Vector3(xR,0,zR), Quaternion.identity);
|
||||
Instantiate(GameObjectB, new Vector3(xR+lengthStartRoom,0,zR), Quaternion.identity);
|
||||
Instantiate(GameObjectB, new Vector3(xR+lengthStartRoom,0,zR+lengthStartRoom), Quaternion.identity);
|
||||
Instantiate(GameObjectB, new Vector3(xR,0,zR+lengthStartRoom), Quaternion.identity);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user