generic doors
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
|
||||
@@ -27,6 +29,9 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
|
||||
[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 ModuleDescription genericModule;
|
||||
public DoorModuleDescription spawnDoor;
|
||||
public List<DoorModuleDescription> exitDoorTypes;
|
||||
|
||||
private int NumberOfRooms => _rooms.Count;
|
||||
|
||||
@@ -45,12 +50,13 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
Logger.Log("Generating room...", LogType.RoomGeneration);
|
||||
|
||||
// get the last entrance from the newest room or create a spawn passage with no entrance door for where the player will start
|
||||
var entrance = NumberOfRooms > 0 ? _rooms[0].exit : new SpawnPassage();
|
||||
var entrance = NumberOfRooms > 0 ? _rooms.Last().exit : new Passage(new DoorModule(null, spawnDoor), true);
|
||||
|
||||
var room = new Room(entrance);
|
||||
_rooms.Add(room);
|
||||
|
||||
GenerateSpace(room, entrance); // TODO: rooms with more than one space
|
||||
|
||||
room.InstantiateRoom(_playSpaceOrigin.transform, (_rooms.Count - 1).ToString());
|
||||
}
|
||||
|
||||
@@ -63,7 +69,7 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
var space = new Space(rrDimensions, entrance);
|
||||
|
||||
// add exit
|
||||
var exitDoor = new DoorModule(DoorType.Exit, space);
|
||||
var exitDoor = new DoorModule(space, exitDoorTypes.RandomElement());
|
||||
exitDoor.Place(new Vector2Int(
|
||||
Random.Range(0, rrDimensions.width),
|
||||
Random.Range(0, rrDimensions.length)
|
||||
@@ -86,7 +92,7 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
Math.Min(entranceRrPosition.x, playSpace.x - minRoomSize.x)
|
||||
);
|
||||
var xMax = Utilities.Utilities.RandomInclusive(
|
||||
Math.Max(entranceRrPosition.x, xMin + minRoomSize.x),
|
||||
Math.Max(entranceRrPosition.x + 1, xMin + minRoomSize.x),
|
||||
playSpace.x
|
||||
);
|
||||
var zMin = Utilities.Utilities.RandomInclusive(
|
||||
@@ -94,13 +100,13 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
Math.Min(entranceRrPosition.y, playSpace.y - minRoomSize.y)
|
||||
);
|
||||
var zMax = Utilities.Utilities.RandomInclusive(
|
||||
Math.Max(entranceRrPosition.y, zMin + minRoomSize.y),
|
||||
Math.Max(entranceRrPosition.y + 1, zMin + minRoomSize.y),
|
||||
playSpace.y
|
||||
);
|
||||
|
||||
var dimensions = new Dimensions(xMax - xMin, zMax - zMin, xMin, zMin);
|
||||
|
||||
Logger.Log($"Generated space dimensions {dimensions}", LogType.RoomGeneration);
|
||||
Logger.Log($"Generated space dimensions {dimensions} from entrance position {entranceRrPosition}", LogType.RoomGeneration);
|
||||
|
||||
return dimensions;
|
||||
}
|
||||
@@ -112,17 +118,5 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
_rooms[NumberOfRooms - 1].roomObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of the oldest room to save resources.
|
||||
/// </summary>
|
||||
public void DisposeOldestRoom()
|
||||
{
|
||||
if (NumberOfRooms > 0)
|
||||
{
|
||||
_rooms[NumberOfRooms - 1].Destroy();
|
||||
_rooms.RemoveAt(NumberOfRooms - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user