Fixed most of the collisions around the monster rooms. It stillhas a pretty good chance of happening.

This commit is contained in:
Max 2025-02-06 16:38:57 +01:00
parent eb7c43a4f1
commit 9ccdba1fdc
2 changed files with 39 additions and 18 deletions

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Unity.VisualScripting;
using UnityEngine;
@ -16,6 +17,7 @@ namespace DungeonGenerator
private List<Room> _normalRooms = new List<Room>();
private Room _bossRoom;
private HashSet<Point> _unoccupiedPoints = new HashSet<Point>();
private HashSet<Point> _occupiedPoints = new HashSet<Point>();
public DungeonMap(int width, int height)
{
@ -45,8 +47,8 @@ namespace DungeonGenerator
default:
return;
}
_unoccupiedPoints.ExceptWith(room.GetPointsInRoom());
AddPointsToOccupied(room.GetPointsInRoom());
}
public void AddRooms(List<Room> rooms)
@ -68,7 +70,7 @@ namespace DungeonGenerator
return;
}
_unoccupiedPoints.ExceptWith(rooms.SelectMany(room => room.GetPointsInRoom()));
AddPointsToOccupied(rooms.SelectMany(room => room.GetPointsInRoom()).ToList());
}
public List<Room> GetMonsterRooms()
@ -95,6 +97,11 @@ namespace DungeonGenerator
{
return new HashSet<Point>(_unoccupiedPoints);
}
public HashSet<Point> GetOccupiedPoints()
{
return new HashSet<Point>(_occupiedPoints);
}
public void PrintMap()
{
@ -146,5 +153,17 @@ namespace DungeonGenerator
$"Monster Rooms: {_monsterRooms.Count}{Environment.NewLine}" +
sb.ToString());
}
private void AddPointsToOccupied(List<Point> points)
{
_occupiedPoints.AddRange(points);
_unoccupiedPoints.ExceptWith(points);
}
private void RemovePointsFromOccupied(List<Point> points)
{
_occupiedPoints.ExceptWith(points);
_unoccupiedPoints.AddRange(points);
}
}
}