9 changed files with 678 additions and 157 deletions
@ -1,10 +1,13 @@
@@ -1,10 +1,13 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://d2rgfedikyr2w"] |
||||
[gd_scene load_steps=4 format=3 uid="uid://d2rgfedikyr2w"] |
||||
|
||||
[ext_resource type="PackedScene" uid="uid://ixy2rotcnjk2" path="res://plant.tscn" id="1_mv10f"] |
||||
[ext_resource type="Script" path="res://Main.cs" id="1_jrcl7"] |
||||
[ext_resource type="PackedScene" path="res://camera_2d.tscn" id="2_pvpm2"] |
||||
[ext_resource type="PackedScene" uid="uid://cvjqldltcr7nl" path="res://plantWorld.tscn" id="2_t7d21"] |
||||
|
||||
[node name="Main" type="Node2D"] |
||||
|
||||
[node name="Plant" parent="." instance=ExtResource("1_mv10f")] |
||||
script = ExtResource("1_jrcl7") |
||||
|
||||
[node name="Camera2D" parent="." instance=ExtResource("2_pvpm2")] |
||||
|
||||
[node name="PlantWorld" parent="." node_paths=PackedStringArray("Camera") instance=ExtResource("2_t7d21")] |
||||
Camera = NodePath("../Camera2D") |
||||
|
||||
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using Godot; |
||||
using LifeComponent; |
||||
|
||||
public class PlantLife |
||||
{ |
||||
private Genetics _genes; |
||||
private BaseLifeComponent _baseLife; |
||||
private Plant _plant_RefUp; |
||||
public PlantParams _plantParams; |
||||
|
||||
public float _size = 1f; |
||||
//public PlantNodeParams RootParams; |
||||
public PlantLife(Plant plantRef) |
||||
{ |
||||
|
||||
_plant_RefUp = plantRef; |
||||
_genes = new Genetics(); |
||||
_baseLife = new BaseLifeComponent(); |
||||
|
||||
} |
||||
|
||||
public void Init() |
||||
{ |
||||
_plantParams = new PlantParams(); |
||||
_plantParams.NodeParams.maxToRootAngleRange = Mathf.DegToRad(270); |
||||
|
||||
GenesToPhenes(); |
||||
//_plantParams.GrowDirection = Vector2.Right; |
||||
_plantParams.NodeParams.MaxToParentAngleRange = Mathf.DegToRad(90); |
||||
_baseLife.Born(); |
||||
} |
||||
|
||||
public void GenesToPhenes() |
||||
{ |
||||
// var c3 = _genes.DNA.Codons[3]; |
||||
var bytes = _genes.DNA.GetBasePairs(3); |
||||
|
||||
var a = bytes[0]; |
||||
_plantParams.AverageChildren = a; |
||||
var b = bytes[1]; |
||||
|
||||
//var c = bytes[2]; |
||||
//_plantParams.MaxChildren = c + 1; |
||||
|
||||
var d = bytes[3]; |
||||
|
||||
if (b == 0) |
||||
_plantParams.GrowDirection = Vector2.Up; |
||||
if (b == 1) |
||||
_plantParams.GrowDirection = Vector2.Left; |
||||
if (b == 2) |
||||
_plantParams.GrowDirection = Vector2.Right; |
||||
if (b == 3) |
||||
_plantParams.GrowDirection = Vector2.Down; |
||||
|
||||
//var v = Mathf.LerpAngle(0.5f, 5.8f, (float)d/4); // 0 - 6.2 |
||||
var v = Mathf.Lerp(0.5f, 5.8f, (float)d/4); |
||||
_plantParams.NodeParams.MaxToParentAngleRange = v; |
||||
|
||||
} |
||||
|
||||
public void Tick(float deltaTime) |
||||
{ |
||||
_baseLife.Tick(deltaTime, _size); |
||||
|
||||
_baseLife.AddEnergy(1 * _size * 0.7f); |
||||
Grow(); |
||||
} |
||||
|
||||
public void Grow() |
||||
{ |
||||
if (_baseLife.Energy > 50) |
||||
{ |
||||
if (_plant_RefUp.CanGrow) |
||||
_plant_RefUp.GrowNewNode(_plantParams); |
||||
|
||||
//GD.Print("Life grew! :) "); |
||||
_baseLife.Energy -= 30; |
||||
_size = _plant_RefUp.Segments.Count; |
||||
|
||||
//_plant_RefUp.AddNewSegment() |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
using System; |
||||
using Godot; |
||||
using LifeComponent; |
||||
|
||||
|
||||
public struct PlantParams |
||||
{ |
||||
public PlantNodeParams NodeParams; |
||||
|
||||
public float maxToRootAngleRange = Mathf.DegToRad(180); |
||||
public Vector2 GrowDirection = Vector2.Up; |
||||
public int RootChildren = 1; |
||||
public int AverageChildren = 2; |
||||
[Phenotype] |
||||
public int MaxChildren = 3; // Hardlimit - should overrule Nodes |
||||
public float SizeDecayOrderFactor = 0.99f; |
||||
|
||||
public float LeaveRatio = 0.1f; |
||||
public float TrunkRatio = 0.5f; |
||||
|
||||
public PlantParams() |
||||
{ |
||||
//RootParams = rootParams; |
||||
NodeParams = PlantNodeParams.Default(); |
||||
NodeParams.MaxChildren = MaxChildren; |
||||
} |
||||
|
||||
public static PlantParams Default() |
||||
{ |
||||
return new PlantParams(); |
||||
} |
||||
public PlantNodeTypes GetRatioNodeType() |
||||
{ |
||||
var r1 = (float)GD.RandRange(0, 10) / 10; |
||||
|
||||
//if (r1 < LeaveRatio) |
||||
// return PlantNodeTypes.Leafes; |
||||
if (r1 > LeaveRatio && r1 < TrunkRatio) |
||||
return PlantNodeTypes.Trunk; |
||||
|
||||
return PlantNodeTypes.Branch; |
||||
} |
||||
|
||||
|
||||
|
||||
} |
||||
|
||||
public struct PlantNodeParams |
||||
{ |
||||
// Angle to grow - calculated from 0°(front) localspace. +/- angle/2 |
||||
[Phenotype] |
||||
public float MinToParentAngleRange = Mathf.DegToRad(12); |
||||
[Phenotype] |
||||
public float MaxToParentAngleRange = Mathf.DegToRad(80); |
||||
|
||||
public float maxToRootAngleRange = Mathf.DegToRad(180); |
||||
public float MinAngleBetweenSibs = Mathf.DegToRad(12); |
||||
//public float MinAngleParentDiv = 0; |
||||
//public float MaxAngleParentDiv = 1f; |
||||
//public float MaxRootDeviationAngle = 3.14f; |
||||
public int MaxChildren = 3; |
||||
public Vector2 Size = Vector2.One; |
||||
public float PreferedRotationToParent = 0f; |
||||
|
||||
public string ConfigName = "default"; |
||||
public PlantNodeTypes NodeType = PlantNodeTypes.Trunk; |
||||
|
||||
public PlantNodeParams() |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
public static PlantNodeParams Default() |
||||
{ |
||||
return new PlantNodeParams(); |
||||
} |
||||
|
||||
public static PlantNodeParams Trunk() |
||||
{ |
||||
var p = new PlantNodeParams(); |
||||
p.MaxChildren = 2; |
||||
p.NodeType = PlantNodeTypes.Trunk; |
||||
p.maxToRootAngleRange = 0.1f; |
||||
|
||||
|
||||
return p; |
||||
} |
||||
|
||||
} |
||||
|
||||
Loading…
Reference in new issue