💫 Better build effects
This commit is contained in:
		| @@ -9,6 +9,7 @@ size = Vector2(54, 54) | ||||
| [node name="GroundTile" type="StaticBody2D"] | ||||
| collision_layer = 0 | ||||
| script = ExtResource("1_mqsaf") | ||||
| TileId = "ground" | ||||
|  | ||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | ||||
| scale = Vector2(0.1, 0.1) | ||||
|   | ||||
| @@ -8,6 +8,7 @@ size = Vector2(54, 54) | ||||
|  | ||||
| [node name="MinerTile" type="StaticBody2D"] | ||||
| script = ExtResource("1_mecoy") | ||||
| TileId = "miner" | ||||
|  | ||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | ||||
| scale = Vector2(0.1, 0.1) | ||||
|   | ||||
| @@ -9,6 +9,7 @@ size = Vector2(54, 54) | ||||
| [node name="StoneIronTile" type="StaticBody2D"] | ||||
| collision_layer = 0 | ||||
| script = ExtResource("1_ewklp") | ||||
| TileId = "stone_iron" | ||||
|  | ||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | ||||
| scale = Vector2(0.1, 0.1) | ||||
|   | ||||
| @@ -9,6 +9,7 @@ size = Vector2(54, 54) | ||||
| [node name="StoneTile" type="StaticBody2D"] | ||||
| collision_layer = 0 | ||||
| script = ExtResource("1_rndy8") | ||||
| TileId = "stone" | ||||
|  | ||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | ||||
| scale = Vector2(0.1, 0.1) | ||||
|   | ||||
| @@ -8,6 +8,7 @@ size = Vector2(54, 54) | ||||
|  | ||||
| [node name="WallTile" type="StaticBody2D"] | ||||
| script = ExtResource("1_ph7y3") | ||||
| TileId = "wall" | ||||
|  | ||||
| [node name="Sprite2D" type="Sprite2D" parent="."] | ||||
| scale = Vector2(0.05, 0.05) | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using System.Numerics; | ||||
| using System.Threading.Tasks; | ||||
| using AceFieldNewHorizon.Scripts.System; | ||||
| using Godot; | ||||
| using Vector2 = Godot.Vector2; | ||||
| @@ -7,9 +7,14 @@ 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; | ||||
|  | ||||
|     public override void _Ready() | ||||
|     { | ||||
| @@ -18,6 +23,15 @@ 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) | ||||
| @@ -47,6 +61,7 @@ public partial class BaseTile : Node2D | ||||
|         var texSize = new Vector2(GridUtils.TileSize, GridUtils.TileSize); | ||||
|  | ||||
|         _progressOverlay.Visible = true; | ||||
|         _progressOverlay.Modulate = Colors.White; | ||||
|         _progressOverlay.Color = new Color(0, 0, 1, 0.4f); // semi-transparent blue | ||||
|  | ||||
|         async void RunProgress() | ||||
| @@ -67,9 +82,33 @@ public partial class BaseTile : Node2D | ||||
|                 ); | ||||
|             } | ||||
|  | ||||
|             _progressOverlay.Visible = false; | ||||
|             // Fade out the overlay instead of making it instantly disappear | ||||
|             await FadeOutOverlay(0.5f); | ||||
|         } | ||||
|  | ||||
|         RunProgress(); | ||||
|     } | ||||
|  | ||||
|     private async Task FadeOutOverlay(float duration) | ||||
|     { | ||||
|         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); | ||||
|             elapsed += (float)GetProcessDeltaTime(); | ||||
|             var alpha = Mathf.Lerp(startAlpha, 0f, elapsed / duration); | ||||
|             _progressOverlay.Modulate = new Color(1, 1, 1, alpha); | ||||
|         } | ||||
|  | ||||
|         _progressOverlay.Visible = false; | ||||
|         _progressOverlay.Modulate = Colors.White; // Reset alpha for next use | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								Sounds/Events/ConstructionComplete.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Sounds/Events/ConstructionComplete.wav
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										24
									
								
								Sounds/Events/ConstructionComplete.wav.import
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Sounds/Events/ConstructionComplete.wav.import
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| [remap] | ||||
|  | ||||
| importer="wav" | ||||
| type="AudioStreamWAV" | ||||
| uid="uid://xmgj505csg5x" | ||||
| path="res://.godot/imported/ConstructionComplete.wav-094dbaa5fa3f80e5fe8fc1583055a77d.sample" | ||||
|  | ||||
| [deps] | ||||
|  | ||||
| source_file="res://Sounds/Events/ConstructionComplete.wav" | ||||
| dest_files=["res://.godot/imported/ConstructionComplete.wav-094dbaa5fa3f80e5fe8fc1583055a77d.sample"] | ||||
|  | ||||
| [params] | ||||
|  | ||||
| force/8_bit=false | ||||
| force/mono=false | ||||
| force/max_rate=false | ||||
| force/max_rate_hz=44100 | ||||
| edit/trim=false | ||||
| edit/normalize=false | ||||
| edit/loop_mode=0 | ||||
| edit/loop_begin=0 | ||||
| edit/loop_end=-1 | ||||
| compress/mode=2 | ||||
		Reference in New Issue
	
	Block a user