diff --git a/aplib.net-demo/Assets/Scripts/Items/EndItem.cs b/aplib.net-demo/Assets/Scripts/Items/EndItem.cs index 02a14832..5d1c93fe 100644 --- a/aplib.net-demo/Assets/Scripts/Items/EndItem.cs +++ b/aplib.net-demo/Assets/Scripts/Items/EndItem.cs @@ -1,8 +1,15 @@ -using UnityEngine; - namespace Assets.Scripts.Items { public class EndItem : Item { + /// + /// Uses the end item and triggers game over. + /// + public override void UseItem() + { + base.UseItem(); + + GameManager.Instance.TriggerGameOver(); + } } } diff --git a/aplib.net-demo/Assets/Scripts/LevelGeneration/LevelSpawner.cs b/aplib.net-demo/Assets/Scripts/LevelGeneration/LevelSpawner.cs index c4ccb883..2a483cb1 100644 --- a/aplib.net-demo/Assets/Scripts/LevelGeneration/LevelSpawner.cs +++ b/aplib.net-demo/Assets/Scripts/LevelGeneration/LevelSpawner.cs @@ -9,6 +9,7 @@ using WFC; using ConnectedComponent = System.Collections.Generic.ISet; using Grid = WFC.Grid; +using Random = UnityEngine.Random; namespace LevelGeneration { @@ -20,6 +21,14 @@ namespace LevelGeneration [RequireComponent(typeof(SpawningExtensions))] public class LevelSpawner : MonoBehaviour { + private readonly float _maxSaturation = 1f; + + private readonly float _maxValue = 1f; + + private readonly float _minSaturation = 0.5f; + + private readonly float _minValue = 0.3f; + /// /// The height of the offset of where we place the teleporter, with respect to the cell's floor. /// @@ -149,12 +158,28 @@ private void PlaceDoorsBetweenConnectedComponents(Cell startCell) MergeConnectedComponentsJoinedByTeleporterPair(teleporterList, connectedComponents); + ColorConnectedComponent(connectedComponents.Select(t => t.connectedComponent)); + (ConnectedComponent startComponent, ConnectedComponent neighbouringRooms) = FindAndRemoveCellConnectedComponent(startCell, connectedComponents); ProcessNeighbouringRooms(startComponent, neighbouringRooms, connectedComponents, doors); } + /// + /// Colors the connected components. + /// + /// The connected components to color. + private void ColorConnectedComponent(IEnumerable connectedComponents) + { + foreach (ConnectedComponent connectedComponent in connectedComponents) + { + Color componentColor = Random.ColorHSV(0f, 1f, _minSaturation, _maxSaturation, _minValue, _maxValue); + foreach (Cell cell in connectedComponent) + cell.Tile.GameObject.GetComponent().material.color = componentColor; + } + } + /// /// Gets the unique teleporters from a given game object. /// diff --git a/aplib.net-demo/Assets/Scripts/SharedRandom.cs b/aplib.net-demo/Assets/Scripts/SharedRandom.cs index 2228da94..7f37ee42 100644 --- a/aplib.net-demo/Assets/Scripts/SharedRandom.cs +++ b/aplib.net-demo/Assets/Scripts/SharedRandom.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using UnityRandom = UnityEngine.Random; namespace ThreadSafeRandom { @@ -35,6 +36,7 @@ private static void Assign() } _local = new Random(_seed); + UnityRandom.InitState(_seed); } public static int Seed() @@ -57,6 +59,8 @@ public static void SetSeed(int seed) { _local = new Random(seed); } + + UnityRandom.InitState(_seed); } }