Make Doc dodge projectiles during lance state

master
John Montagu, the 4th Earl of Sandvich 2024-10-11 12:24:13 -07:00
parent b54ce905ab
commit feec74fa65
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 52 additions and 9 deletions

View File

@ -10,9 +10,6 @@ public partial class Doc : Boss
public AnimationPlayer MiscAnimation { get; set; } public AnimationPlayer MiscAnimation { get; set; }
[Export]
public Items.Weapons.Sword Lance { get; set; }
[Export] [Export]
public override bool IsActive public override bool IsActive
{ {
@ -109,7 +106,7 @@ public partial class Doc : Boss
if (name == "Doc") if (name == "Doc")
{ {
IsActive = true; IsActive = true;
Inventory.SelectedItem = Lance; Inventory.SelectedItem = GetNode<Items.Item>("%DocLance");
} }
}; };
@ -122,7 +119,7 @@ public partial class Doc : Boss
if (this.GetWorld().CurrentPlayer.IsAlive && !IsActive) if (this.GetWorld().CurrentPlayer.IsAlive && !IsActive)
{ {
IsActive = true; IsActive = true;
Inventory.SelectedItem = Lance; Inventory.SelectedItem = GetNode<Items.Item>("%DocLance");
} }
}; };
} }

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=71 format=3 uid="uid://d2skjvvx6fal0"] [gd_scene load_steps=72 format=3 uid="uid://d2skjvvx6fal0"]
[ext_resource type="Script" path="res://Characters/Doc.cs" id="2_3elet"] [ext_resource type="Script" path="res://Characters/Doc.cs" id="2_3elet"]
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_5jxom"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_5jxom"]
@ -568,14 +568,16 @@ size = Vector2(16, 19)
[sub_resource type="CircleShape2D" id="CircleShape2D_8hwat"] [sub_resource type="CircleShape2D" id="CircleShape2D_8hwat"]
radius = 16.0 radius = 16.0
[node name="Doc" type="CharacterBody2D" node_paths=PackedStringArray("Lance", "BossStateMachine", "DefaultSelectedItem", "ThinkerStateMachine", "Stats", "Sprite", "Inventory", "StateMachine", "Hurtbox")] [sub_resource type="CircleShape2D" id="CircleShape2D_kap5k"]
radius = 48.0
[node name="Doc" type="CharacterBody2D" node_paths=PackedStringArray("BossStateMachine", "DefaultSelectedItem", "ThinkerStateMachine", "Stats", "Sprite", "Inventory", "StateMachine", "Hurtbox")]
y_sort_enabled = true y_sort_enabled = true
texture_filter = 3 texture_filter = 3
material = SubResource("ShaderMaterial_7n7iy") material = SubResource("ShaderMaterial_7n7iy")
collision_layer = 10 collision_layer = 10
collision_mask = 17 collision_mask = 17
script = ExtResource("2_3elet") script = ExtResource("2_3elet")
Lance = NodePath("Inventory/DocLance")
BossStateMachine = NodePath("BossStateMachine") BossStateMachine = NodePath("BossStateMachine")
BossName = "Doc, The Two-Time" BossName = "Doc, The Two-Time"
Music = ExtResource("3_qnxmu") Music = ExtResource("3_qnxmu")
@ -698,8 +700,9 @@ InitialState = NodePath("Attack")
script = ExtResource("21_ij3bp") script = ExtResource("21_ij3bp")
NPC = NodePath("../..") NPC = NodePath("../..")
[node name="DashDefensive" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("NPC")] [node name="DashDefensive" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("ProjectileDetection", "NPC")]
script = ExtResource("20_12htp") script = ExtResource("20_12htp")
ProjectileDetection = NodePath("../../ProjectileDetection")
MaxDistanceToTarget = 256.0 MaxDistanceToTarget = 256.0
UseItemDistance = 64.0 UseItemDistance = 64.0
NPC = NodePath("../..") NPC = NodePath("../..")
@ -820,5 +823,13 @@ offset_bottom = -14.0
[node name="Label" parent="InteractionTrigger/Popup" index="0"] [node name="Label" parent="InteractionTrigger/Popup" index="0"]
text = "Duel" text = "Duel"
[node name="ProjectileDetection" type="Area2D" parent="."]
unique_name_in_owner = true
collision_layer = 0
collision_mask = 256
[node name="CollisionShape2D" type="CollisionShape2D" parent="ProjectileDetection"]
shape = SubResource("CircleShape2D_kap5k")
[editable path="Hurtbox"] [editable path="Hurtbox"]
[editable path="InteractionTrigger"] [editable path="InteractionTrigger"]

View File

@ -9,14 +9,49 @@ public partial class DashDefensive : AttackState
protected bool _dashedAway = false; protected bool _dashedAway = false;
protected State.Character.CharacterDashState _dashState; protected State.Character.CharacterDashState _dashState;
protected float _originalDashModifier; protected float _originalDashModifier;
private Callable _dodgeCallable;
[Export]
public Area2D ProjectileDetection { get; set; }
public override void _Ready() public override void _Ready()
{ {
_dashState = NPC.StateMachine.FindChildOfType<CharacterDashState>(); _dashState = NPC.StateMachine.FindChildOfType<CharacterDashState>();
_originalDashModifier = _dashState.VelocityModifier; _originalDashModifier = _dashState.VelocityModifier;
_dodgeCallable = new Callable(this, MethodName.DodgeProjectile);
base._Ready(); base._Ready();
} }
public override IState<ThinkerState> Enter(IState<ThinkerState> prev)
{
ProjectileDetection?.Connect(Area2D.SignalName.AreaEntered,
_dodgeCallable);
return base.Enter(prev);
}
public override void Exit(IState<ThinkerState> prev)
{
ProjectileDetection?.Disconnect(Area2D.SignalName.AreaEntered,
_dodgeCallable);
base.Exit(prev);
}
private void DodgeProjectile(Area2D area)
{
if (area is BoundingBoxes.Hitbox hitbox)
{
if (hitbox.GetOwner() is Entities.Projectile projectile)
{
GD.Print("changing direction");
var direction = projectile.Direction;
DashTo(direction.Rotated(Mathf.Pi / 2));
}
}
}
public override ThinkerState Think() public override ThinkerState Think()
{ {
Characters.Character bestTarget = NPC.FindBestTarget(); Characters.Character bestTarget = NPC.FindBestTarget();