move swordstate into weaponstate

pull/3/head
John Montagu, the 4th Earl of Sandvich 2023-05-26 17:42:50 -07:00
parent 41af6baa13
commit 23e93eb674
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
12 changed files with 85 additions and 55 deletions

View File

@ -2,7 +2,7 @@ using Godot;
using SupaLidlGame.BoundingBoxes; using SupaLidlGame.BoundingBoxes;
using SupaLidlGame.Characters; using SupaLidlGame.Characters;
using SupaLidlGame.Extensions; using SupaLidlGame.Extensions;
using SupaLidlGame.State.Sword; using SupaLidlGame.State.Weapon;
namespace SupaLidlGame.Items.Weapons namespace SupaLidlGame.Items.Weapons
{ {
@ -42,7 +42,7 @@ namespace SupaLidlGame.Items.Weapons
public double NPCAnticipateTime { get; set; } public double NPCAnticipateTime { get; set; }
[Export] [Export]
public SwordStateMachine StateMachine { get; set; } public WeaponStateMachine StateMachine { get; set; }
public override bool IsParryable { get; protected set; } public override bool IsParryable { get; protected set; }

View File

@ -1,13 +1,13 @@
[gd_scene load_steps=35 format=3 uid="uid://d72ehtv1ks0e"] [gd_scene load_steps=35 format=3 uid="uid://dvqap2uhcah63"]
[ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mlo73"] [ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mlo73"]
[ext_resource type="Script" path="res://State/Sword/SwordStateMachine.cs" id="2_rje2m"] [ext_resource type="Script" path="res://State/Weapon/WeaponStateMachine.cs" id="2_vwirq"]
[ext_resource type="Script" path="res://State/Sword/SwordIdleState.cs" id="3_qh2cs"] [ext_resource type="Script" path="res://State/Weapon/SwordIdleState.cs" id="3_nw6r0"]
[ext_resource type="Texture2D" uid="uid://dp7osg05ip5oo" path="res://Assets/Sprites/sword.png" id="3_r75ni"] [ext_resource type="Texture2D" uid="uid://dp7osg05ip5oo" path="res://Assets/Sprites/sword.png" id="3_r75ni"]
[ext_resource type="PackedScene" uid="uid://du5vhccg75nrq" path="res://BoundingBoxes/Hitbox.tscn" id="3_up3ob"] [ext_resource type="PackedScene" uid="uid://du5vhccg75nrq" path="res://BoundingBoxes/Hitbox.tscn" id="3_up3ob"]
[ext_resource type="Script" path="res://State/Weapon/SwordAnticipateState.cs" id="4_j3cud"]
[ext_resource type="PackedScene" uid="uid://cojxmcin13ihm" path="res://Utils/Trail.tscn" id="4_pt6lq"] [ext_resource type="PackedScene" uid="uid://cojxmcin13ihm" path="res://Utils/Trail.tscn" id="4_pt6lq"]
[ext_resource type="Script" path="res://State/Sword/SwordAnticipateState.cs" id="4_ycuhw"] [ext_resource type="Script" path="res://State/Weapon/SwordAttackState.cs" id="5_hmisb"]
[ext_resource type="Script" path="res://State/Sword/SwordAttackState.cs" id="5_30003"]
[ext_resource type="Texture2D" uid="uid://do1bui3bblkk7" path="res://Assets/Sprites/sword-swing.png" id="5_pywek"] [ext_resource type="Texture2D" uid="uid://do1bui3bblkk7" path="res://Assets/Sprites/sword-swing.png" id="5_pywek"]
[ext_resource type="AudioStream" uid="uid://c4n7ioxpukdwi" path="res://Assets/Sounds/parry.wav" id="6_8nxjm"] [ext_resource type="AudioStream" uid="uid://c4n7ioxpukdwi" path="res://Assets/Sounds/parry.wav" id="6_8nxjm"]
@ -350,21 +350,21 @@ Knockback = 64.0
Anchor = NodePath("Anchor") Anchor = NodePath("Anchor")
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")] [node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_rje2m") script = ExtResource("2_vwirq")
InitialState = NodePath("Idle") InitialState = NodePath("Idle")
[node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("AnticipateState", "Sword")] [node name="Idle" type="Node" parent="State" node_paths=PackedStringArray("AnticipateState", "Sword")]
script = ExtResource("3_qh2cs") script = ExtResource("3_nw6r0")
AnticipateState = NodePath("../Anticipate") AnticipateState = NodePath("../Anticipate")
Sword = NodePath("../..") Sword = NodePath("../..")
[node name="Anticipate" type="Node" parent="State" node_paths=PackedStringArray("Sword", "AttackState")] [node name="Anticipate" type="Node" parent="State" node_paths=PackedStringArray("Sword", "AttackState")]
script = ExtResource("4_ycuhw") script = ExtResource("4_j3cud")
Sword = NodePath("../..") Sword = NodePath("../..")
AttackState = NodePath("../Attack") AttackState = NodePath("../Attack")
[node name="Attack" type="Node" parent="State" node_paths=PackedStringArray("Sword", "AnticipateState", "IdleState")] [node name="Attack" type="Node" parent="State" node_paths=PackedStringArray("Sword", "AnticipateState", "IdleState")]
script = ExtResource("5_30003") script = ExtResource("5_hmisb")
Sword = NodePath("../..") Sword = NodePath("../..")
AnticipateState = NodePath("../Anticipate") AnticipateState = NodePath("../Anticipate")
IdleState = NodePath("../Idle") IdleState = NodePath("../Idle")

View File

@ -1,5 +1,4 @@
using Godot; using Godot;
using SupaLidlGame.Items;
namespace SupaLidlGame.State.Character namespace SupaLidlGame.State.Character
{ {
@ -29,7 +28,7 @@ namespace SupaLidlGame.State.Character
{ {
if (@event.IsActionPressed("roll")) if (@event.IsActionPressed("roll"))
{ {
if (Character.Inventory.SelectedItem is Weapon weapon) if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{ {
if (!weapon.IsUsing) if (!weapon.IsUsing)
{ {

View File

@ -1,5 +1,4 @@
using Godot; using Godot;
using SupaLidlGame.Items;
using SupaLidlGame.Characters; using SupaLidlGame.Characters;
namespace SupaLidlGame.State.Character namespace SupaLidlGame.State.Character
@ -33,7 +32,7 @@ namespace SupaLidlGame.State.Character
"ui_up", "ui_down"); "ui_up", "ui_down");
Vector2 mousePos = Character.GetGlobalMousePosition(); Vector2 mousePos = Character.GetGlobalMousePosition();
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos); Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
if (Character.Inventory.SelectedItem is Weapon weapon) if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{ {
if (!weapon.IsUsing) if (!weapon.IsUsing)
{ {

View File

@ -1,18 +0,0 @@
using Godot;
namespace SupaLidlGame.State.Sword
{
public abstract partial class SwordState : Node, IState<SwordState>
{
public virtual SwordState Use() => null;
public abstract IState<SwordState> Enter(IState<SwordState> previousState);
public virtual void Exit(IState<SwordState> nextState)
{
}
public virtual IState<SwordState> Process(double delta) => null;
}
}

View File

@ -1,8 +1,8 @@
using Godot; using Godot;
namespace SupaLidlGame.State.Sword namespace SupaLidlGame.State.Weapon
{ {
public partial class SwordAnticipateState : SwordState public partial class SwordAnticipateState : WeaponState
{ {
[Export] [Export]
public SupaLidlGame.Items.Weapons.Sword Sword { get; set; } public SupaLidlGame.Items.Weapons.Sword Sword { get; set; }
@ -12,7 +12,7 @@ namespace SupaLidlGame.State.Sword
private double _anticipateTime; private double _anticipateTime;
public override SwordState Enter(IState<SwordState> prevState) public override WeaponState Enter(IState<WeaponState> prevState)
{ {
Sword.EnableParry(); Sword.EnableParry();
@ -33,7 +33,7 @@ namespace SupaLidlGame.State.Sword
return null; return null;
} }
public override SwordState Process(double delta) public override WeaponState Process(double delta)
{ {
// go into attack state if anticipation time is delta // go into attack state if anticipation time is delta
if ((_anticipateTime -= delta) <= 0) if ((_anticipateTime -= delta) <= 0)

View File

@ -1,8 +1,8 @@
using Godot; using Godot;
namespace SupaLidlGame.State.Sword namespace SupaLidlGame.State.Weapon
{ {
public partial class SwordAttackState : SwordState public partial class SwordAttackState : WeaponState
{ {
[Export] [Export]
public SupaLidlGame.Items.Weapons.Sword Sword { get; set; } public SupaLidlGame.Items.Weapons.Sword Sword { get; set; }
@ -21,7 +21,7 @@ namespace SupaLidlGame.State.Sword
private bool _isAlternate = false; private bool _isAlternate = false;
public override SwordState Enter(IState<SwordState> prevState) public override WeaponState Enter(IState<WeaponState> prevState)
{ {
//Sword.AnimationPlayer.Stop(); //Sword.AnimationPlayer.Stop();
Sword.Attack(); Sword.Attack();
@ -46,12 +46,12 @@ namespace SupaLidlGame.State.Sword
return null; return null;
} }
public override void Exit(IState<SwordState> nextState) public override void Exit(IState<WeaponState> nextState)
{ {
Sword.Deattack(); Sword.Deattack();
} }
public override SwordState Use() public override WeaponState Use()
{ {
if (_useDuration <= 0) if (_useDuration <= 0)
{ {
@ -66,7 +66,7 @@ namespace SupaLidlGame.State.Sword
return null; return null;
} }
public override SwordState Process(double delta) public override WeaponState Process(double delta)
{ {
if (_attackDuration > 0) if (_attackDuration > 0)
{ {

View File

@ -1,8 +1,8 @@
using Godot; using Godot;
namespace SupaLidlGame.State.Sword namespace SupaLidlGame.State.Weapon
{ {
public partial class SwordIdleState : SwordState public partial class SwordIdleState : WeaponState
{ {
[Export] [Export]
public SwordAnticipateState AnticipateState { get; set; } public SwordAnticipateState AnticipateState { get; set; }
@ -12,7 +12,7 @@ namespace SupaLidlGame.State.Sword
private double _attackCooldown; private double _attackCooldown;
public override SwordState Enter(IState<SwordState> prevState) public override WeaponState Enter(IState<WeaponState> prevState)
{ {
if (prevState is SwordAttackState) if (prevState is SwordAttackState)
{ {
@ -21,7 +21,7 @@ namespace SupaLidlGame.State.Sword
return null; return null;
} }
public override SwordState Use() public override WeaponState Use()
{ {
if (_attackCooldown <= 0) if (_attackCooldown <= 0)
{ {
@ -31,7 +31,7 @@ namespace SupaLidlGame.State.Sword
return AnticipateState; return AnticipateState;
} }
public override SwordState Process(double delta) public override WeaponState Process(double delta)
{ {
if (_attackCooldown > 0) if (_attackCooldown > 0)
{ {

View File

@ -0,0 +1,5 @@
using Godot;
namespace SupaLidlGame.State.Weapon
{
}

View File

@ -1,11 +1,10 @@
using Godot; using Godot;
namespace SupaLidlGame.State.Sword namespace SupaLidlGame.State.Weapon
{ {
public partial class SwordStateMachine : StateMachine<SwordState> }
{
[Export] /*
public override SwordState InitialState { get; set; }
public void Use() public void Use()
{ {
@ -24,5 +23,5 @@ namespace SupaLidlGame.State.Sword
ChangeState(s); ChangeState(s);
} }
} }
}
} */

View File

@ -0,0 +1,18 @@
using Godot;
namespace SupaLidlGame.State.Weapon
{
public abstract partial class WeaponState : Node, IState<WeaponState>
{
public virtual WeaponState Use() => null;
public abstract IState<WeaponState> Enter(IState<WeaponState> previousState);
public virtual void Exit(IState<WeaponState> nextState)
{
}
public virtual IState<WeaponState> Process(double delta) => null;
}
}

View File

@ -0,0 +1,28 @@
using Godot;
namespace SupaLidlGame.State.Weapon
{
public partial class WeaponStateMachine : StateMachine<WeaponState>
{
[Export]
public override WeaponState InitialState { get; set; }
public void Use()
{
var state = CurrentState.Use();
if (state is not null)
{
ChangeState(state);
}
}
public void Process(double delta)
{
var state = CurrentState.Process(delta);
if (state is WeaponState s)
{
ChangeState(s);
}
}
}
}