Compare commits

...

2 Commits

13 changed files with 111 additions and 38 deletions

View File

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

View File

@@ -5,6 +5,7 @@
[node name="Player" type="CharacterBody2D"]
script = ExtResource("1_08t41")
MaxZoom = 5.0
[node name="Sprite2D" type="Sprite2D" parent="."]
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"
type="CompressedTexture2D"
uid="uid://c3qdue55e6blv"
path="res://.godot/imported/StoneIronTile.png-a3d6be6bb8b8b8a0f32242e23f1c00ca.ctex"
path="res://.godot/imported/OreIronTile.png-68726be1be21a3f84cf7d705e1a39b0d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Scenes/Tiles/StoneIronTile.png"
dest_files=["res://.godot/imported/StoneIronTile.png-a3d6be6bb8b8b8a0f32242e23f1c00ca.ctex"]
source_file="res://Scenes/Tiles/OreIronTile.png"
dest_files=["res://.godot/imported/OreIronTile.png-68726be1be21a3f84cf7d705e1a39b0d.ctex"]
[params]

View File

@@ -1,24 +1,26 @@
[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="Texture2D" uid="uid://c3qdue55e6blv" path="res://Scenes/Tiles/StoneIronTile.png" id="2_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/OreIronTile.png" id="2_7v0w1"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8o613"]
size = Vector2(54, 54)
[node name="StoneIronTile" type="StaticBody2D"]
[node name="OreIronTile" type="StaticBody2D"]
collision_layer = 0
script = ExtResource("1_ewklp")
script = ExtResource("1_exnim")
TileId = "stone_iron"
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.1, 0.1)
texture = ExtResource("2_ewklp")
position = Vector2(1.49012e-08, -9.53674e-07)
scale = Vector2(0.0983607, 0.0981818)
texture = ExtResource("2_7v0w1")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_8o613")
[node name="ProgressOverlay" type="ColorRect" parent="."]
visible = false
offset_left = -27.0
offset_top = -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"
[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")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_8o613")
[node name="ProgressOverlay" type="ColorRect" parent="."]
visible = false
offset_left = -27.0
offset_top = -27.0
offset_right = 27.0

View File

@@ -71,7 +71,7 @@ public partial class NaturalResourceGenerator : Node2D
if (_rng.Randf() < IronDensity)
{
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)
{
// For iron, make sure we're placing on stone
case "stone_iron" when !_stoneTiles.Contains(cell):
case "ore_iron" when !_stoneTiles.Contains(cell):
continue;
// Remove from previous layer if needed
case "stone_iron" when _stoneTiles.Contains(cell):
case "ore_iron" when _stoneTiles.Contains(cell):
_stoneTiles.Remove(cell);
break;
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 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 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 Vector2I _hoveredCell;
@@ -121,6 +181,12 @@ public partial class PlacementManager : Node2D
{
var building = Registry.GetBuilding(_currentBuildingId);
if (building == null) return;
if (!CanStartNewBuild())
{
// Optionally show feedback to player that build queue is full
return;
}
var scene = building.Scene;
var buildingInstance = (BaseTile)scene.Instantiate();
@@ -132,7 +198,11 @@ public partial class PlacementManager : Node2D
Grid.OccupyArea(_hoveredCell, buildingInstance, building.Size, _currentRotation, building.Layer);
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") &&

View File

@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AceFieldNewHorizon.Scripts.System;
using Godot;
@@ -8,13 +9,11 @@ namespace AceFieldNewHorizon.Scripts.Tiles;
public partial class BaseTile : Node2D
{
[Export] public string TileId { get; set; }
public BuildingData TileData { get; set; }
private CollisionShape2D _collisionShape;
private Sprite2D _sprite;
private ColorRect _progressOverlay;
private AudioStreamPlayer _completionSound;
private Action _onConstructionComplete;
public override void _Ready()
{
@@ -23,15 +22,6 @@ public partial class BaseTile : Node2D
_progressOverlay = GetNodeOrNull<ColorRect>("ProgressOverlay");
if (_progressOverlay != null)
_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)
@@ -54,10 +44,15 @@ public partial class BaseTile : Node2D
}
// 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);
_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);
// Notify completion
_onConstructionComplete?.Invoke();
}
RunProgress();
@@ -94,12 +92,6 @@ public partial class BaseTile : Node2D
var elapsed = 0f;
var startAlpha = _progressOverlay.Modulate.A;
// Play completion sound
if (_completionSound?.Stream != null)
{
_completionSound.Play();
}
while (elapsed < duration)
{
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);

View File

@@ -4,5 +4,11 @@ namespace AceFieldNewHorizon.Scripts.Tiles;
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();
}
}