Skip to content

Commit

Permalink
Merge branch 'main' into test/complex-aplib-test
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Jun 23, 2024
2 parents 2a43109 + 94f3940 commit f97b89a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
11 changes: 9 additions & 2 deletions aplib.net-demo/Assets/Scripts/Items/EndItem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using UnityEngine;

namespace Assets.Scripts.Items
{
public class EndItem : Item
{
/// <summary>
/// Uses the end item and triggers game over.
/// </summary>
public override void UseItem()
{
base.UseItem();

GameManager.Instance.TriggerGameOver();
}
}
}
25 changes: 25 additions & 0 deletions aplib.net-demo/Assets/Scripts/LevelGeneration/LevelSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using WFC;
using ConnectedComponent = System.Collections.Generic.ISet<WFC.Cell>;
using Grid = WFC.Grid;
using Random = UnityEngine.Random;

namespace LevelGeneration
{
Expand All @@ -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;

/// <summary>
/// The height of the offset of where we place the teleporter, with respect to the cell's floor.
/// </summary>
Expand Down Expand Up @@ -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);
}

/// <summary>
/// Colors the connected components.
/// </summary>
/// <param name="connectedComponents">The connected components to color.</param>
private void ColorConnectedComponent(IEnumerable<ConnectedComponent> 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<Renderer>().material.color = componentColor;
}
}

/// <summary>
/// Gets the unique teleporters from a given game object.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions aplib.net-demo/Assets/Scripts/SharedRandom.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using UnityRandom = UnityEngine.Random;

namespace ThreadSafeRandom
{
Expand Down Expand Up @@ -35,6 +36,7 @@ private static void Assign()
}

_local = new Random(_seed);
UnityRandom.InitState(_seed);
}

public static int Seed()
Expand All @@ -57,6 +59,8 @@ public static void SetSeed(int seed)
{
_local = new Random(seed);
}

UnityRandom.InitState(_seed);
}
}

Expand Down

0 comments on commit f97b89a

Please sign in to comment.