Начал делать генерацию комнат после первого коридора, до ии функций.
This commit is contained in:
parent
3a73877096
commit
3a3f1ea763
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using _Project.Scripts.Utilities;
|
using _Project.Scripts.Utilities;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -14,5 +15,10 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
{
|
{
|
||||||
Rooms.Add(room);
|
Rooms.Add(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Room GetLastRoom()
|
||||||
|
{
|
||||||
|
return Rooms.LastOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,10 +35,22 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
this.rt = rt;
|
this.rt = rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Room(Vector2 position, int wigth, int length, RoomType rt, bool isWalling, EntranceToRoomType entrance, List<ExitsInRoomType> exits)
|
||||||
|
{
|
||||||
|
Position = position;
|
||||||
|
Wigth = wigth;
|
||||||
|
Length = length;
|
||||||
|
this.rt = rt;
|
||||||
|
this.isWalling = isWalling;
|
||||||
|
this.entrance = entrance;
|
||||||
|
this.exits = exits;
|
||||||
|
}
|
||||||
|
|
||||||
public int Wigth { get; set; }
|
public int Wigth { get; set; }
|
||||||
public int Length { get; set; }
|
public int Length { get; set; }
|
||||||
public Vector2 Position;
|
public Vector2 Position;
|
||||||
public RoomType rt { get; set; }
|
public RoomType rt { get; set; }
|
||||||
|
public bool isWalling {get; set;} //примыкает ли комната к стене
|
||||||
public EntranceToRoomType entrance { get; set; }
|
public EntranceToRoomType entrance { get; set; }
|
||||||
public List<ExitsInRoomType> exits { get; set; }
|
public List<ExitsInRoomType> exits { get; set; }
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Design.Serialization;
|
using System.ComponentModel.Design.Serialization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -35,30 +36,35 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
LevelManager.Rooms.Add(new Room(Vector2.zero,lengthStartRoom, lengthStartRoom,RoomType.Start));
|
LevelManager.Rooms.Add(new Room(Vector2.zero,lengthStartRoom, lengthStartRoom,RoomType.Start));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Room CreateCorridor(Vector2 posRoom, int Length, int Wigth, ExitsInRoomType exitType)
|
||||||
void CreateCorridor(Vector2 posRoom, int Length, int Wigth, ExitsInRoomType exitType)
|
|
||||||
{
|
{
|
||||||
Vector2 corridorPos = Vector2.zero;
|
Vector2 corridorPos = Vector2.zero;
|
||||||
int cLength = 0;
|
int cLength = 0;
|
||||||
int cWidth = 0;
|
int cWidth = 0;
|
||||||
|
EntranceToRoomType entranceToRoomType = EntranceToRoomType.Null;
|
||||||
|
List<ExitsInRoomType> exitsInRoomType = new List<ExitsInRoomType>();
|
||||||
switch (exitType)
|
switch (exitType)
|
||||||
{
|
{
|
||||||
// Выход направо (+X)
|
// Выход направо (+X)
|
||||||
case ExitsInRoomType.XAxisP:
|
case ExitsInRoomType.XAxisP:
|
||||||
// Начинается у правой стены комнаты (posRoom.x + Length)
|
// Начинается у правой стены комнаты (posRoom.x + Length)
|
||||||
// Центрируем коридор по высоте/оси Z: смещаем на половину разницы ширин
|
// Центрируем коридор по высоте/оси Z: смещаем на половину разницы ширин
|
||||||
|
exitsInRoomType.Add (ExitsInRoomType.XAxisP);
|
||||||
|
entranceToRoomType = EntranceToRoomType.XAxisN;
|
||||||
corridorPos = new Vector2(
|
corridorPos = new Vector2(
|
||||||
posRoom.x + Length,
|
posRoom.x + Length,
|
||||||
posRoom.y + (Wigth - corridorWigth) / 2f
|
posRoom.y + (Wigth - corridorWigth) / 2f
|
||||||
);
|
);
|
||||||
cLength = corridorLength;
|
cLength = corridorLength;
|
||||||
cWidth = corridorWigth;
|
cWidth = corridorWigth;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Выход налево (-X)
|
// Выход налево (-X)
|
||||||
case ExitsInRoomType.XAxisN:
|
case ExitsInRoomType.XAxisN:
|
||||||
// Начинается слева от комнаты, отступая на длину коридора
|
// Начинается слева от комнаты, отступая на длину коридора
|
||||||
|
exitsInRoomType .Add (ExitsInRoomType.XAxisN);
|
||||||
|
entranceToRoomType = EntranceToRoomType.XAxisP;
|
||||||
corridorPos = new Vector2(
|
corridorPos = new Vector2(
|
||||||
posRoom.x - corridorLength,
|
posRoom.x - corridorLength,
|
||||||
posRoom.y + (Wigth - corridorWigth) / 2f
|
posRoom.y + (Wigth - corridorWigth) / 2f
|
||||||
@ -69,6 +75,9 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
|
|
||||||
// Выход вперед/вверх (+Z / в Vector2 это Y)
|
// Выход вперед/вверх (+Z / в Vector2 это Y)
|
||||||
case ExitsInRoomType.ZAxisP:
|
case ExitsInRoomType.ZAxisP:
|
||||||
|
entranceToRoomType = EntranceToRoomType.ZAxisN;
|
||||||
|
|
||||||
|
exitsInRoomType.Add (ExitsInRoomType.ZAxisP);
|
||||||
// Начинается у верхней стены комнаты (posRoom.y + Wigth)
|
// Начинается у верхней стены комнаты (posRoom.y + Wigth)
|
||||||
// Центрируем коридор по горизонтали/оси X:
|
// Центрируем коридор по горизонтали/оси X:
|
||||||
corridorPos = new Vector2(
|
corridorPos = new Vector2(
|
||||||
@ -82,6 +91,9 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
|
|
||||||
// Выход назад/вниз (-Z / в Vector2 это Y)
|
// Выход назад/вниз (-Z / в Vector2 это Y)
|
||||||
case ExitsInRoomType.ZAxisN:
|
case ExitsInRoomType.ZAxisN:
|
||||||
|
entranceToRoomType = EntranceToRoomType.ZAxisP;
|
||||||
|
|
||||||
|
exitsInRoomType.Add (ExitsInRoomType.ZAxisN);
|
||||||
// Начинается ниже комнаты, отступая на длину коридора
|
// Начинается ниже комнаты, отступая на длину коридора
|
||||||
corridorPos = new Vector2(
|
corridorPos = new Vector2(
|
||||||
posRoom.x + (Length - corridorWigth) / 2f,
|
posRoom.x + (Length - corridorWigth) / 2f,
|
||||||
@ -93,11 +105,11 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Создаем коридор как отдельную комнату
|
// Создаем коридор как отдельную комнату
|
||||||
// (Убедись, что в enum RoomType добавлен тип Corridor, либо используй Normal)
|
|
||||||
Room corridor = new Room(cLength, cWidth, RoomType.Corridor);
|
Room corridor = new Room(corridorPos,
|
||||||
// Либо через твой конструктор с позицией:
|
cLength, cWidth, RoomType.Corridor,false,
|
||||||
// Room corridor = new Room(corridorPos, cLength, cWidth, RoomType.Normal);
|
EntranceToRoomType.Null,exitsInRoomType);
|
||||||
|
|
||||||
LevelManager.Rooms.Add(corridor);
|
LevelManager.Rooms.Add(corridor);
|
||||||
|
|
||||||
// Визуализация коридора (расставляем маркеры по углам коридора для наглядности)
|
// Визуализация коридора (расставляем маркеры по углам коридора для наглядности)
|
||||||
@ -105,15 +117,41 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y), Quaternion.identity);
|
Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y), Quaternion.identity);
|
||||||
Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y + cWidth), Quaternion.identity);
|
Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y + cWidth), Quaternion.identity);
|
||||||
Instantiate(GameObjectB, new Vector3(corridorPos.x, 0, corridorPos.y + cWidth), Quaternion.identity);
|
Instantiate(GameObjectB, new Vector3(corridorPos.x, 0, corridorPos.y + cWidth), Quaternion.identity);
|
||||||
|
return corridor;
|
||||||
}
|
}
|
||||||
void CreateRoom()
|
|
||||||
|
void TryPlaceRoom(Room corridor)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Room lastCorridor = LevelManager.Instance.GetLastRoom();
|
||||||
|
if (corridor != null && corridor.exits.Count == 1)
|
||||||
|
{
|
||||||
|
switch (corridor.exits.Last())
|
||||||
|
{
|
||||||
|
case ExitsInRoomType.XAxisP:
|
||||||
|
{
|
||||||
|
if ((lengthFloor - (corridor.Position.x + corridorLength + lengthWallMin) > 0)
|
||||||
|
&& (lengthFloor - (corridor.Position.y + corridorWigth + lengthWallMin) > 0))
|
||||||
|
{
|
||||||
|
Room newRoom = GenerateRandomRoom();
|
||||||
|
if()
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Room GenerateRandomRoom()
|
||||||
{
|
{
|
||||||
int a = Random.Range(lengthWallMin, lengthWallMax);
|
int a = Random.Range(lengthWallMin, lengthWallMax);
|
||||||
int b = Random.Range(lengthWallMin, lengthWallMax);
|
int b = Random.Range(lengthWallMin, lengthWallMax);
|
||||||
Room room = new Room();
|
Room room = new Room();
|
||||||
room.Length = a;
|
room.Length = a;
|
||||||
room.Wigth = b;
|
room.Wigth = b;
|
||||||
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateStartRoom()
|
void CreateStartRoom()
|
||||||
@ -190,7 +228,11 @@ namespace _Project.Scripts.LevelGenerating
|
|||||||
Instantiate(GameObjectB, new Vector3(xR,0,zR+lengthStartRoom), Quaternion.identity);
|
Instantiate(GameObjectB, new Vector3(xR,0,zR+lengthStartRoom), Quaternion.identity);
|
||||||
|
|
||||||
CreateCorridor(new Vector2Int(xR, zR),lengthStartRoom,lengthStartRoom,room.exits.First());
|
CreateCorridor(new Vector2Int(xR, zR),lengthStartRoom,lengthStartRoom,room.exits.First());
|
||||||
|
Room firstCorridor = CreateCorridor(new Vector2(xR, zR), lengthStartRoom, lengthStartRoom, room.exits.First());
|
||||||
|
if (firstCorridor != null)
|
||||||
|
{
|
||||||
|
TryPlaceRoom(firstCorridor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user