Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
Cat Flynn | d431848791 | |
Cat Flynn | 78e4c6ee9e | |
ktyl | f13fe16317 | |
ktyl | ece699b68e | |
ktyl | 1bbb11b042 | |
ktyl | 8c55e2131f | |
ktyl | c22827967f | |
ktyl | 6793335983 |
9
gdd.md
9
gdd.md
|
@ -11,15 +11,14 @@
|
||||||
## Clock
|
## Clock
|
||||||
|
|
||||||
Ticks can be applied manually or they can be applied over time.
|
Ticks can be applied manually or they can be applied over time.
|
||||||
Add a tick counter as a UI element.
|
There is a tick counter UI debug element.
|
||||||
|
|
||||||
## Grid
|
## Diffusion
|
||||||
|
|
||||||
|
### Grid
|
||||||
|
|
||||||
Add a 10x10 grid.
|
Add a 10x10 grid.
|
||||||
Tiles are highlighted a different colour when the player hovers over them with the cursor.
|
Tiles are highlighted a different colour when the player hovers over them with the cursor.
|
||||||
|
|
||||||
### Diffusion
|
|
||||||
|
|
||||||
Tiles in the grid contain floating point values.
|
Tiles in the grid contain floating point values.
|
||||||
These values propogate to neighbouring cells a tick happens.
|
These values propogate to neighbouring cells a tick happens.
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
[gd_resource type="Resource" load_steps=3 format=2]
|
[gd_resource type="Resource" load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://scripts/tile/TileTypeCollection.cs" type="Script" id=1]
|
[ext_resource path="res://scripts/tile/TileTypeCollection.cs" type="Script" id=1]
|
||||||
[ext_resource path="res://resources/tiles/tile_types/developed.tres" type="Resource" id=2]
|
[ext_resource path="res://resources/tiles/tile_types/developed.tres" type="Resource" id=2]
|
||||||
|
[ext_resource path="res://resources/tiles/tile_types/wild.tres" type="Resource" id=3]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
_resources = [ ExtResource( 2 ) ]
|
_resources = [ ExtResource( 2 ), ExtResource( 3 ) ]
|
||||||
|
|
|
@ -8,4 +8,5 @@ Name = "Wild"
|
||||||
Key = 87
|
Key = 87
|
||||||
Color = Color( 0.14902, 1, 0, 0 )
|
Color = Color( 0.14902, 1, 0, 0 )
|
||||||
HeatGeneration = -0.02
|
HeatGeneration = -0.02
|
||||||
|
HealRate = 0.01
|
||||||
Threshold = 0.6
|
Threshold = 0.6
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public class HeatSystem
|
public class EnvironmentSystem
|
||||||
{
|
{
|
||||||
private readonly TileGrid _tiles;
|
private readonly TileGrid _tiles;
|
||||||
private readonly float _diffusionCoefficient;
|
private readonly float _diffusionCoefficient;
|
||||||
|
|
||||||
private float[] _nextTemperatures = null;
|
private float[] _nextTemperatures = null;
|
||||||
|
|
||||||
public HeatSystem(TileGrid tiles, float diffusionCoefficient)
|
public EnvironmentSystem(TileGrid tiles, float diffusionCoefficient)
|
||||||
{
|
{
|
||||||
_tiles = tiles;
|
_tiles = tiles;
|
||||||
_diffusionCoefficient = diffusionCoefficient;
|
_diffusionCoefficient = diffusionCoefficient;
|
||||||
|
@ -20,7 +20,6 @@ public class HeatSystem
|
||||||
Diffuse();
|
Diffuse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private float TransferHeat(float t0, float alpha, float nx, float ny, float px, float py)
|
private float TransferHeat(float t0, float alpha, float nx, float ny, float px, float py)
|
||||||
{
|
{
|
||||||
float d2tdx2 = nx - 2 * t0 + px;
|
float d2tdx2 = nx - 2 * t0 + px;
|
||||||
|
@ -46,23 +45,42 @@ public class HeatSystem
|
||||||
var tile = _tiles[i];
|
var tile = _tiles[i];
|
||||||
var type = tile.type;
|
var type = tile.type;
|
||||||
tile.temperature += type.HeatGeneration;
|
tile.temperature += type.HeatGeneration;
|
||||||
ApplyHeatDamage(ref tile);
|
|
||||||
_tiles[i] = tile;
|
_tiles[i] = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < _tiles.Count; i++)
|
||||||
|
{
|
||||||
|
ApplyHeatDamage(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyHeatDamage(ref Tile tile)
|
private void ApplyHeatDamage(int i)
|
||||||
{
|
{
|
||||||
|
_tiles.MapIndex(i, out var x, out var y);
|
||||||
|
var tile = _tiles[x, y];
|
||||||
if (!(tile.type is IDamageable damageable))
|
if (!(tile.type is IDamageable damageable))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var surplus = tile.temperature - damageable.Threshold;
|
var delta = tile.temperature - damageable.Threshold;
|
||||||
if (surplus < 0)
|
if (delta < 0)
|
||||||
return;
|
{
|
||||||
|
// we want to heal based on how many wild tiles surround us
|
||||||
|
float wild = _tiles.GetNeighbourProportion<Wild>(x, y);
|
||||||
|
float heal = damageable.HealRate * wild;
|
||||||
|
|
||||||
|
tile.currentHealth += heal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// TODO: parameterised balancing
|
// TODO: parameterised balancing
|
||||||
tile.currentHealth -= surplus;
|
|
||||||
|
// take damage
|
||||||
|
tile.currentHealth -= delta;
|
||||||
|
}
|
||||||
|
|
||||||
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
|
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
|
||||||
|
|
||||||
|
_tiles[x, y] = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Diffuse()
|
private void Diffuse()
|
||||||
|
@ -96,5 +114,4 @@ public class HeatSystem
|
||||||
_tiles[i] = tile;
|
_tiles[i] = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ public class WorldGrid : Node2D
|
||||||
public ShaderMaterial material;
|
public ShaderMaterial material;
|
||||||
}
|
}
|
||||||
private TileView[] _tileViews;
|
private TileView[] _tileViews;
|
||||||
private HeatSystem _heat;
|
private EnvironmentSystem _environment;
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
|
@ -30,7 +30,7 @@ public class WorldGrid : Node2D
|
||||||
|
|
||||||
GenerateCanvasItems(_tileGrid);
|
GenerateCanvasItems(_tileGrid);
|
||||||
|
|
||||||
_heat = new HeatSystem(_tileGrid, DiffusionCoefficient);
|
_environment = new EnvironmentSystem(_tileGrid, DiffusionCoefficient);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Positioning
|
#region Positioning
|
||||||
|
@ -53,6 +53,7 @@ public class WorldGrid : Node2D
|
||||||
|
|
||||||
var tile = _tileGrid[idx];
|
var tile = _tileGrid[idx];
|
||||||
tile.type = tileType;
|
tile.type = tileType;
|
||||||
|
tile = tileType.ApplySpawneffect(tile);
|
||||||
_tileGrid[x, y] = tile;
|
_tileGrid[x, y] = tile;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -100,5 +101,5 @@ public class WorldGrid : Node2D
|
||||||
|
|
||||||
public ShaderMaterial GetTileMaterial(int idx) => _tileViews[idx].material;
|
public ShaderMaterial GetTileMaterial(int idx) => _tileViews[idx].material;
|
||||||
|
|
||||||
public void _on_Clock_OnTick(int ticks) => _heat.Process();
|
public void _on_Clock_OnTick(int ticks) => _environment.Process();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
public interface IDamageable
|
public interface IDamageable
|
||||||
{
|
{
|
||||||
|
float HealRate { get; }
|
||||||
float Threshold { get; }
|
float Threshold { get; }
|
||||||
}
|
}
|
|
@ -89,5 +89,64 @@ public class TileGrid : Resource, IReadOnlyList<Tile>
|
||||||
{
|
{
|
||||||
return x >= 0 && x < Size && y >= 0 && y < Size;
|
return x >= 0 && x < Size && y >= 0 && y < Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly int[] _neighbours = new int[]
|
||||||
|
{
|
||||||
|
-1, 0,
|
||||||
|
0, 1,
|
||||||
|
1, 0,
|
||||||
|
0, -1
|
||||||
|
};
|
||||||
|
|
||||||
|
private void GetCoordinate(int dir, out int x, out int y)
|
||||||
|
{
|
||||||
|
dir %= 4;
|
||||||
|
int idx = dir * 2;
|
||||||
|
x = _neighbours[idx];
|
||||||
|
y = _neighbours[idx + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetNeighbourProportion<T>(int x, int y)
|
||||||
|
{
|
||||||
|
int typed = GetNeighbourCount<T>(x, y);
|
||||||
|
int all = GetNeighbourCount(x, y);
|
||||||
|
return (float)typed / (float)all;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetNeighbourCount<T>(int x, int y)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
GetCoordinate(i, out var nx, out var ny);
|
||||||
|
|
||||||
|
if (!IsInBounds(x + nx, y + ny))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(this[x + nx, y + ny].type is T))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetNeighbourCount(int x, int y)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
GetCoordinate(i, out var nx, out var ny);
|
||||||
|
|
||||||
|
if (!IsInBounds(x + nx, y + ny))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,6 @@ public class TileType : Resource
|
||||||
public float HeatGeneration { get; private set; }
|
public float HeatGeneration { get; private set; }
|
||||||
|
|
||||||
public override string ToString() => Name;
|
public override string ToString() => Name;
|
||||||
|
|
||||||
|
public virtual Tile ApplySpawneffect(Tile tile) => tile;
|
||||||
}
|
}
|
|
@ -2,6 +2,15 @@ using Godot;
|
||||||
|
|
||||||
public class Wild : TileType, IDamageable
|
public class Wild : TileType, IDamageable
|
||||||
{
|
{
|
||||||
|
[Export]
|
||||||
|
public float HealRate { get; private set; } = 0.01f;
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public float Threshold { get; private set; }
|
public float Threshold { get; private set; }
|
||||||
|
|
||||||
|
public override Tile ApplySpawneffect(Tile tile)
|
||||||
|
{
|
||||||
|
tile.currentHealth = 0;
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -20,10 +20,14 @@ public class BuildModeUI : Control
|
||||||
_buildMode = GetNode<BuildMode>(_buildModePath);
|
_buildMode = GetNode<BuildMode>(_buildModePath);
|
||||||
|
|
||||||
var buttonHeight = 40;
|
var buttonHeight = 40;
|
||||||
var tileType = _buildMode.BuildableTiles[0];
|
|
||||||
int x = 50;
|
|
||||||
|
|
||||||
SpawnButton(tileType, buttonHeight, ref x);
|
int x = 50;
|
||||||
|
int margin = 5;
|
||||||
|
foreach (var tt in _buildMode.BuildableTiles)
|
||||||
|
{
|
||||||
|
SpawnButton(tt, buttonHeight, ref x);
|
||||||
|
x += margin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateButtonToggleState(TileType tileType)
|
private void UpdateButtonToggleState(TileType tileType)
|
||||||
|
|
Loading…
Reference in New Issue