Files
godot-host-test/Game/Turret/Turret.cs
T
redglow fc1df2f740 .
2026-07-27 19:51:17 +02:00

38 lines
1.3 KiB
C#

using Godot;
using GodotHostTest.AetherBind;
using Microsoft.Extensions.Logging;
using OwofGames.AetherBind;
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()
{
var projectile = _sceneInstantiator.Instantiate<Node2D>(_projectilePackedScene);
projectile.Rotation = _launcher.Rotation;
AddChild(projectile);
_logger.LogInformation("Projectile launched.");
}
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);
}
}