This commit is contained in:
redglow
2026-07-21 20:49:24 +02:00
parent c540b99eb6
commit e7dbb9cabb
31 changed files with 394 additions and 76 deletions
+27 -2
View File
@@ -6,11 +6,36 @@ namespace GodotHostTest.Game.Turret;
public partial class Turret : Sprite2D
{
[Export] private Node2D _launcher = null!;
[Export] private PackedScene _projectilePackedScene = null!;
private double _rotationDirection;
[Export] private double _rotationSpeed = 6;
[Inject] private ISceneInstantiator _sceneInstantiator = null!;
public override void _Ready()
private void OnTimerTimeout()
{
GetTree().CreateTimer(1).Timeout += () => AddChild(_sceneInstantiator.Instantiate(_projectilePackedScene));
var projectile = _sceneInstantiator.Instantiate<Node2D>(_projectilePackedScene);
projectile.Rotation = _launcher.Rotation;
AddChild(projectile);
}
public override void _Input(InputEvent @event)
{
_rotationDirection = 0;
if (@event.IsActionPressed("rotate_clockwise")) _rotationDirection = 1;
if (@event.IsActionPressed("rotate_counterclockwise")) _rotationDirection = -1;
}
public override void _PhysicsProcess(double delta)
{
_rotationDirection = 0;
if (Input.IsActionPressed("rotate_clockwise")) _rotationDirection = 1;
if (Input.IsActionPressed("rotate_counterclockwise")) _rotationDirection = -1;
_launcher.Rotation += (float)(_rotationSpeed * delta * _rotationDirection);
base._PhysicsProcess(delta);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://wq1ylxxdyo3t"
path="res://.godot/imported/towerDefense_tile181.png-175b1fdaaa15393876652158f79f62d1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Game/Turret/towerDefense_tile181.png"
dest_files=["res://.godot/imported/towerDefense_tile181.png-175b1fdaaa15393876652158f79f62d1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ce3yr5qcy6tn8"
path="res://.godot/imported/towerDefense_tile206.png-1691c021ff92a454ed8143a8198835e0.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Game/Turret/towerDefense_tile206.png"
dest_files=["res://.godot/imported/towerDefense_tile206.png-1691c021ff92a454ed8143a8198835e0.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
+29
View File
@@ -0,0 +1,29 @@
[gd_scene format=3 uid="uid://cgixjjrc2kdui"]
[ext_resource type="Texture2D" uid="uid://wq1ylxxdyo3t" path="res://Game/Turret/towerDefense_tile181.png" id="1_fa2t6"]
[ext_resource type="Script" uid="uid://ce7gnp1lcrrdv" path="res://Game/Turret/Turret.cs" id="2_tkk1n"]
[ext_resource type="PackedScene" uid="uid://brbufibn7hi3o" path="res://Game/Projectile/projectile.tscn" id="3_eoix6"]
[ext_resource type="Texture2D" uid="uid://ce3yr5qcy6tn8" path="res://Game/Turret/towerDefense_tile206.png" id="4_q6l7p"]
[sub_resource type="Curve" id="Curve_u8d0v"]
_data = [Vector2(0, 1), 0.0, -1.0, 0, 1, Vector2(1, 0), -1.0, 0.0, 1, 0]
point_count = 2
[node name="Turret" type="Sprite2D" unique_id=682995021 node_paths=PackedStringArray("_launcher")]
texture = ExtResource("1_fa2t6")
script = ExtResource("2_tkk1n")
_projectilePackedScene = ExtResource("3_eoix6")
_launcher = NodePath("Launcher")
[node name="Launcher" type="Sprite2D" parent="." unique_id=1492355681]
texture = ExtResource("4_q6l7p")
[node name="Line2D" type="Line2D" parent="Launcher" unique_id=777442120]
points = PackedVector2Array(0, 0, 0, -270)
width_curve = SubResource("Curve_u8d0v")
default_color = Color(1, 0.1764706, 0.19215687, 0.38039216)
[node name="Timer" type="Timer" parent="." unique_id=95651717]
autostart = true
[connection signal="timeout" from="Timer" to="." method="OnTimerTimeout"]