This commit is contained in:
redglow
2026-07-27 19:51:17 +02:00
parent dad5027e0e
commit fc1df2f740
8 changed files with 38 additions and 21 deletions
+3 -10
View File
@@ -8,13 +8,14 @@ namespace GodotHostTest.Game.Turret;
public partial class Turret : Sprite2D
{
[Export] private Node2D _launcher = null!;
[Inject] private ILogger<Turret> _logger = null!;
[Export] private PackedScene _projectilePackedScene = null!;
private double _rotationDirection;
[Export] private double _rotationSpeed = 6;
[Inject] private ISceneInstantiator _sceneInstantiator = null!;
[Export] private double _slowDownFactor = 0.3;
private void OnTimerTimeout()
{
@@ -24,20 +25,12 @@ public partial class Turret : Sprite2D
_logger.LogInformation("Projectile launched.");
}
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;
if (Input.IsActionPressed("slow_down")) _rotationDirection *= _slowDownFactor;
_launcher.Rotation += (float)(_rotationSpeed * delta * _rotationDirection);
base._PhysicsProcess(delta);
+3 -1
View File
@@ -12,8 +12,10 @@ 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")
_projectilePackedScene = ExtResource("3_eoix6")
_rotationSpeed = 4.0
_slowDownFactor = 0.5
[node name="Launcher" type="Sprite2D" parent="." unique_id=1492355681]
texture = ExtResource("4_q6l7p")