Vesna can walk diagonally now
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=476 format=3 uid="uid://c25udixd5m6l0"]
|
||||
[gd_scene load_steps=477 format=3 uid="uid://c25udixd5m6l0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b05uyj001ehwi" path="res://scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs" id="1_yd5ep"]
|
||||
[ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/Player2D.cs" id="2_1vqmv"]
|
||||
[ext_resource type="Script" uid="uid://cjbclkxesh3hc" path="res://scripts/CSharp/Common/CharacterControls/PlayerMovement.cs" id="2_1vqmv"]
|
||||
[ext_resource type="Script" uid="uid://n7oihifvqp23" path="res://scripts/CSharp/Common/Animation/VesnaAnimations.cs" id="3_f6xmn"]
|
||||
[ext_resource type="Texture2D" uid="uid://7jrac5ii3ah3" path="res://art/animation/Vesna2D/Vesna Anims Sequences/B01-Idle/0001.png" id="3_tb2wl"]
|
||||
[ext_resource type="Texture2D" uid="uid://c06b551t2qlo6" path="res://art/animation/Vesna2D/Vesna Anims Sequences/B01-Idle/0002.png" id="4_dy5kt"]
|
||||
[ext_resource type="Texture2D" uid="uid://bj2ssu0ixr0p1" path="res://art/animation/Vesna2D/Vesna Anims Sequences/B01-Idle/0004.png" id="6_3sina"]
|
||||
@@ -2071,14 +2072,12 @@ script = ExtResource("1_yd5ep")
|
||||
_farmingControls = NodePath("FarmingControls")
|
||||
_player2d = NodePath("CharacterBody2D")
|
||||
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." node_paths=PackedStringArray("_sprite", "_wateringParticles") groups=["PlantGrowing"]]
|
||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." groups=["PlantGrowing"]]
|
||||
position = Vector2(0, 374)
|
||||
collision_layer = 4
|
||||
collision_mask = 3
|
||||
script = ExtResource("2_1vqmv")
|
||||
_speed = 1500.0
|
||||
_sprite = NodePath("visuals/Animated Sprites")
|
||||
_wateringParticles = NodePath("../pouring water vfx")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"]
|
||||
z_index = 1
|
||||
@@ -2087,8 +2086,11 @@ position = Vector2(-24, -13)
|
||||
shape = SubResource("CircleShape2D_ssqtd")
|
||||
debug_color = Color(0.923708, 0.202722, 0.475262, 0.42)
|
||||
|
||||
[node name="visuals" type="Node2D" parent="CharacterBody2D"]
|
||||
[node name="visuals" type="Node2D" parent="CharacterBody2D" node_paths=PackedStringArray("_sprite", "_wateringParticles")]
|
||||
position = Vector2(0, -374)
|
||||
script = ExtResource("3_f6xmn")
|
||||
_sprite = NodePath("Animated Sprites")
|
||||
_wateringParticles = NodePath("../../pouring water vfx")
|
||||
|
||||
[node name="Animated Sprites" type="AnimatedSprite2D" parent="CharacterBody2D/visuals"]
|
||||
position = Vector2(0, 450)
|
||||
|
||||
@@ -31,6 +31,7 @@ InventoryManager="*res://scripts/CSharp/Common/Inventory/InventoryManager.cs"
|
||||
Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd"
|
||||
QuestManager="*res://scripts/CSharp/Common/Quest/QuestManager.cs"
|
||||
FightManagerAutoload="*res://prefabs/fight/fight_manager_autoload.tscn"
|
||||
InputService="*res://scripts/CSharp/Common/Services/InputService.cs"
|
||||
|
||||
[dialogic]
|
||||
|
||||
|
||||
+12
-33
@@ -1,30 +1,19 @@
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
namespace Babushka.scripts.CSharp.Common.Animation;
|
||||
|
||||
public partial class Player2D : CharacterBody2D
|
||||
public partial class VesnaAnimations : Node
|
||||
{
|
||||
[Export] private float _speed = 100f;
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
[Export] private SceneTree.GroupCallFlags _fieldFlags;
|
||||
[Export] private CpuParticles2D _wateringParticles;
|
||||
|
||||
// -1 means no tool.
|
||||
private int _toolID = -1;
|
||||
private string _toolString;
|
||||
private bool anyActionPressed;
|
||||
private bool _canHandleInput = true;
|
||||
private string _toolString;
|
||||
private int _toolID = -1; // -1 means no tool.
|
||||
private Vector2 _lastDirection = Vector2.Zero;
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
public bool InputEnabled
|
||||
{
|
||||
get => _canHandleInput;
|
||||
set => _canHandleInput = value;
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -37,12 +26,11 @@ public partial class Player2D : CharacterBody2D
|
||||
PlayPickUpAnimation();
|
||||
}
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
anyActionPressed = false;
|
||||
|
||||
if (!_canHandleInput)
|
||||
if (!InputService.Instance.InputEnabled)
|
||||
return;
|
||||
|
||||
bool right = Input.IsActionPressed("move_right");
|
||||
@@ -53,8 +41,6 @@ public partial class Player2D : CharacterBody2D
|
||||
|
||||
if (up)
|
||||
{
|
||||
Velocity = new Vector2(0, -_speed);
|
||||
MoveAndSlide();
|
||||
_sprite.Animation = "back walking" + _toolString;
|
||||
anyActionPressed = true;
|
||||
_lastDirection = Vector2.Up;
|
||||
@@ -63,8 +49,6 @@ public partial class Player2D : CharacterBody2D
|
||||
|
||||
if (down && !walkingAnimationPicked)
|
||||
{
|
||||
Velocity = new Vector2(0, _speed);
|
||||
MoveAndSlide();
|
||||
_sprite.Animation = "front walking" + _toolString;
|
||||
anyActionPressed = true;
|
||||
_lastDirection = Vector2.Down;
|
||||
@@ -73,8 +57,6 @@ public partial class Player2D : CharacterBody2D
|
||||
|
||||
if (right && !walkingAnimationPicked)
|
||||
{
|
||||
Velocity = new Vector2(_speed, 0);
|
||||
MoveAndSlide();
|
||||
_sprite.FlipH = false;
|
||||
_sprite.Animation = "side walking" + _toolString;
|
||||
anyActionPressed = true;
|
||||
@@ -84,8 +66,6 @@ public partial class Player2D : CharacterBody2D
|
||||
|
||||
if (left && !walkingAnimationPicked)
|
||||
{
|
||||
Velocity = new Vector2(-_speed, 0);
|
||||
MoveAndSlide();
|
||||
_sprite.FlipH = true;
|
||||
_sprite.Animation = "side walking" + _toolString;
|
||||
anyActionPressed = true;
|
||||
@@ -152,11 +132,11 @@ public partial class Player2D : CharacterBody2D
|
||||
/// </summary>
|
||||
public void PlayWateringAnimation()
|
||||
{
|
||||
if (_toolID == 1 && _canHandleInput)
|
||||
if (_toolID == 1 && InputService.Instance.InputEnabled)
|
||||
{
|
||||
_sprite.Animation = "diagonal wateringcan";
|
||||
_sprite.Play();
|
||||
_canHandleInput = false;
|
||||
InputService.Instance.InputEnabled = false;
|
||||
_wateringParticles.Emitting = true;
|
||||
Task.Run(DelayedInputHandlerReset);
|
||||
}
|
||||
@@ -166,14 +146,14 @@ public partial class Player2D : CharacterBody2D
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
_wateringParticles.Emitting = false;
|
||||
_canHandleInput = true;
|
||||
InputService.Instance.InputEnabled = true;
|
||||
}
|
||||
|
||||
public void PlayPickUpAnimation()
|
||||
{
|
||||
_sprite.Animation = "side pickup";
|
||||
_sprite.Play();
|
||||
_canHandleInput = false;
|
||||
InputService.Instance.InputEnabled = false;
|
||||
Task.Run(DelayedInputHandlerReset);
|
||||
}
|
||||
|
||||
@@ -181,7 +161,7 @@ public partial class Player2D : CharacterBody2D
|
||||
{
|
||||
_sprite.Animation = "diagonal farming";
|
||||
_sprite.Play();
|
||||
_canHandleInput = false;
|
||||
InputService.Instance.InputEnabled = false;
|
||||
Task.Run(DelayedInputHandlerReset);
|
||||
}
|
||||
|
||||
@@ -190,10 +170,9 @@ public partial class Player2D : CharacterBody2D
|
||||
{
|
||||
_sprite.Animation = "back interact";
|
||||
_sprite.Play();
|
||||
_canHandleInput = false;
|
||||
_lastDirection = Vector2.Up;
|
||||
InputService.Instance.InputEnabled = false;
|
||||
Task.Run(DelayedInputHandlerReset);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://n7oihifvqp23
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class PlayerMovement : CharacterBody2D
|
||||
{
|
||||
[Export] private float _speed = 1000f;
|
||||
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
bool anyActionPressed = false;
|
||||
Vector2 currentVelocity = Vector2.Zero;
|
||||
|
||||
if (!InputService.Instance.InputEnabled)
|
||||
return;
|
||||
|
||||
bool right = Input.IsActionPressed("move_right");
|
||||
bool left = Input.IsActionPressed("move_left");
|
||||
bool up = Input.IsActionPressed("move_up");
|
||||
bool down = Input.IsActionPressed("move_down");
|
||||
|
||||
if (up)
|
||||
{
|
||||
currentVelocity += new Vector2(0, -_speed);
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (down)
|
||||
{
|
||||
currentVelocity += new Vector2(0, _speed);
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (right)
|
||||
{
|
||||
currentVelocity += new Vector2(_speed, 0);
|
||||
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (left)
|
||||
{
|
||||
currentVelocity += new Vector2(-_speed, 0);
|
||||
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (anyActionPressed)
|
||||
{
|
||||
Velocity = currentVelocity;
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public partial class PlantBehaviour2D : Node2D
|
||||
if (_field.FieldState != FieldState.Watered || _magicWordSaid != _magicWordNeeded)
|
||||
return;
|
||||
|
||||
GetTree().CallGroup("PlantGrowing", Player2D.MethodName.PlayFarmingAnimation);
|
||||
//GetTree().CallGroup("PlantGrowing", PlayerMovement.MethodName.PlayFarmingAnimation);
|
||||
// todo:
|
||||
// find out why the last plant stage is being skipped the second time around
|
||||
switch (_state)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Babushka.scripts.CSharp.Common.Animation;
|
||||
using Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
@@ -9,7 +11,8 @@ public partial class VesnaBehaviour2D : Node
|
||||
[ExportGroup("Farming")]
|
||||
[Export] private FieldService2D _fieldParent;
|
||||
[Export] private FarmingControls2D _farmingControls;
|
||||
[Export] private Player2D _player2d;
|
||||
[Export] private PlayerMovement _player2d;
|
||||
[Export] private VesnaAnimations _vesnaAnimations;
|
||||
[Export] private ItemResource _hoe;
|
||||
[Export] private ItemResource _wateringCan;
|
||||
|
||||
@@ -77,7 +80,7 @@ public partial class VesnaBehaviour2D : Node
|
||||
if (toolId == 1)
|
||||
{
|
||||
_farmingControls.FillWateringCan();
|
||||
_player2d.PlayWateringCanFillupAnimation();
|
||||
_vesnaAnimations.PlayWateringCanFillupAnimation();
|
||||
EmitSignal(SignalName.FilledWateringCan);
|
||||
}
|
||||
}
|
||||
@@ -85,18 +88,18 @@ public partial class VesnaBehaviour2D : Node
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Enables the character movement in the Player2D script.
|
||||
/// Enables the input.
|
||||
/// </summary>
|
||||
public void EnableMovement()
|
||||
{
|
||||
_player2d.InputEnabled = true;
|
||||
InputService.Instance.InputEnabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables the character movement in the Player2D script.
|
||||
/// Disables the input.
|
||||
/// </summary>
|
||||
public void DisableMovement()
|
||||
{
|
||||
_player2d.InputEnabled = false;
|
||||
InputService.Instance.InputEnabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Services;
|
||||
|
||||
public partial class InputService : Node
|
||||
{
|
||||
public static InputService Instance { get; private set; } = null!;
|
||||
|
||||
[Signal]
|
||||
public delegate void InputEnabledChangedEventHandler(bool enabled);
|
||||
|
||||
private static bool _inputEnabled = true;
|
||||
|
||||
public bool InputEnabled
|
||||
{
|
||||
get => _inputEnabled;
|
||||
set
|
||||
{
|
||||
if (_inputEnabled != value)
|
||||
{
|
||||
CallDeferred(nameof(SetInputEnabled), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetInputEnabled(bool enabled)
|
||||
{
|
||||
_inputEnabled = enabled;
|
||||
EmitSignal(SignalName.InputEnabledChanged, _inputEnabled);
|
||||
}
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://blmbgmdv4aui8
|
||||
Reference in New Issue
Block a user