Compare commits

...

2 Commits

13 changed files with 111 additions and 38 deletions

View File

@@ -37,8 +37,8 @@
"allowedRotations": [0], "allowedRotations": [0],
"layer": 0 "layer": 0
}, },
"stone_iron": { "ore_iron": {
"scene": "res://Scenes/Tiles/StoneIronTile.tscn", "scene": "res://Scenes/Tiles/OreIronTile.tscn",
"cost": {}, "cost": {},
"durability": 200, "durability": 200,
"buildTime": 0.0, "buildTime": 0.0,

View File

@@ -5,6 +5,7 @@
[node name="Player" type="CharacterBody2D"] [node name="Player" type="CharacterBody2D"]
script = ExtResource("1_08t41") script = ExtResource("1_08t41")
MaxZoom = 5.0
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
rotation = 1.5708 rotation = 1.5708

Binary file not shown.

Before

Width:  |  Height:  |  Size: 486 KiB

After

Width:  |  Height:  |  Size: 367 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 KiB

View File

@@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://c3qdue55e6blv" uid="uid://c3qdue55e6blv"
path="res://.godot/imported/StoneIronTile.png-a3d6be6bb8b8b8a0f32242e23f1c00ca.ctex" path="res://.godot/imported/OreIronTile.png-68726be1be21a3f84cf7d705e1a39b0d.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://Scenes/Tiles/StoneIronTile.png" source_file="res://Scenes/Tiles/OreIronTile.png"
dest_files=["res://.godot/imported/StoneIronTile.png-a3d6be6bb8b8b8a0f32242e23f1c00ca.ctex"] dest_files=["res://.godot/imported/OreIronTile.png-68726be1be21a3f84cf7d705e1a39b0d.ctex"]
[params] [params]

View File

@@ -1,24 +1,26 @@
[gd_scene load_steps=4 format=3 uid="uid://dnkcl5ucmip40"] [gd_scene load_steps=4 format=3 uid="uid://dnkcl5ucmip40"]
[ext_resource type="Script" uid="uid://dh0jdeplrigxu" path="res://Scripts/Tiles/GroundTile.cs" id="1_ewklp"] [ext_resource type="Script" uid="uid://dh0jdeplrigxu" path="res://Scripts/Tiles/GroundTile.cs" id="1_exnim"]
[ext_resource type="Texture2D" uid="uid://c3qdue55e6blv" path="res://Scenes/Tiles/StoneIronTile.png" id="2_ewklp"] [ext_resource type="Texture2D" uid="uid://c3qdue55e6blv" path="res://Scenes/Tiles/OreIronTile.png" id="2_7v0w1"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8o613"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_8o613"]
size = Vector2(54, 54) size = Vector2(54, 54)
[node name="StoneIronTile" type="StaticBody2D"] [node name="OreIronTile" type="StaticBody2D"]
collision_layer = 0 collision_layer = 0
script = ExtResource("1_ewklp") script = ExtResource("1_exnim")
TileId = "stone_iron" TileId = "stone_iron"
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.1, 0.1) position = Vector2(1.49012e-08, -9.53674e-07)
texture = ExtResource("2_ewklp") scale = Vector2(0.0983607, 0.0981818)
texture = ExtResource("2_7v0w1")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_8o613") shape = SubResource("RectangleShape2D_8o613")
[node name="ProgressOverlay" type="ColorRect" parent="."] [node name="ProgressOverlay" type="ColorRect" parent="."]
visible = false
offset_left = -27.0 offset_left = -27.0
offset_top = -27.0 offset_top = -27.0
offset_right = 27.0 offset_right = 27.0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 474 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 590 KiB

After

Width:  |  Height:  |  Size: 558 KiB

View File

@@ -12,13 +12,15 @@ script = ExtResource("1_rndy8")
TileId = "stone" TileId = "stone"
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.1, 0.1) position = Vector2(1.01328e-06, 1.01328e-06)
scale = Vector2(0.0976562, 0.0976562)
texture = ExtResource("2_rndy8") texture = ExtResource("2_rndy8")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_8o613") shape = SubResource("RectangleShape2D_8o613")
[node name="ProgressOverlay" type="ColorRect" parent="."] [node name="ProgressOverlay" type="ColorRect" parent="."]
visible = false
offset_left = -27.0 offset_left = -27.0
offset_top = -27.0 offset_top = -27.0
offset_right = 27.0 offset_right = 27.0

View File

@@ -71,7 +71,7 @@ public partial class NaturalResourceGenerator : Node2D
if (_rng.Randf() < IronDensity) if (_rng.Randf() < IronDensity)
{ {
var veinSize = _rng.RandiRange(MinIronVeinSize, MaxIronVeinSize); var veinSize = _rng.RandiRange(MinIronVeinSize, MaxIronVeinSize);
PlaceVein(stoneCell, "stone_iron", veinSize, _ironTiles); PlaceVein(stoneCell, "ore_iron", veinSize, _ironTiles);
} }
} }
} }
@@ -93,10 +93,10 @@ public partial class NaturalResourceGenerator : Node2D
switch (tileType) switch (tileType)
{ {
// For iron, make sure we're placing on stone // For iron, make sure we're placing on stone
case "stone_iron" when !_stoneTiles.Contains(cell): case "ore_iron" when !_stoneTiles.Contains(cell):
continue; continue;
// Remove from previous layer if needed // Remove from previous layer if needed
case "stone_iron" when _stoneTiles.Contains(cell): case "ore_iron" when _stoneTiles.Contains(cell):
_stoneTiles.Remove(cell); _stoneTiles.Remove(cell);
break; break;
case "stone" when _groundTiles.Contains(cell): case "stone" when _groundTiles.Contains(cell):

View File

@@ -10,8 +10,68 @@ public partial class PlacementManager : Node2D
{ {
[Export] public GridManager Grid { get; set; } [Export] public GridManager Grid { get; set; }
[Export] public BuildingRegistry Registry { get; set; } [Export] public BuildingRegistry Registry { get; set; }
[Export] public int MaxConcurrentBuilds { get; set; } = 6; // Make it adjustable in editor
private static readonly List<string> BuildableTiles = ["wall", "miner"]; private static readonly List<string> BuildableTiles = ["wall", "miner"];
private readonly List<BuildTask> _activeBuilds = new();
private AudioStreamPlayer _completionSound;
public override void _Ready()
{
base._Ready();
// Setup completion sound
_completionSound = new AudioStreamPlayer();
AddChild(_completionSound);
var sound = GD.Load<AudioStream>("res://Sounds/Events/ConstructionComplete.wav");
if (sound != null)
{
_completionSound.Stream = sound;
}
}
private void OnBuildCompleted()
{
// Remove all completed builds
_activeBuilds.RemoveAll(task => task.IsCompleted);
// If no builds left, play the completion sound
if (_activeBuilds.Count == 0)
{
_completionSound.Play();
}
}
// Call this when starting a new build
private bool CanStartNewBuild()
{
// Remove completed builds
_activeBuilds.RemoveAll(task => task.IsCompleted);
return _activeBuilds.Count < MaxConcurrentBuilds;
}
private class BuildTask : IDisposable
{
private readonly Action _onCompleted;
public bool IsCompleted { get; private set; }
public BuildTask(Action onCompleted)
{
_onCompleted = onCompleted;
}
public void Complete()
{
if (IsCompleted) return;
IsCompleted = true;
_onCompleted?.Invoke();
}
public void Dispose()
{
Complete();
}
}
private string _currentBuildingId = "wall"; private string _currentBuildingId = "wall";
private Vector2I _hoveredCell; private Vector2I _hoveredCell;
@@ -122,6 +182,12 @@ public partial class PlacementManager : Node2D
var building = Registry.GetBuilding(_currentBuildingId); var building = Registry.GetBuilding(_currentBuildingId);
if (building == null) return; if (building == null) return;
if (!CanStartNewBuild())
{
// Optionally show feedback to player that build queue is full
return;
}
var scene = building.Scene; var scene = building.Scene;
var buildingInstance = (BaseTile)scene.Instantiate(); var buildingInstance = (BaseTile)scene.Instantiate();
buildingInstance.RotationDegrees = _currentRotation; buildingInstance.RotationDegrees = _currentRotation;
@@ -132,7 +198,11 @@ public partial class PlacementManager : Node2D
Grid.OccupyArea(_hoveredCell, buildingInstance, building.Size, _currentRotation, building.Layer); Grid.OccupyArea(_hoveredCell, buildingInstance, building.Size, _currentRotation, building.Layer);
if (building.BuildTime > 0f) if (building.BuildTime > 0f)
buildingInstance.StartConstruction(building.BuildTime); {
var buildTask = new BuildTask(OnBuildCompleted);
_activeBuilds.Add(buildTask);
buildingInstance.StartConstruction(building.BuildTime, buildTask.Complete);
}
} }
if (Input.IsActionPressed("destroy_tile") && if (Input.IsActionPressed("destroy_tile") &&

View File

@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using AceFieldNewHorizon.Scripts.System; using AceFieldNewHorizon.Scripts.System;
using Godot; using Godot;
@@ -9,12 +10,10 @@ public partial class BaseTile : Node2D
{ {
[Export] public string TileId { get; set; } [Export] public string TileId { get; set; }
public BuildingData TileData { get; set; }
private CollisionShape2D _collisionShape; private CollisionShape2D _collisionShape;
private Sprite2D _sprite; private Sprite2D _sprite;
private ColorRect _progressOverlay; private ColorRect _progressOverlay;
private AudioStreamPlayer _completionSound; private Action _onConstructionComplete;
public override void _Ready() public override void _Ready()
{ {
@@ -23,15 +22,6 @@ public partial class BaseTile : Node2D
_progressOverlay = GetNodeOrNull<ColorRect>("ProgressOverlay"); _progressOverlay = GetNodeOrNull<ColorRect>("ProgressOverlay");
if (_progressOverlay != null) if (_progressOverlay != null)
_progressOverlay.Visible = false; _progressOverlay.Visible = false;
// Setup audio player
_completionSound = new AudioStreamPlayer();
AddChild(_completionSound);
var sound = GD.Load<AudioStream>("res://Sounds/Events/ConstructionComplete.wav");
if (sound != null)
{
_completionSound.Stream = sound;
}
} }
public void SetGhostMode(bool canPlace) public void SetGhostMode(bool canPlace)
@@ -54,10 +44,15 @@ public partial class BaseTile : Node2D
} }
// Building progress visualization // Building progress visualization
public void StartConstruction(float buildTime) public void StartConstruction(float buildTime, Action onComplete = null)
{ {
if (_progressOverlay == null || _sprite?.Texture == null) return; if (_progressOverlay == null || _sprite?.Texture == null)
{
onComplete?.Invoke();
return;
}
_onConstructionComplete = onComplete;
var texSize = new Vector2(GridUtils.TileSize, GridUtils.TileSize); var texSize = new Vector2(GridUtils.TileSize, GridUtils.TileSize);
_progressOverlay.Visible = true; _progressOverlay.Visible = true;
@@ -82,8 +77,11 @@ public partial class BaseTile : Node2D
); );
} }
// Fade out the overlay instead of making it instantly disappear // Fade out the overlay
await FadeOutOverlay(0.5f); await FadeOutOverlay(0.5f);
// Notify completion
_onConstructionComplete?.Invoke();
} }
RunProgress(); RunProgress();
@@ -94,12 +92,6 @@ public partial class BaseTile : Node2D
var elapsed = 0f; var elapsed = 0f;
var startAlpha = _progressOverlay.Modulate.A; var startAlpha = _progressOverlay.Modulate.A;
// Play completion sound
if (_completionSound?.Stream != null)
{
_completionSound.Play();
}
while (elapsed < duration) while (elapsed < duration)
{ {
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame); await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);

View File

@@ -4,5 +4,11 @@ namespace AceFieldNewHorizon.Scripts.Tiles;
public partial class GroundTile : BaseTile public partial class GroundTile : BaseTile
{ {
public override void _Ready()
{
var sprite = GetNode<Sprite2D>("Sprite2D");
sprite.Modulate = new Color(0.75f, 0.75f, 0.75f); // Makes the sprite 25% darker
base._Ready();
}
} }