diff --git a/Assets/GameAssets/Materials/test.mat b/Assets/GameAssets/Materials/nutrientMap.mat similarity index 92% rename from Assets/GameAssets/Materials/test.mat rename to Assets/GameAssets/Materials/nutrientMap.mat index e071ddf..a9f8215 100644 --- a/Assets/GameAssets/Materials/test.mat +++ b/Assets/GameAssets/Materials/nutrientMap.mat @@ -20,20 +20,24 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: test + m_Name: nutrientMap m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 - m_ValidKeywords: [] + m_ValidKeywords: + - _ALPHAPREMULTIPLY_ON + - _SURFACE_TYPE_TRANSPARENT m_InvalidKeywords: [] m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 + m_CustomRenderQueue: 3000 stringTagMap: - RenderType: Opaque + RenderType: Transparent disabledShaderPasses: - MOTIONVECTORS + - DepthOnly + - SHADOWCASTER m_LockedProperties: m_SavedProperties: serializedVersion: 3 @@ -63,7 +67,7 @@ Material: m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MainTex: - m_Texture: {fileID: 2800000, guid: 97c1df594a1bc8447a058044bea5a739, type: 3} + m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _MetallicGlossMap: @@ -108,8 +112,8 @@ Material: - _Cutoff: 0.5 - _DetailAlbedoMapScale: 1 - _DetailNormalMapScale: 1 - - _DstBlend: 0 - - _DstBlendAlpha: 0 + - _DstBlend: 10 + - _DstBlendAlpha: 10 - _EnvironmentReflections: 1 - _GlossMapScale: 0 - _Glossiness: 0 @@ -124,10 +128,10 @@ Material: - _SpecularHighlights: 1 - _SrcBlend: 1 - _SrcBlendAlpha: 1 - - _Surface: 0 + - _Surface: 1 - _WorkflowMode: 1 - _XRMotionVectorsPass: 1 - - _ZWrite: 1 + - _ZWrite: 0 m_Colors: - _BaseColor: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/GameAssets/Materials/test.mat.meta b/Assets/GameAssets/Materials/nutrientMap.mat.meta similarity index 100% rename from Assets/GameAssets/Materials/test.mat.meta rename to Assets/GameAssets/Materials/nutrientMap.mat.meta diff --git a/Assets/GameAssets/Scripts/NutrientController.cs b/Assets/GameAssets/Scripts/NutrientController.cs index 08247d7..e7b3961 100644 --- a/Assets/GameAssets/Scripts/NutrientController.cs +++ b/Assets/GameAssets/Scripts/NutrientController.cs @@ -1,3 +1,4 @@ +using System; using UnityEditor.TextCore.Text; using UnityEngine; using static UnityEngine.GraphicsBuffer; @@ -29,15 +30,43 @@ public class NutrientController : MonoBehaviour } - public float GetNutrients(float x, float y) + public float GetNutrients(float x, float y, float radius) { int locX = Mathf.FloorToInt(x * sizeX); int locY = Mathf.FloorToInt(y * sizeY); - return nutrientMap[locX, locY]; + int ceilRad = Mathf.CeilToInt(radius); + float totalNutrients = 0; + + for(int r = -ceilRad; r < ceilRad; r++) + { + for (int c = -ceilRad; c < ceilRad; c++) + { + if((locX + ceilRad > 0 && locX + ceilRad < sizeX) && (locY + ceilRad > 0 && locY + ceilRad < sizeY)) + { + int fraction = Mathf.Abs(r) + Mathf.Abs(c); + if(fraction == 0) + { + totalNutrients += nutrientMap[locX + ceilRad, locY + ceilRad]; + } + else + { + totalNutrients += nutrientMap[locX + ceilRad, locY + ceilRad] / (fraction * 2); + } + } + } + } + + if(totalNutrients == 0) + { + float thing = nutrientMap[locX, locY]; + Debug.Log("HERE" + thing); + } + + return totalNutrients; } - public void UseNutrients(float x, float y, float used) + public void UseNutrients(float x, float y, float radius, float used) { int locX = Mathf.FloorToInt(x * sizeX); int locY = Mathf.FloorToInt(y * sizeY); @@ -61,26 +90,13 @@ public class NutrientController : MonoBehaviour for (int c = 0; c < sizeY; c++) { float colorValue = nutrientMap[r, c]; - texture.SetPixel(r, c, new Color(colorValue, colorValue, colorValue)); + texture.SetPixel(r, c, new Color(colorValue, colorValue, colorValue, 0.5f)); } } texture.Apply(); meshRenderer.material.mainTexture = texture; - } - - private void ConsoleDump() - { - string toPrint = "\n"; - for (int r = 0; r < sizeX; r++) - { - for (int c = 0; c < sizeY; c++) - { - toPrint += nutrientMap[r, c] + " "; - } - toPrint += "\n"; - } - Debug.Log(toPrint); + meshRenderer.gameObject.SetActive(true); } #if UNITY_EDITOR @@ -95,11 +111,6 @@ public class NutrientController : MonoBehaviour { (target as NutrientController).Render(); } - - if(GUILayout.Button("Dump it")) - { - (target as NutrientController).ConsoleDump(); - } } } #endif diff --git a/Assets/GameAssets/Scripts/Plant.cs b/Assets/GameAssets/Scripts/Plant.cs index d82b618..0e3ab32 100644 --- a/Assets/GameAssets/Scripts/Plant.cs +++ b/Assets/GameAssets/Scripts/Plant.cs @@ -42,9 +42,14 @@ public class Plant : MonoBehaviour float x = transform.position.x / terrain.terrainData.size.x; float y = transform.position.z / terrain.terrainData.size.z; + float size = visual.transform.localScale.x; + + float nutrientsAvailable = nutrientCont.GetNutrients(x, y, size); + + Debug.Log($"Nutrients available {nutrientsAvailable}"); - float nutrientsAvailable = nutrientCont.GetNutrients(x, y); float nutrientsNeededFrame = (nutrientNeed * Time.deltaTime); + if (nutrientsNeededFrame > nutrientsAvailable) { healthCurrent -= Time.deltaTime * 0.1f * healthMax; @@ -52,7 +57,7 @@ public class Plant : MonoBehaviour else { visual.transform.localScale += visual.transform.localScale * (growthRate * Time.deltaTime); - nutrientCont.UseNutrients(x, y, nutrientsNeededFrame); + nutrientCont.UseNutrients(x, y, size, nutrientsNeededFrame); nutrientsConsumed += nutrientsNeededFrame; } diff --git a/Assets/GameAssets/Scripts/PlantController.cs b/Assets/GameAssets/Scripts/PlantController.cs index 7659f01..d09e7cd 100644 --- a/Assets/GameAssets/Scripts/PlantController.cs +++ b/Assets/GameAssets/Scripts/PlantController.cs @@ -18,7 +18,7 @@ public class PlantController : MonoBehaviour xBound = terrain.GetComponent().terrainData.size.x; zBound = terrain.GetComponent().terrainData.size.z; - for (int i = 0; i < 100; i++) + for (int i = 0; i < 1; i++) { GameObject newPlant = Instantiate(plantPrefab); newPlant.GetComponent().SetVisual(plantModels[Random.Range(0, plantModels.Count - 1)]); diff --git a/Assets/TerrainData_f1d78ebe-8a30-4615-87bf-8a9df8d4f7ac.asset b/Assets/TerrainData_f1d78ebe-8a30-4615-87bf-8a9df8d4f7ac.asset new file mode 100644 index 0000000..a09d70f Binary files /dev/null and b/Assets/TerrainData_f1d78ebe-8a30-4615-87bf-8a9df8d4f7ac.asset differ diff --git a/Assets/TerrainData_f1d78ebe-8a30-4615-87bf-8a9df8d4f7ac.asset.meta b/Assets/TerrainData_f1d78ebe-8a30-4615-87bf-8a9df8d4f7ac.asset.meta new file mode 100644 index 0000000..751ce21 --- /dev/null +++ b/Assets/TerrainData_f1d78ebe-8a30-4615-87bf-8a9df8d4f7ac.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a76965b09359b2745aeaf339a493e753 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 15600000 + userData: + assetBundleName: + assetBundleVariant: