Added trees
parent
b672d4556a
commit
9896d0896a
|
@ -0,0 +1,18 @@
|
||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://assets/KenneySurvivalKit/Models/tree.glb" type="PackedScene" id=1]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape" id=1]
|
||||||
|
radius = 0.329139
|
||||||
|
height = 0.936801
|
||||||
|
|
||||||
|
[node name="tree" instance=ExtResource( 1 )]
|
||||||
|
|
||||||
|
[node name="tree" parent="." index="0"]
|
||||||
|
transform = Transform( 1.5, 0, 0, 0, 1, 0, 0, 0, 1.5, 0, 0, 0 )
|
||||||
|
|
||||||
|
[node name="StaticBody" type="StaticBody" parent="." index="1"]
|
||||||
|
|
||||||
|
[node name="CollisionShape" type="CollisionShape" parent="StaticBody" index="0"]
|
||||||
|
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.519998, 0 )
|
||||||
|
shape = SubResource( 1 )
|
|
@ -266,7 +266,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
|
||||||
shape = SubResource( 9 )
|
shape = SubResource( 9 )
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="."]
|
[node name="Camera" type="Camera" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 0.60042, 0.799685, 0, -0.799685, 0.60042, -4.76837e-07, 8.3759, 5.70105 )
|
transform = Transform( 1, 0, 0, 0, 0.60042, 0.799685, 0, -0.799685, 0.60042, -4.76837e-07, 6.37557, 4.57224 )
|
||||||
current = true
|
current = true
|
||||||
fov = 60.0
|
fov = 60.0
|
||||||
script = ExtResource( 10 )
|
script = ExtResource( 10 )
|
||||||
|
|
|
@ -18,8 +18,8 @@ public class TileWorld : Spatial
|
||||||
}
|
}
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
private static readonly Color RockColor = new Color (0.5f, 0.5f, 0.4f, 1f);
|
private static readonly Color RockColor = new Color(0.5f, 0.5f, 0.4f, 1f);
|
||||||
private static readonly Color GrassColor = new Color (0, 0.4f, 0, 1f);
|
private static readonly Color GrassColor = new Color(0, 0.4f, 0, 1f);
|
||||||
|
|
||||||
private GenerationState _currentGenerationState = GenerationState.Heightmap;
|
private GenerationState _currentGenerationState = GenerationState.Heightmap;
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ public class TileWorld : Spatial
|
||||||
private TextureRect _heightmapOffscreenTextureRect;
|
private TextureRect _heightmapOffscreenTextureRect;
|
||||||
private Array<Spatial> _rockAssets = new Array<Spatial>();
|
private Array<Spatial> _rockAssets = new Array<Spatial>();
|
||||||
private Array<Spatial> _grassAssets = new Array<Spatial>();
|
private Array<Spatial> _grassAssets = new Array<Spatial>();
|
||||||
|
private Array<Spatial> _treeAssets = new Array<Spatial>();
|
||||||
private Spatial _environmentNode;
|
private Spatial _environmentNode;
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
|
@ -77,6 +78,10 @@ public class TileWorld : Spatial
|
||||||
_grassAssets.Add(asset);
|
_grassAssets.Add(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Spatial asset in GetNode<Node>("Assets/Trees").GetChildren())
|
||||||
|
{
|
||||||
|
_treeAssets.Add(asset);
|
||||||
|
}
|
||||||
|
|
||||||
_environmentNode = GetNode<Spatial>("Environment");
|
_environmentNode = GetNode<Spatial>("Environment");
|
||||||
|
|
||||||
|
@ -114,12 +119,14 @@ public class TileWorld : Spatial
|
||||||
{
|
{
|
||||||
foreach (int coord_y in Enumerable.Range(0, Size))
|
foreach (int coord_y in Enumerable.Range(0, Size))
|
||||||
{
|
{
|
||||||
Colormap.SetPixel(coord_x, coord_y, new Color((float) Mathf.Min(coord_x, coord_y) / Size, (float) 0, 0, 1));
|
Colormap.SetPixel(coord_x, coord_y,
|
||||||
Heightmap.SetPixel(coord_x, coord_y, new Color((float) Mathf.Min(coord_x, coord_y) / Size, (float) 0, 0, 1));
|
new Color((float)Mathf.Min(coord_x, coord_y) / Size, (float)0, 0, 1));
|
||||||
|
Heightmap.SetPixel(coord_x, coord_y,
|
||||||
|
new Color((float)Mathf.Min(coord_x, coord_y) / Size, (float)0, 0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Colormap.SetPixel(Size - 1, Size -1, new Color(1, 1, 1, 1));
|
Colormap.SetPixel(Size - 1, Size - 1, new Color(1, 1, 1, 1));
|
||||||
Colormap.Unlock();
|
Colormap.Unlock();
|
||||||
|
|
||||||
OnMapGenerationComplete();
|
OnMapGenerationComplete();
|
||||||
|
@ -140,7 +147,7 @@ public class TileWorld : Spatial
|
||||||
noiseGenerator.Lacunarity = 4;
|
noiseGenerator.Lacunarity = 4;
|
||||||
|
|
||||||
ImageTexture heightmapTexture = new ImageTexture();
|
ImageTexture heightmapTexture = new ImageTexture();
|
||||||
heightmapTexture.CreateFromImage(noiseGenerator.GetSeamlessImage((int) Size));
|
heightmapTexture.CreateFromImage(noiseGenerator.GetSeamlessImage((int)Size));
|
||||||
heightmapTexture.Flags = 0;
|
heightmapTexture.Flags = 0;
|
||||||
_heightmapOffscreenTextureRect.Texture = heightmapTexture;
|
_heightmapOffscreenTextureRect.Texture = heightmapTexture;
|
||||||
Heightmap.CopyFrom(_heightmapOffscreenViewport.GetTexture().GetData());
|
Heightmap.CopyFrom(_heightmapOffscreenViewport.GetTexture().GetData());
|
||||||
|
@ -176,11 +183,12 @@ public class TileWorld : Spatial
|
||||||
}
|
}
|
||||||
|
|
||||||
int assetIndex = randomGenerator.Next(assets.Count);
|
int assetIndex = randomGenerator.Next(assets.Count);
|
||||||
Spatial assetInstance = (Spatial) assets[assetIndex].Duplicate();
|
Spatial assetInstance = (Spatial)assets[assetIndex].Duplicate();
|
||||||
Transform assetTransform = Transform.Identity;
|
Transform assetTransform = Transform.Identity;
|
||||||
assetTransform.origin = GetTileWorldCenterFromOffset(offsetCoord);
|
assetTransform.origin = GetTileWorldCenterFromOffset(offsetCoord);
|
||||||
assetTransform.origin.y += 1.2f;
|
assetTransform.origin.y += 1.2f;
|
||||||
assetTransform.basis = assetTransform.basis.Rotated(Vector3.Up, (float)(randomGenerator.NextDouble() * Mathf.Pi * 2));
|
assetTransform.basis =
|
||||||
|
assetTransform.basis.Rotated(Vector3.Up, (float)(randomGenerator.NextDouble() * Mathf.Pi * 2));
|
||||||
assetInstance.Transform = assetTransform;
|
assetInstance.Transform = assetTransform;
|
||||||
|
|
||||||
return assetInstance;
|
return assetInstance;
|
||||||
|
@ -211,16 +219,24 @@ public class TileWorld : Spatial
|
||||||
{
|
{
|
||||||
_environmentNode.AddChild(rockAsset);
|
_environmentNode.AddChild(rockAsset);
|
||||||
}
|
}
|
||||||
} else if (IsColorEqualApprox(colorValue, GrassColor))
|
}
|
||||||
|
else if (IsColorEqualApprox(colorValue, GrassColor))
|
||||||
{
|
{
|
||||||
Spatial grassAsset = SelectAsset(offsetCoord, _grassAssets, environmentRandom, 0.35);
|
Spatial grassAsset = SelectAsset(offsetCoord, _grassAssets, environmentRandom, 0.35);
|
||||||
if (grassAsset != null)
|
if (grassAsset != null)
|
||||||
{
|
{
|
||||||
_environmentNode.AddChild(grassAsset);
|
_environmentNode.AddChild(grassAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spatial treeAsset = SelectAsset(offsetCoord, _treeAssets, environmentRandom, 0.10);
|
||||||
|
if (treeAsset != null)
|
||||||
|
{
|
||||||
|
_environmentNode.AddChild(treeAsset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Colormap.Unlock();
|
Colormap.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +264,6 @@ public class TileWorld : Spatial
|
||||||
|
|
||||||
OnMapGenerationComplete();
|
OnMapGenerationComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsOffsetCoordValid(Vector2 offsetCoord)
|
public bool IsOffsetCoordValid(Vector2 offsetCoord)
|
||||||
|
@ -321,6 +336,6 @@ public class TileWorld : Spatial
|
||||||
return new Vector3(
|
return new Vector3(
|
||||||
tileCenter.x - Mathf.Round(Size * 0.75f * 0.5f),
|
tileCenter.x - Mathf.Round(Size * 0.75f * 0.5f),
|
||||||
GetHeightAtOffset(offsetCoord),
|
GetHeightAtOffset(offsetCoord),
|
||||||
tileCenter.y + (Mathf.Sqrt(3) / 2) * Size * 0.5f);
|
tileCenter.y + ((Mathf.Sqrt(3) / 2) * Mathf.Round(Size * 0.5f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=9 format=2]
|
[gd_scene load_steps=10 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://scenes/TileWorld.cs" type="Script" id=1]
|
[ext_resource path="res://scenes/TileWorld.cs" type="Script" id=1]
|
||||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
[ext_resource path="res://assets/Environment/rockC.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://assets/Environment/rockC.tscn" type="PackedScene" id=6]
|
||||||
[ext_resource path="res://assets/Environment/rockA.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://assets/Environment/rockA.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://assets/Environment/grassLarge.tscn" type="PackedScene" id=8]
|
[ext_resource path="res://assets/Environment/grassLarge.tscn" type="PackedScene" id=8]
|
||||||
|
[ext_resource path="res://assets/Environment/tree.tscn" type="PackedScene" id=9]
|
||||||
|
|
||||||
[node name="TileWorld" type="Spatial"]
|
[node name="TileWorld" type="Spatial"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
@ -64,4 +65,8 @@ visible = false
|
||||||
|
|
||||||
[node name="grassLarge" parent="Assets/Grass" instance=ExtResource( 8 )]
|
[node name="grassLarge" parent="Assets/Grass" instance=ExtResource( 8 )]
|
||||||
|
|
||||||
|
[node name="Trees" type="Spatial" parent="Assets"]
|
||||||
|
|
||||||
|
[node name="tree" parent="Assets/Trees" instance=ExtResource( 9 )]
|
||||||
|
|
||||||
[node name="Environment" type="Spatial" parent="."]
|
[node name="Environment" type="Spatial" parent="."]
|
||||||
|
|
Loading…
Reference in New Issue