miepzerino
2023-12-25 f69bd91a28797df42f32c342a0d0305d08278a93
Added border to map
2 files modified
39 ■■■■ changed files
Assets/Scenes/GameplayScene.unity 8 ●●●●● patch | view | raw | blame | history
Assets/Scripts/GenerateTileMap.cs 31 ●●●● patch | view | raw | blame | history
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
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();
    }
}