From 955a1cd4b246ce26c8c71a307caad725a1d7554d Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Sat, 1 Jan 2022 15:04:43 -0600 Subject: [PATCH] Add map generator margin --- src/rooms.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rooms.rs b/src/rooms.rs index d9c8cc9..50938e6 100644 --- a/src/rooms.rs +++ b/src/rooms.rs @@ -33,6 +33,11 @@ const ROOM_SIZE_LIMITS: Range = 4..8; /// at least 1 to ensure that walls generate. const ROOM_MIN_DISTANCE: usize = 4; +/// The minimum distance between the interior of a room and the edge +/// of the map. Should be at least 1 to ensure that all rooms have +/// walls. +const ROOM_MARGIN: usize = 2; + /// Factor to encourage routes to travel through existing rooms rather /// than cutting new hallways. 0.0 very strongly encourages traveling /// through rooms, 1.0 is indifferent to the existence of rooms, and @@ -143,8 +148,8 @@ impl RoomBounds { rng.gen_range(ROOM_SIZE_LIMITS), ); let ul_corner = ( - rng.gen_range(0..region_size.0 - size.0), - rng.gen_range(0..region_size.1 - size.1), + rng.gen_range(ROOM_MARGIN..region_size.0 - size.0 - ROOM_MARGIN), + rng.gen_range(ROOM_MARGIN..region_size.1 - size.1 - ROOM_MARGIN), ); let new_room = Self { ul_corner, size };