.
This commit is contained in:
+27
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user