cell - delete Hex - refactor, feature State: stable В Hex перенесен функционал из cell.
129 lines
3.3 KiB
C#
129 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
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 { get; private set; } //Ìîäèôèêàòîð ê äîõîäó â åäåíèöó âðåìåíè îò ýòîãî ãåêñà
|
|
public int ownerID;
|
|
public stateTypes state = stateTypes.idle;
|
|
|
|
//TODO ïåðåìåííàÿ äëÿ ïàìàòè ñîäåðæèìîãî
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|