Compare commits
4 Commits
c22827967f
...
f13fe16317
Author | SHA1 | Date |
---|---|---|
ktyl | f13fe16317 | |
ktyl | ece699b68e | |
ktyl | 1bbb11b042 | |
ktyl | 8c55e2131f |
|
@ -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://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]
|
||||
script = ExtResource( 1 )
|
||||
_resources = [ ExtResource( 2 ) ]
|
||||
_resources = [ ExtResource( 2 ), ExtResource( 3 ) ]
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
using Godot;
|
||||
|
||||
public class HeatSystem
|
||||
public class EnvironmentSystem
|
||||
{
|
||||
private readonly TileGrid _tiles;
|
||||
private readonly float _diffusionCoefficient;
|
||||
|
||||
private float[] _nextTemperatures = null;
|
||||
|
||||
public HeatSystem(TileGrid tiles, float diffusionCoefficient)
|
||||
public EnvironmentSystem(TileGrid tiles, float diffusionCoefficient)
|
||||
{
|
||||
_tiles = tiles;
|
||||
_diffusionCoefficient = diffusionCoefficient;
|
||||
|
@ -20,7 +20,6 @@ public class HeatSystem
|
|||
Diffuse();
|
||||
}
|
||||
|
||||
|
||||
private float TransferHeat(float t0, float alpha, float nx, float ny, float px, float py)
|
||||
{
|
||||
float d2tdx2 = nx - 2 * t0 + px;
|
||||
|
@ -56,13 +55,50 @@ public class HeatSystem
|
|||
if (!(tile.type is IDamageable damageable))
|
||||
return;
|
||||
|
||||
var surplus = tile.temperature - damageable.Threshold;
|
||||
if (surplus < 0)
|
||||
return;
|
||||
var delta = tile.temperature - damageable.Threshold;
|
||||
if (delta < 0)
|
||||
{
|
||||
// we want to heal based on how many wild tiles surround us
|
||||
float healRate = 0.01f;
|
||||
|
||||
// TODO: parameterised balancing
|
||||
tile.currentHealth -= surplus;
|
||||
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
|
||||
// count neighbours
|
||||
}
|
||||
else
|
||||
{
|
||||
// take damage
|
||||
// TODO: parameterised balancing
|
||||
tile.currentHealth -= delta;
|
||||
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -96,5 +132,4 @@ public class HeatSystem
|
|||
_tiles[i] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ public class WorldGrid : Node2D
|
|||
public ShaderMaterial material;
|
||||
}
|
||||
private TileView[] _tileViews;
|
||||
private HeatSystem _heat;
|
||||
private EnvironmentSystem _environment;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
|
@ -30,7 +30,7 @@ public class WorldGrid : Node2D
|
|||
|
||||
GenerateCanvasItems(_tileGrid);
|
||||
|
||||
_heat = new HeatSystem(_tileGrid, DiffusionCoefficient);
|
||||
_environment = new EnvironmentSystem(_tileGrid, DiffusionCoefficient);
|
||||
}
|
||||
|
||||
#region Positioning
|
||||
|
@ -53,6 +53,7 @@ public class WorldGrid : Node2D
|
|||
|
||||
var tile = _tileGrid[idx];
|
||||
tile.type = tileType;
|
||||
tile = tileType.ApplySpawneffect(tile);
|
||||
_tileGrid[x, y] = tile;
|
||||
}
|
||||
#endregion
|
||||
|
@ -100,5 +101,5 @@ public class WorldGrid : Node2D
|
|||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -17,4 +17,6 @@ public class TileType : Resource
|
|||
public float HeatGeneration { get; private set; }
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
public virtual Tile ApplySpawneffect(Tile tile) => tile;
|
||||
}
|
|
@ -4,4 +4,10 @@ public class Wild : TileType, IDamageable
|
|||
{
|
||||
[Export]
|
||||
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);
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue