added enemy attack
This commit is contained in:
parent
96bec5a6b7
commit
562a33bd8e
54 changed files with 1950 additions and 48 deletions
|
|
@ -5,7 +5,7 @@ using Chickensoft.LogicBlocks.Auto;
|
|||
namespace Dancer;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public sealed partial class Birb : CharacterBody2D, IAttackable
|
||||
public sealed partial class Birb : CharacterBody2D, IAttackable, IProvide<IHitboxOwner>, IHitboxOwner
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
|
|
@ -35,35 +35,13 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
|||
|
||||
public void OnReady()
|
||||
{
|
||||
this.Provide();
|
||||
SetPhysicsProcess(true);
|
||||
SetProcess(true);
|
||||
}
|
||||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
// _timeThought += (float)delta;
|
||||
// if (_timeThought >= ThinkTime)
|
||||
// {
|
||||
// _timeThought -= ThinkTime;
|
||||
// if (_target is not null)
|
||||
// {
|
||||
// var xDifference = _target.Position.X - Position.X;
|
||||
// var distance = Mathf.Abs(xDifference);
|
||||
// if (Mathf.Abs(distance - AttackDistance) > Speed * ThinkTime)
|
||||
// _targetVelocity = Mathf.Sign(xDifference) * Mathf.Sign(distance - AttackDistance) * Speed;
|
||||
// else
|
||||
// _targetVelocity = 0f;
|
||||
// BodySprite.FlipH = xDifference < 0;
|
||||
// }
|
||||
// else
|
||||
// _targetVelocity = 0f;
|
||||
// }
|
||||
//
|
||||
// Velocity = Velocity with
|
||||
// {
|
||||
// X = Mathf.MoveToward(Velocity.X, _targetVelocity, (float)delta * 500f)
|
||||
// };
|
||||
|
||||
Ai.Input(new Logic.Input.OnPhysicsProcess(delta));
|
||||
|
||||
if (!IsOnFloor()) Velocity += GetGravity() * (float)delta;
|
||||
|
|
@ -71,7 +49,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
|||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
public void OnProcess(double delta)
|
||||
{
|
||||
HealthBar.Value = _hp;
|
||||
HealthBar.Visible = _hp < MaxHp;
|
||||
|
|
@ -93,7 +71,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
|||
var targetVelocity = Mathf.Sign(xDifference) * speed;
|
||||
Velocity = Velocity with
|
||||
{
|
||||
X = Mathf.MoveToward(Velocity.X, targetVelocity, (float)delta * Acceleration)
|
||||
X = Mathf.MoveToward(Velocity.X, targetVelocity, (float)delta * Acceleration),
|
||||
};
|
||||
return speedRequiredToReachGoalNow < Speed;
|
||||
}
|
||||
|
|
@ -102,7 +80,7 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
|||
{
|
||||
Velocity = Velocity with
|
||||
{
|
||||
X = Mathf.MoveToward(Velocity.X, 0, (float)delta * Acceleration)
|
||||
X = Mathf.MoveToward(Velocity.X, 0, (float)delta * Acceleration),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -122,6 +100,20 @@ public sealed partial class Birb : CharacterBody2D, IAttackable
|
|||
if (_hp <= 0.01) QueueFree();
|
||||
}
|
||||
|
||||
IHitboxOwner IProvide<IHitboxOwner>.Value() => this;
|
||||
|
||||
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnBodyHit;
|
||||
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnBodyHit;
|
||||
private void OnBodyHit(Hitbox hitbox, Node2D body)
|
||||
{
|
||||
if (body is not IAttackable attackable) return;
|
||||
attackable.GetAttacked(new()
|
||||
{
|
||||
Attacker = this,
|
||||
Damage = 1f,
|
||||
});
|
||||
}
|
||||
|
||||
[Meta]
|
||||
public sealed partial class Logic : AutoBlock
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,16 +2,20 @@
|
|||
|
||||
[ext_resource type="Script" uid="uid://daowp76saltic" path="res://src/creatures/birb/Birb.cs" id="1_lyo8d"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://cyf7ij04grglc" path="res://src/creatures/birb/birb.aseprite" id="2_ba6cv"]
|
||||
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="3_bu42x"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8bh2b"]
|
||||
size = Vector2(22, 4)
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_feb5d"]
|
||||
radius = 5.0
|
||||
height = 14.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_lyo8d"]
|
||||
radius = 52.0
|
||||
radius = 60.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ba6cv"]
|
||||
radius = 160.0
|
||||
radius = 180.00278
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_lyo8d"]
|
||||
bg_color = Color(0.15, 0.15, 0.15, 0.34509805)
|
||||
|
|
@ -46,6 +50,18 @@ tracks/1/keys = {
|
|||
"update": 1,
|
||||
"values": [0]
|
||||
}
|
||||
tracks/2/type = "value"
|
||||
tracks/2/imported = false
|
||||
tracks/2/enabled = true
|
||||
tracks/2/path = NodePath("Body/StabHitbox/CollisionShape2D:disabled")
|
||||
tracks/2/interp = 1
|
||||
tracks/2/loop_wrap = true
|
||||
tracks/2/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ba6cv"]
|
||||
resource_name = "idle"
|
||||
|
|
@ -146,6 +162,18 @@ tracks/2/keys = {
|
|||
"method": &"OnAttackFinished"
|
||||
}]
|
||||
}
|
||||
tracks/3/type = "value"
|
||||
tracks/3/imported = false
|
||||
tracks/3/enabled = true
|
||||
tracks/3/path = NodePath("Body/StabHitbox/CollisionShape2D:disabled")
|
||||
tracks/3/interp = 1
|
||||
tracks/3/loop_wrap = true
|
||||
tracks/3/keys = {
|
||||
"times": PackedFloat32Array(0, 0.5, 0.7),
|
||||
"transitions": PackedFloat32Array(1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [true, false, true]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1i6dk"]
|
||||
_data = {
|
||||
|
|
@ -166,6 +194,18 @@ sprite_frames = ExtResource("2_ba6cv")
|
|||
animation = &"idle"
|
||||
offset = Vector2(9, -4)
|
||||
|
||||
[node name="StabHitbox" type="Area2D" parent="Body" unique_id=1373491990]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 16
|
||||
collision_mask = 2
|
||||
script = ExtResource("3_bu42x")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/StabHitbox" unique_id=1331922714]
|
||||
position = Vector2(11, 2)
|
||||
shape = SubResource("RectangleShape2D_8bh2b")
|
||||
disabled = true
|
||||
debug_color = Color(0.8758822, 0.3187781, 0.34832907, 0.41960785)
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1744954023]
|
||||
position = Vector2(0, 1)
|
||||
shape = SubResource("CapsuleShape2D_feb5d")
|
||||
|
|
@ -185,6 +225,7 @@ collision_mask = 2
|
|||
monitorable = false
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Chase" unique_id=567870323]
|
||||
position = Vector2(-1, 0)
|
||||
shape = SubResource("CircleShape2D_ba6cv")
|
||||
debug_color = Color(0, 0.6, 0.69803923, 0)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue