готовый генератор комнат

This commit is contained in:
vladislove committed 2026-10-09 01:41:25 +03:00
1 parent 9519be076f
commit 650af515e9
12 files changed
+770 -273

No files matched your search

+35 -13
View File
@@ -3,9 +3,31 @@ using UnityEngine;
namespace _Project.Scripts.LevelGenerating
{
// =====================================================================
// НЕ ЗАБЫТЬ (напоминание себе):
// Все координаты и размеры в Room хранятся в МОДУЛЯХ (1 модуль = 0.5 м), а не в метрах.
// - В инспекторе WallsGenerator размеры задаются в метрах и переводятся в модули (x2).
// - В мировые координаты переводить ТОЛЬКО через LevelGrid.ToWorld(...).
// - Размеры комнат всегда ЧЁТНЫЕ в модулях (целые метры), иначе центровка по коридору
// даст дробные позиции. Это обеспечивает WallsGenerator (метод Even).
// =====================================================================
public static class LevelGrid
{
public const float Module = 0.5f;
public const int PerMeter = 2;
public static int FromMeters(int meters) => meters * PerMeter;
public static Vector3 ToWorld(Vector2Int cell, float y = 0f) =>
new Vector3(cell.x * Module, y, cell.y * Module);
public static Vector3 ToWorld(Vector2 cell, float y = 0f) =>
new Vector3(cell.x * Module, y, cell.y * Module);
}
public class Room
{
public Room(Vector2 position, int width, int length, RoomType rt):this()
public Room(Vector2Int position, int width, int length, RoomType rt) : this()
{
Position = position;
Width = width;
@@ -18,9 +40,8 @@ namespace _Project.Scripts.LevelGenerating
exits = new List<ExitsInRoomType>();
}
public Room(Vector2 position, int width, int length, RoomType rt, EntranceToRoomType entrance):this()
public Room(Vector2Int position, int width, int length, RoomType rt, EntranceToRoomType entrance) : this()
{
Position = position;
Width = width;
Length = length;
@@ -28,14 +49,15 @@ namespace _Project.Scripts.LevelGenerating
this.entrance = entrance;
}
public Room(int width, int length, RoomType rt):this()
public Room(int width, int length, RoomType rt) : this()
{
Width = width;
Length = length;
this.rt = rt;
}
public Room(Vector2 position, int width, int length, RoomType rt, bool isWallable, EntranceToRoomType entrance, List<ExitsInRoomType> exits)
public Room(Vector2Int position, int width, int length, RoomType rt, bool isWallable,
EntranceToRoomType entrance, List<ExitsInRoomType> exits)
{
Position = position;
Width = width;
@@ -46,14 +68,14 @@ namespace _Project.Scripts.LevelGenerating
this.exits = exits;
}
public int Width { get; set; }//width - по оси z
public int Length { get; set; }//length- по оси x
public Vector2 Position;
public int Width { get; set; } // по оси Z, в модулях
public int Length { get; set; } // по оси X, в модулях
public Vector2Int Position; // левый нижний угол, в модулях
public RoomType rt { get; set; }
public EntranceToRoomType entrance { get; set; }
public bool isWallable { get; set; }
public List<ExitsInRoomType> exits { get; set; }
public EntranceToRoomType entrance { get; set; }
public bool isWallable { get; set; } // по факту: комнату ужали об границу карты (стоит переименовать)
public List<ExitsInRoomType> exits { get; set; }
public Vector2 Center => new Vector2(Position.x + Length / 2f, Position.y + Width / 2f);
}
}