wild tiles take heat damage from developed tiles #7
This commit is contained in:
parent
58c2d9a451
commit
6793335983
|
@ -4,3 +4,5 @@
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
_healthy = Color( 0.0431373, 0.541176, 0.0235294, 1 )
|
||||||
|
_depleted = Color( 0.670588, 0.572549, 0.27451, 1 )
|
||||||
|
|
|
@ -7,4 +7,4 @@ script = ExtResource( 1 )
|
||||||
Name = "Developed"
|
Name = "Developed"
|
||||||
Key = 68
|
Key = 68
|
||||||
Color = Color( 0.372549, 0.372549, 0.372549, 1 )
|
Color = Color( 0.372549, 0.372549, 0.372549, 1 )
|
||||||
HeatGeneration = 0.4
|
HeatGeneration = 0.15
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
[gd_resource type="Resource" load_steps=2 format=2]
|
[gd_resource type="Resource" load_steps=2 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://scripts/tile/TileType.cs" type="Script" id=1]
|
[ext_resource path="res://scripts/tile/Wild.cs" type="Script" id=1]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
Name = "Wild"
|
Name = "Wild"
|
||||||
Key = 87
|
Key = 87
|
||||||
Color = Color( 0, 0.545098, 0.0196078, 1 )
|
Color = Color( 0.14902, 1, 0, 0 )
|
||||||
HeatGeneration = -0.2
|
HeatGeneration = -0.02
|
||||||
|
Threshold = 0.6
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class WorldGrid : Node2D
|
||||||
|
|
||||||
TileView view = default;
|
TileView view = default;
|
||||||
view.material = (ShaderMaterial)canvasItem.Material;
|
view.material = (ShaderMaterial)canvasItem.Material;
|
||||||
view.material.SetShaderParam("lowColor", _tileGrid.StartTileType.Color);
|
//view.material.SetShaderParam("lowColor", _tileGrid.StartTileType.Color);
|
||||||
_tileViews[i] = view;
|
_tileViews[i] = view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,20 @@ public class WorldGrid : Node2D
|
||||||
py = y < _tileGrid.Size - 1 ? _tileGrid[x, y + 1].temperature : t;
|
py = y < _tileGrid.Size - 1 ? _tileGrid[x, y + 1].temperature : t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyHeatDamage(ref Tile tile)
|
||||||
|
{
|
||||||
|
if (!(tile.type is IDamageable damageable))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var surplus = tile.temperature - damageable.Threshold;
|
||||||
|
if (surplus < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// TODO: parameterised balancing
|
||||||
|
tile.currentHealth -= surplus;
|
||||||
|
tile.currentHealth = Mathf.Clamp(tile.currentHealth, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
private void GenerateHeat()
|
private void GenerateHeat()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _tileGrid.Count; i++)
|
for (int i = 0; i < _tileGrid.Count; i++)
|
||||||
|
@ -136,6 +150,7 @@ public class WorldGrid : Node2D
|
||||||
var tile = _tileGrid[i];
|
var tile = _tileGrid[i];
|
||||||
var type = tile.type;
|
var type = tile.type;
|
||||||
tile.temperature += type.HeatGeneration;
|
tile.temperature += type.HeatGeneration;
|
||||||
|
ApplyHeatDamage(ref tile);
|
||||||
_tileGrid[i] = tile;
|
_tileGrid[i] = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,25 @@ using Godot;
|
||||||
|
|
||||||
public class NoOverlay : Overlay
|
public class NoOverlay : Overlay
|
||||||
{
|
{
|
||||||
|
[Export]
|
||||||
|
private Color _healthy;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
private Color _depleted;
|
||||||
|
|
||||||
// in this view we want to draw tiles with their normal colour
|
// in this view we want to draw tiles with their normal colour
|
||||||
public override void Apply(Tile tile, ShaderMaterial material)
|
public override void Apply(Tile tile, ShaderMaterial material)
|
||||||
{
|
{
|
||||||
var type = tile.type;
|
var type = tile.type;
|
||||||
|
|
||||||
|
if (type is Wild wild)
|
||||||
|
{
|
||||||
|
material.SetShaderParam("lowColor", _depleted);
|
||||||
|
material.SetShaderParam("highColor", _healthy);
|
||||||
|
material.SetShaderParam("t", tile.currentHealth);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
material.SetShaderParam("lowColor", type.Color);
|
material.SetShaderParam("lowColor", type.Color);
|
||||||
material.SetShaderParam("t", 0);
|
material.SetShaderParam("t", 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
public interface IDamageable
|
||||||
|
{
|
||||||
|
float Threshold { get; }
|
||||||
|
}
|
|
@ -5,4 +5,5 @@ public struct Tile
|
||||||
public bool isHighlighted;
|
public bool isHighlighted;
|
||||||
public float temperature;
|
public float temperature;
|
||||||
public TileType type;
|
public TileType type;
|
||||||
|
public float currentHealth;
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ public class TileGrid : Resource, IReadOnlyList<Tile>
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
private Resource _startTileTypeResource;
|
private Resource _startTileTypeResource;
|
||||||
public TileType StartTileType => (TileType)_startTileTypeResource;
|
private TileType StartTileType => (TileType)_startTileTypeResource;
|
||||||
|
|
||||||
public int Count => Size * Size;
|
public int Count => Size * Size;
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ public class TileGrid : Resource, IReadOnlyList<Tile>
|
||||||
tile.isHighlighted = false;
|
tile.isHighlighted = false;
|
||||||
tile.temperature = 0.0f;
|
tile.temperature = 0.0f;
|
||||||
tile.type = StartTileType;
|
tile.type = StartTileType;
|
||||||
|
tile.currentHealth = 1.0f;
|
||||||
|
|
||||||
tiles.Add(tile);
|
tiles.Add(tile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
public class Wild : TileType, IDamageable
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public float Threshold { get; private set; }
|
||||||
|
}
|
Loading…
Reference in New Issue