From f69bd91a28797df42f32c342a0d0305d08278a93 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Mon, 25 Dec 2023 23:36:15 +0000
Subject: [PATCH] Added border to map

---
 Assets/Scenes/GameplayScene.unity |    8 +++++---
 Assets/Scripts/GenerateTileMap.cs |   31 +++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/Assets/Scenes/GameplayScene.unity b/Assets/Scenes/GameplayScene.unity
index 1303732..647535c 100644
--- a/Assets/Scenes/GameplayScene.unity
+++ b/Assets/Scenes/GameplayScene.unity
@@ -4738,9 +4738,11 @@
   m_Script: {fileID: 11500000, guid: 000b2ca4a3c14d04e8c8a5c1084c700f, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  width: 256
-  height: 256
-  ruleTile: {fileID: 11400000, guid: e77c00aec3ec74f4a9ec15ef63c3f9a7, type: 2}
+  maxWidth: 256
+  maxHeight: 384
+  maxGroundHeight: 256
+  forestRuleTile: {fileID: 11400000, guid: e77c00aec3ec74f4a9ec15ef63c3f9a7, type: 2}
+  borderTile: {fileID: 11400000, guid: dcef846474e534b45ab3b175559c19a2, type: 2}
 --- !u!1 &1990316377
 GameObject:
   m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/GenerateTileMap.cs b/Assets/Scripts/GenerateTileMap.cs
index 6d5d630..136a14d 100644
--- a/Assets/Scripts/GenerateTileMap.cs
+++ b/Assets/Scripts/GenerateTileMap.cs
@@ -8,8 +8,9 @@
 public class GenerateTileMap : MonoBehaviour
 {
     public int? seed;
-    public int width = 256;
-    public int height = 256;
+    public int maxWidth = 256;
+    public int maxHeight = 384;
+    public int maxGroundHeight = 256;
     private float scale;
     private float offsetX;
     private float offsetY;
@@ -59,12 +60,12 @@
 
     public IEnumerator GenerateTiles(Action finishedCallback, List<Vector3Int> destroyedTiles)
     {
-        for (int x = 0; x < width; x++)
+        for (int x = 1; x < maxWidth; x++)
         {
-            for (int y = 0; y < height; y++)
+            for (int y = 1; y < maxGroundHeight; y++)
             {
-                float xPerlin = ((float)x / width) * scale + offsetX;
-                float yPerlin = ((float)y / height) * scale + offsetY;
+                float xPerlin = ((float)x / maxWidth) * scale + offsetX;
+                float yPerlin = ((float)y / maxHeight) * scale + offsetY;
                 float perlinNoise = Mathf.PerlinNoise(xPerlin, yPerlin);
 
                 if (perlinNoise >= 0.3f)
@@ -83,6 +84,24 @@
                 yield return null;
             }
         }
+        for (int x = 0; x <= maxWidth; x += maxWidth)
+        {
+            for (int y = 0; y <= maxHeight; y++)
+            {
+                tilemap.SetTile(new Vector3Int(x, y), borderTile);
+            }
+
+        }
+        yield return null;
+        for (int y = 0; y <= maxHeight; y += maxHeight)
+        {
+            for (int x = 1; x <= maxWidth; x++)
+            {
+                tilemap.SetTile(new Vector3Int(x, y), borderTile);
+            }
+
+        }
+        yield return null;
         finishedCallback();
     }
 }

--
Gitblit v1.9.3