generate simple room
This commit is contained in:
49
Assets/Escape Room Engine/Engine/Scripts/Engine.cs
Normal file
49
Assets/Escape Room Engine/Engine/Scripts/Engine.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts
|
||||
{
|
||||
public class Engine : MonoBehaviour
|
||||
{
|
||||
public static Engine DefaultEngine => FindObjectOfType<Engine>();
|
||||
|
||||
public Material roomMaterial;
|
||||
|
||||
public int NumberOfRooms => _rooms.Count;
|
||||
|
||||
private List<Room> _rooms = new(1);
|
||||
|
||||
public void GenerateRoom()
|
||||
{
|
||||
// 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 Passage();
|
||||
|
||||
var room = new Room(entrance);
|
||||
_rooms.Add(room);
|
||||
|
||||
GenerateSpace(room, entrance); // TODO: rooms with more than one space
|
||||
room.InstantiateRoom(transform, (_rooms.Count - 1).ToString());
|
||||
}
|
||||
|
||||
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);
|
||||
room.AddSpace(space, exit);
|
||||
}
|
||||
|
||||
/// <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