From b034e23fd6bd1b9c31e4a88e88fdb2cc37053555 Mon Sep 17 00:00:00 2001 From: Piegames <14054505+piegamesde@users.noreply.github.com> Date: Sun, 22 Apr 2018 16:46:49 +0200 Subject: [PATCH] Make tile positions relative --- Assets/Scripts/Generation/DungeonGenerator.cs | 13 +++++++++++ Assets/Scripts/Generation/GenRoom.cs | 23 +++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Generation/DungeonGenerator.cs b/Assets/Scripts/Generation/DungeonGenerator.cs index c65e132..f91eebf 100644 --- a/Assets/Scripts/Generation/DungeonGenerator.cs +++ b/Assets/Scripts/Generation/DungeonGenerator.cs @@ -150,8 +150,21 @@ public class DungeonGenerator { rooms.Remove(start); 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 rooms, GenEdge ed) { 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; diff --git a/Assets/Scripts/Generation/GenRoom.cs b/Assets/Scripts/Generation/GenRoom.cs index 416cf43..ed24240 100644 --- a/Assets/Scripts/Generation/GenRoom.cs +++ b/Assets/Scripts/Generation/GenRoom.cs @@ -3,19 +3,28 @@ using System.Collections.Generic; using UnityEngine; public class GenRoom { - public RectInt bounds = new RectInt(); - public Dictionary tiles = new Dictionary(); - public HashSet doorsUp = new HashSet(); - public HashSet doorsDown = new HashSet(); - public HashSet doorsLeft = new HashSet(); - public HashSet doorsRight = new HashSet(); + // ---Internal for generation only--- + // TODO make them package protcted please + + public RectInt bounds = new RectInt(); + public HashSet doorsUp = new HashSet(); + public HashSet doorsDown = new HashSet(); + public HashSet doorsLeft = new HashSet(); + public HashSet doorsRight = new HashSet(); + + // --- 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 tiles = new Dictionary(); public float Distance(GenRoom r) { return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y); } 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 AllDoors() {