diff --git a/Data/Buildings.json b/Data/Buildings.json index f185b09..4dca6bc 100644 --- a/Data/Buildings.json +++ b/Data/Buildings.json @@ -21,6 +21,18 @@ "layer": 1, "size": [1, 1] }, + "turret": { + "scene": "res://Scenes/Tiles/TurretTile.tscn", + "cost": { + "stone": 10, + "ore_iron": 5 + }, + "durability": 200, + "buildTime": 5.0, + "allowedRotations": [0], + "layer": 1, + "size": [1, 1] + }, "enemy_nest": { "scene": "res://Scenes/Tiles/EnemyNest.tscn", "cost": {}, diff --git a/Scenes/Tiles/EnemyNest.tscn b/Scenes/Tiles/EnemyNest.tscn index 8aed99b..3db4ad7 100644 --- a/Scenes/Tiles/EnemyNest.tscn +++ b/Scenes/Tiles/EnemyNest.tscn @@ -7,9 +7,10 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_id484"] size = Vector2(54, 54) -[node name="EnemyNest" type="CharacterBody2D"] +[node name="EnemyNest" type="StaticBody2D"] script = ExtResource("1_4g0ff") EnemyScene = ExtResource("2_pka71") +TileId = "enemy_nest" [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.056, 0.056) diff --git a/Scenes/Tiles/TurretTile.png b/Scenes/Tiles/TurretTile.png new file mode 100644 index 0000000..845dd4a Binary files /dev/null and b/Scenes/Tiles/TurretTile.png differ diff --git a/Scenes/Tiles/TurretTile.png.import b/Scenes/Tiles/TurretTile.png.import new file mode 100644 index 0000000..dd3f543 --- /dev/null +++ b/Scenes/Tiles/TurretTile.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ckssi7soymu7g" +path="res://.godot/imported/TurretTile.png-d55543f854deaa0fedf248ba979d1cb4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Scenes/Tiles/TurretTile.png" +dest_files=["res://.godot/imported/TurretTile.png-d55543f854deaa0fedf248ba979d1cb4.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Scenes/Tiles/TurretTile.tscn b/Scenes/Tiles/TurretTile.tscn new file mode 100644 index 0000000..6209fc7 --- /dev/null +++ b/Scenes/Tiles/TurretTile.tscn @@ -0,0 +1,32 @@ +[gd_scene load_steps=5 format=3 uid="uid://dbup2pvjl8het"] + +[ext_resource type="Script" uid="uid://n5g6i0uovxfk" path="res://Scripts/Tiles/TurretTile.cs" id="1_j3157"] +[ext_resource type="Texture2D" uid="uid://ckssi7soymu7g" path="res://Scenes/Tiles/TurretTile.png" id="2_7ljeh"] +[ext_resource type="Texture2D" uid="uid://dmbbkwgff7dej" path="res://Scenes/Tiles/TurretTileBarrel.png" id="3_gfad6"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_pndcb"] +size = Vector2(54, 54) + +[node name="Turret" type="StaticBody2D"] +script = ExtResource("1_j3157") +TileId = "turret" + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.1, 0.1) +texture = ExtResource("2_7ljeh") + +[node name="Barrel" type="Sprite2D" parent="."] +position = Vector2(0, -3) +scale = Vector2(0.08, 0.08) +texture = ExtResource("3_gfad6") +offset = Vector2(0, -54) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_pndcb") + +[node name="ProgressOverlay" type="ColorRect" parent="."] +visible = false +offset_left = -27.0 +offset_top = -27.0 +offset_right = 27.0 +offset_bottom = 27.0 diff --git a/Scenes/Tiles/TurretTileBarrel.png b/Scenes/Tiles/TurretTileBarrel.png new file mode 100644 index 0000000..df6e19d Binary files /dev/null and b/Scenes/Tiles/TurretTileBarrel.png differ diff --git a/Scenes/Tiles/TurretTileBarrel.png.import b/Scenes/Tiles/TurretTileBarrel.png.import new file mode 100644 index 0000000..7c453e4 --- /dev/null +++ b/Scenes/Tiles/TurretTileBarrel.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dmbbkwgff7dej" +path="res://.godot/imported/TurretTileBarrel.png-a9f6a29579c44d5d6ed4cc8f6c09fd72.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Scenes/Tiles/TurretTileBarrel.png" +dest_files=["res://.godot/imported/TurretTileBarrel.png-a9f6a29579c44d5d6ed4cc8f6c09fd72.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Scripts/Entities/Enemy.cs b/Scripts/Entities/Enemy.cs index eeac6e2..2cfa232 100644 --- a/Scripts/Entities/Enemy.cs +++ b/Scripts/Entities/Enemy.cs @@ -4,6 +4,8 @@ namespace AceFieldNewHorizon.Scripts.Entities; public partial class Enemy : CharacterBody2D { + public const string EnemyGroupName = "Enemy"; + [Export] public float MoveSpeed = 150.0f; [Export] public float DetectionRadius = 300.0f; [Export] public float AttackRange = 50.0f; @@ -29,6 +31,8 @@ public partial class Enemy : CharacterBody2D // Connect signals _detectionArea.BodyEntered += OnBodyEnteredDetection; _detectionArea.BodyExited += OnBodyExitedDetection; + + AddToGroup(EnemyGroupName); } public override void _Process(double delta) diff --git a/Scripts/System/PlacementManager.cs b/Scripts/System/PlacementManager.cs index 8b0456b..5aebf1c 100644 --- a/Scripts/System/PlacementManager.cs +++ b/Scripts/System/PlacementManager.cs @@ -16,7 +16,7 @@ public partial class PlacementManager : Node2D [Export] public bool Enabled { get; set; } = true; [Export] public StringName ToggleBuildAction { get; set; } = "toggle_build"; - private static readonly List BuildableTiles = ["wall", "miner"]; + private static readonly List BuildableTiles = ["wall", "miner", "turret"]; private readonly Dictionary _buildTasks = new(); private AudioStreamPlayer _completionSound; private AudioStreamPlayer _buildingSound; diff --git a/Scripts/Tiles/BaseTile.cs b/Scripts/Tiles/BaseTile.cs index f474e1b..2059957 100644 --- a/Scripts/Tiles/BaseTile.cs +++ b/Scripts/Tiles/BaseTile.cs @@ -28,7 +28,7 @@ public partial class BaseTile : Node2D _progressOverlay.Visible = false; } - public void SetGhostMode(bool canPlace) + public virtual void SetGhostMode(bool canPlace) { // Don't modify collision for constructing buildings if (IsConstructing) return; @@ -42,7 +42,7 @@ public partial class BaseTile : Node2D : new Color(1, 0, 0, 0.5f); } - public void FinalizePlacement() + public virtual void FinalizePlacement() { if (_collisionShape != null) _collisionShape.Disabled = false; diff --git a/Scripts/Tiles/TurretTile.cs b/Scripts/Tiles/TurretTile.cs new file mode 100644 index 0000000..2dd42bb --- /dev/null +++ b/Scripts/Tiles/TurretTile.cs @@ -0,0 +1,33 @@ +using Godot; + +namespace AceFieldNewHorizon.Scripts.Tiles; + +public partial class TurretTile : BaseTile +{ + private Sprite2D _spriteBarrel; + + public override void _Ready() + { + base._Ready(); + + _spriteBarrel = GetNodeOrNull("Barrel"); + } + + public override void SetGhostMode(bool canPlace) + { + base.SetGhostMode(canPlace); + + if (_spriteBarrel != null) + _spriteBarrel.Modulate = canPlace + ? new Color(0, 1, 0, 0.5f) + : new Color(1, 0, 0, 0.5f); + } + + public override void FinalizePlacement() + { + base.FinalizePlacement(); + + if (_spriteBarrel != null) + _spriteBarrel.Modulate = Colors.White; + } +} \ No newline at end of file diff --git a/Scripts/Tiles/TurretTile.cs.uid b/Scripts/Tiles/TurretTile.cs.uid new file mode 100644 index 0000000..8b03fa7 --- /dev/null +++ b/Scripts/Tiles/TurretTile.cs.uid @@ -0,0 +1 @@ +uid://n5g6i0uovxfk