Throw item
This commit is contained in:
@@ -98,6 +98,10 @@ namespace GameJamDungeon
|
||||
.Handle((in PlayerLogic.Output.Animations.Attack output) =>
|
||||
{
|
||||
AnimationPlayer.Play("attack");
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
||||
{
|
||||
ThrowItem();
|
||||
});
|
||||
|
||||
this.Provide();
|
||||
@@ -137,6 +141,16 @@ namespace GameJamDungeon
|
||||
return input with { Y = 0f };
|
||||
}
|
||||
|
||||
public void ThrowItem()
|
||||
{
|
||||
var itemScene = GD.Load<PackedScene>("res://src/items/throwable/ThrowableItem.tscn");
|
||||
var throwItem = itemScene.Instantiate<IThrowableItem>();
|
||||
GetTree().Root.AddChildEx(throwItem);
|
||||
throwItem.GlobalPosition = GameRepo.PlayerGlobalPosition.Value;
|
||||
throwItem.GlobalRotation = GlobalRotation;
|
||||
throwItem.AnimationPlayer.Play("throw");
|
||||
}
|
||||
|
||||
public void OnAnimationFinished(StringName animation)
|
||||
{
|
||||
GD.Print("Attack finished");
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace GameJamDungeon
|
||||
}
|
||||
|
||||
public readonly record struct MovementComputed(Basis Rotation, Vector3 Velocity);
|
||||
|
||||
public readonly record struct ThrowItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace GameJamDungeon
|
||||
if (Godot.Input.IsActionPressed(GameInputs.Sprint))
|
||||
velocity *= 3;
|
||||
|
||||
if (Godot.Input.IsActionJustPressed(GameInputs.Throw))
|
||||
Output(new Output.ThrowItem());
|
||||
|
||||
Output(new Output.MovementComputed(transform.Basis, velocity));
|
||||
|
||||
return ToSelf();
|
||||
|
||||
Reference in New Issue
Block a user