Compare commits

..

No commits in common. "d431848791adade3ebfce5de89308446fc903e4a" and "f13fe1631724e75493151ce76cd1aea147b9fb39" have entirely different histories.

6 changed files with 38 additions and 83 deletions

9
gdd.md
View File

@ -11,14 +11,15 @@
## Clock
Ticks can be applied manually or they can be applied over time.
There is a tick counter UI debug element.
Add a tick counter as a UI element.
## Diffusion
### Grid
## Grid
Add a 10x10 grid.
Tiles are highlighted a different colour when the player hovers over them with the cursor.
### Diffusion
Tiles in the grid contain floating point values.
These values propogate to neighbouring cells a tick happens.

View File

@ -8,5 +8,4 @@ Name = "Wild"
Key = 87
Color = Color( 0.14902, 1, 0, 0 )
HeatGeneration = -0.02
HealRate = 0.01
Threshold = 0.6

View File

@ -45,19 +45,13 @@ public class EnvironmentSystem
var tile = _tiles[i];
var type = tile.type;
tile.temperature += type.HeatGeneration;
ApplyHeatDamage(ref tile);
_tiles[i] = tile;
}
for (int i = 0; i < _tiles.Count; i++)
{
ApplyHeatDamage(i);
}
}
private void ApplyHeatDamage(int i)
private void ApplyHeatDamage(ref Tile tile)
{
_tiles.MapIndex(i, out var x, out var y);
var tile = _tiles[x, y];
if (!(tile.type is IDamageable damageable))
return;
@ -65,22 +59,46 @@ public class EnvironmentSystem
if (delta < 0)
{
// we want to heal based on how many wild tiles surround us
float wild = _tiles.GetNeighbourProportion<Wild>(x, y);
float heal = damageable.HealRate * wild;
float healRate = 0.01f;
tile.currentHealth += heal;
// count neighbours
}
else
{
// TODO: parameterised balancing
// take damage
// TODO: parameterised balancing
tile.currentHealth -= delta;
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
}
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
}
_tiles[x, y] = tile;
public int GetNeighbourCount<T>(int x, int y) where T : TileType
{
int count = 0;
for (int i = -1; i < 1; i += 2)
{
for (int j = -1; j < 1; j += 2)
{
int xi = x + 1;
int yj = y + 1;
// assume tiles out side of bounds are the same type as this one
if (!_tiles.IsInBounds(xi, yj))
{
count += 1;
continue;
}
if (!(_tiles[xi, yj] is T))
continue;
count++;
}
}
return count;
}
private void Diffuse()

View File

@ -1,5 +1,4 @@
public interface IDamageable
{
float HealRate { get; }
float Threshold { get; }
}

View File

@ -89,64 +89,5 @@ public class TileGrid : Resource, IReadOnlyList<Tile>
{
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;
}
}

View File

@ -2,9 +2,6 @@ using Godot;
public class Wild : TileType, IDamageable
{
[Export]
public float HealRate { get; private set; } = 0.01f;
[Export]
public float Threshold { get; private set; }