improve room generation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts
|
||||
{
|
||||
@@ -10,9 +10,21 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
|
||||
public Material roomMaterial;
|
||||
|
||||
[Tooltip("The minimum size that should be allowed for rooms.")]
|
||||
public Vector2Int minRoomSize;
|
||||
[Tooltip("The size of the physical play space available to the engine.")] public Vector2Int playSpace;
|
||||
|
||||
public int NumberOfRooms => _rooms.Count;
|
||||
|
||||
private List<Room> _rooms = new(1);
|
||||
private readonly List<Room> _rooms = new(1);
|
||||
private GameObject _playSpaceOrigin;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_playSpaceOrigin = new GameObject("Play Space Origin");
|
||||
_playSpaceOrigin.transform.SetParent(transform);
|
||||
_playSpaceOrigin.transform.localPosition = new Vector3(-playSpace.x / 2f, 0, -playSpace.y / 2f);
|
||||
}
|
||||
|
||||
public void GenerateRoom()
|
||||
{
|
||||
@@ -23,17 +35,25 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
_rooms.Add(room);
|
||||
|
||||
GenerateSpace(room, entrance); // TODO: rooms with more than one space
|
||||
room.InstantiateRoom(transform, (_rooms.Count - 1).ToString());
|
||||
room.InstantiateRoom(_playSpaceOrigin.transform, (_rooms.Count - 1).ToString());
|
||||
}
|
||||
|
||||
void GenerateSpace(Room room, Passage from)
|
||||
private void GenerateSpace(Room room, Passage from)
|
||||
{
|
||||
var exit = new Passage();
|
||||
var size = new SpaceSize(Random.Range(2, 6), Random.Range(2, 6)); // TODO: no hardcoded space size
|
||||
var space = new Space(size, from, exit);
|
||||
var space = new Space(GenerateSpaceDimensions(), from, exit);
|
||||
room.AddSpace(space, exit);
|
||||
}
|
||||
|
||||
private Dimensions GenerateSpaceDimensions()
|
||||
{
|
||||
var xMin = Random.Range(0, playSpace.x - minRoomSize.x + 1);
|
||||
var xMax = Random.Range(xMin + minRoomSize.x, playSpace.x + 1);
|
||||
var yMin = Random.Range(0, playSpace.y - minRoomSize.y + 1);
|
||||
var yMax = Random.Range(yMin + minRoomSize.y, playSpace.y + 1);
|
||||
return new Dimensions(xMax - xMin, yMax - yMin, xMin, yMin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of the oldest room to save resources.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user