diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 0555414..0186a90 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a1dcbfb04709dfd37aefc14d20d3b4403915452d042fd97b4d010bc3f9fcb7d7 -size 245104 +oid sha256:45ce29d7c715ed438e0e5591c8b6514f58a8d4f48992a140314c52ec494d48bb +size 245596 diff --git a/Assets/scripts/cell.cs b/Assets/scripts/cell.cs deleted file mode 100644 index dd938c1..0000000 --- a/Assets/scripts/cell.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - - -public class cell : MonoBehaviour -{ - public Vector2Int pos = new Vector2Int(0, 0); - public float noiseValue; - - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - /* - GetComponent().color = new Color(noiseValue, noiseValue, noiseValue, 1); - noiseValue = Random.Range(0f, 1f); - */ - } - - public void Init() - { - //Debug.Log(noiseValue); - noiseValue = Mathf.Pow(noiseValue, 1.7f); - - float pow = 1.2f; - - Color color; - if (noiseValue <= 0.35) - { - noiseValue = Mathf.Pow(noiseValue, pow); - color = new Color(noiseValue*0.2f, noiseValue * 0.2f, noiseValue + 0.1f);//вода - } - else if (noiseValue <= 0.5) - { - noiseValue = Mathf.Pow(noiseValue, pow); - color = new Color(noiseValue*0.4f, noiseValue+0.3f, noiseValue*0.4f);//низина - } - else if (noiseValue <= 0.8) - { - noiseValue = Mathf.Pow(noiseValue, pow); - color = new Color(noiseValue * 0.2f, noiseValue + 0.3f, noiseValue * 0.2f);//поле - } - else if (noiseValue <= 0.95) - { - noiseValue = Mathf.Pow(noiseValue, pow); - color = new Color(noiseValue*0.8f + 0.1f, noiseValue * 0.4f, noiseValue * 0.2f);//горы - } - else - { - noiseValue = Mathf.Pow(noiseValue, pow); - color = new Color(noiseValue*0.6f + 0.0f, noiseValue * 0.1f, noiseValue * 0.0f);//непроходимый пик - } - GetComponent().color = color; - - } -} - diff --git a/Assets/scripts/cell.cs.meta b/Assets/scripts/cell.cs.meta deleted file mode 100644 index d55a708..0000000 --- a/Assets/scripts/cell.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 62970f09f26042b4c8cf4ca27a04b8f1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/scripts/gridGen.cs b/Assets/scripts/gridGen.cs index 8a7fcff..edd4d04 100644 --- a/Assets/scripts/gridGen.cs +++ b/Assets/scripts/gridGen.cs @@ -62,8 +62,8 @@ public class gridGen : MonoBehaviour { GameObject hex = Instantiate(hexPrefab); hex.transform.Translate(new Vector3(x, y, 0)); - hex.GetComponent().noiseValue = noise.getNoise((float) nowX/this.x, (float) nowY /this.x, Mathf.Max(this.x, this.y)); - hex.GetComponent().Init(); + + hex.GetComponent().InitializeHex(new Vector2Int(this.nowX, this.nowY), noise.getNoise((float)nowX / this.x, (float)nowY / this.x, Mathf.Max(this.x, this.y)), noise.seed); } } diff --git a/Assets/scripts/hex/Hex.cs b/Assets/scripts/hex/Hex.cs index ba9bc62..8786467 100644 --- a/Assets/scripts/hex/Hex.cs +++ b/Assets/scripts/hex/Hex.cs @@ -7,12 +7,14 @@ public class Hex : MonoBehaviour public enum landscapeTypes { water, land, hill, highHill, mountain, uncrosableMountain }; public enum stateTypes { idle, owned, battle }; + + public Vector2Int position; public float noiseValue; public landscapeTypes landType; public int miniMapSeed; - public int income; //Модификатор к доходу в еденицу времени от этого гекса + public int income { get; private set; } //Модификатор к доходу в еденицу времени от этого гекса public int ownerID; public stateTypes state = stateTypes.idle; @@ -29,4 +31,98 @@ public class Hex : MonoBehaviour { } + + public void InitializeHex(Vector2Int pos, float noiseVal, int seed) + { + noiseValue = noiseVal; + position = pos; + //Debug.Log(noiseValue); + noiseValue = Mathf.Pow(noiseValue, 1.7f); //Урезчение переходов ландшафта + + miniMapSeed = seed + position.x * 100000 + position.y; + + + + //Вынести эти велечины в настройки + float waterLevel = 0.34f; + float landLevel = 0.4f; + float hillLevel = 0.6f; + float highHillLevel = 0.75f; + float mountainLevel = 0.95f; + + + //Определение типа ландшафта + if (noiseValue <= waterLevel) + { + landType = landscapeTypes.water; + } + else if (noiseValue <= landLevel) + { + landType = landscapeTypes.land; + } + else if (noiseValue <= hillLevel) + { + landType = landscapeTypes.hill; + } + else if (noiseValue <= highHillLevel) + { + landType = landscapeTypes.highHill; + } + else if (noiseValue <= mountainLevel) + { + landType = landscapeTypes.mountain; + } + else + { + landType = landscapeTypes.uncrosableMountain; + } + + + + InitializeTexture(); + + + + } + + private void InitializeTexture() + { + Color color = new Color(0,0,0,0); + + float pow = 1.2f; //степень в которую возводтится шум для дополнительного урезчения цветов' + + float val = Mathf.Pow(noiseValue, pow); + + switch (landType) + { + case landscapeTypes.water: + color = new Color(noiseValue * 0.2f, noiseValue * 0.2f, noiseValue + 0.1f); + break; + + case landscapeTypes.land: + color = new Color(noiseValue * 0.3f, noiseValue + 0.3f, noiseValue * 0.3f); + break; + + case landscapeTypes.hill: + color = new Color(noiseValue * 0.5f, noiseValue + 0.3f, noiseValue * 0.2f); + break; + + case landscapeTypes.highHill: + color = new Color(noiseValue * 0.7f, noiseValue + 0.3f, noiseValue * 0.2f); + break; + + case landscapeTypes.mountain: + color = new Color(noiseValue * 0.8f + 0.1f, noiseValue * 0.4f, noiseValue * 0.2f); + break; + + case landscapeTypes.uncrosableMountain: + color = new Color(noiseValue * 0.6f + 0.0f, noiseValue * 0.1f, noiseValue * 0.0f); + break; + + } + + GetComponent().color = color; + + } + } diff --git a/Assets/scripts/perlinNoise.cs b/Assets/scripts/perlinNoise.cs index 39df252..c5bd466 100644 --- a/Assets/scripts/perlinNoise.cs +++ b/Assets/scripts/perlinNoise.cs @@ -17,7 +17,7 @@ public class perlinNoise : MonoBehaviour void Start() { - if(seed == -1) { seed = (int) (Random.value * 1000000000); } + if(seed == -1) { seed = (int) (Random.value * int.MaxValue); } Debug.Log(seed); Random.InitState(seed); diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index c138b8b..dc81038 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bcfaf58910486ba48afa619810882e57adf179820c10c6be170fc8b4cc22b102 -size 22959 +oid sha256:a422016c01eae1f9beb90c32554dd7dd7ce6c4d0f6bd29f11a9aa6db2f1a1703 +size 22971