Make tile positions relative
This commit is contained in:
parent
8ebeb2b982
commit
b034e23fd6
2 changed files with 29 additions and 7 deletions
|
@ -150,8 +150,21 @@ public class DungeonGenerator {
|
||||||
|
|
||||||
rooms.Remove(start);
|
rooms.Remove(start);
|
||||||
rooms.Remove(end);
|
rooms.Remove(end);
|
||||||
|
|
||||||
|
foreach (GenRoom r in rooms)
|
||||||
|
makeRoomRelative(r);
|
||||||
|
makeRoomRelative(start);
|
||||||
|
makeRoomRelative(end);
|
||||||
|
makeRoomRelative(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void makeRoomRelative(GenRoom room) {
|
||||||
|
room.roomPosition = room.bounds.position;
|
||||||
|
foreach (Vector2Int v in room.tiles.Keys) {
|
||||||
|
v.Set((v - room.roomPosition).x, (v-room.roomPosition).y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void AddStraightHorizontal(HashSet<GenRoom> rooms, GenEdge ed) {
|
public static void AddStraightHorizontal(HashSet<GenRoom> rooms, GenEdge ed) {
|
||||||
GenRoom righter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r1.r : ed.r2.r;
|
GenRoom righter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r1.r : ed.r2.r;
|
||||||
GenRoom lefter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r2.r : ed.r1.r;
|
GenRoom lefter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r2.r : ed.r1.r;
|
||||||
|
|
|
@ -3,19 +3,28 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class GenRoom {
|
public class GenRoom {
|
||||||
public RectInt bounds = new RectInt();
|
// ---Internal for generation only---
|
||||||
public Dictionary<Vector2Int, Room.TileType> tiles = new Dictionary<Vector2Int, Room.TileType>();
|
// TODO make them package protcted please
|
||||||
public HashSet<Vector2Int> doorsUp = new HashSet<Vector2Int>();
|
|
||||||
public HashSet<Vector2Int> doorsDown = new HashSet<Vector2Int>();
|
public RectInt bounds = new RectInt();
|
||||||
public HashSet<Vector2Int> doorsLeft = new HashSet<Vector2Int>();
|
public HashSet<Vector2Int> doorsUp = new HashSet<Vector2Int>();
|
||||||
public HashSet<Vector2Int> doorsRight = new HashSet<Vector2Int>();
|
public HashSet<Vector2Int> doorsDown = new HashSet<Vector2Int>();
|
||||||
|
public HashSet<Vector2Int> doorsLeft = new HashSet<Vector2Int>();
|
||||||
|
public HashSet<Vector2Int> doorsRight = new HashSet<Vector2Int>();
|
||||||
|
|
||||||
|
// --- The final room genration result ---
|
||||||
|
|
||||||
|
// The position of the anchor of the room in world space. This should be the top left corner of the room, but may be any point in the world.
|
||||||
|
public Vector2Int roomPosition;
|
||||||
|
// All positions are in room space relative to the room's anchor
|
||||||
|
public Dictionary<Vector2Int, Room.TileType> tiles = new Dictionary<Vector2Int, Room.TileType>();
|
||||||
|
|
||||||
public float Distance(GenRoom r) {
|
public float Distance(GenRoom r) {
|
||||||
return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);
|
return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2Int GetCenter() {
|
public Vector2Int GetCenter() {
|
||||||
return new Vector2Int(( int ) bounds.center.x, ( int ) bounds.center.y);
|
return new Vector2Int(( int ) bounds.center.x, ( int ) bounds.center.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<Vector2Int> AllDoors() {
|
public HashSet<Vector2Int> AllDoors() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue