refactor: Hex, cell

cell - delete
Hex - refactor, feature
State: stable

В Hex перенесен функционал из cell.
This commit is contained in:
2026-01-16 22:36:32 +03:00
parent 4ffdf964a7
commit e4e834d373
7 changed files with 104 additions and 82 deletions

Binary file not shown.

View File

@@ -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<SpriteRenderer>().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<SpriteRenderer>().color = color;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 62970f09f26042b4c8cf4ca27a04b8f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -62,8 +62,8 @@ public class gridGen : MonoBehaviour
{
GameObject hex = Instantiate(hexPrefab);
hex.transform.Translate(new Vector3(x, y, 0));
hex.GetComponent<cell>().noiseValue = noise.getNoise((float) nowX/this.x, (float) nowY /this.x, Mathf.Max(this.x, this.y));
hex.GetComponent<cell>().Init();
hex.GetComponent<Hex>().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);
}
}

View File

@@ -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<SpriteRenderer>().color = color;
}
}

View File

@@ -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);

Binary file not shown.