Basic enemy attack pattern
This commit is contained in:
@@ -73,6 +73,8 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public ProgressBar VTBar { get; set; } = default!;
|
||||
|
||||
[Node] public IArea3D CollisionDetector { get; set; } = default!;
|
||||
|
||||
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; } = default!;
|
||||
@@ -112,6 +114,7 @@ namespace GameJamDungeon
|
||||
VTBar.Value = _currentVT.Value;
|
||||
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
CollisionDetector.AreaEntered += OnEnemyHitBoxEntered;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
@@ -144,6 +147,20 @@ namespace GameJamDungeon
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
private void OnEnemyHitBoxEntered(Area3D area)
|
||||
{
|
||||
if (area is IHitbox hitBox)
|
||||
{
|
||||
if (_currentHP.Value > 0)
|
||||
{
|
||||
var enemy = hitBox.GetParent<IEnemy>();
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(hitBox.Damage, PlayerStatInfo, enemy.EnemyStatInfo);
|
||||
_currentHP.OnNext(_currentHP.Value - damage);
|
||||
GD.Print($"Player hit for {damage} damage.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://cfecvvav8kkp6"]
|
||||
[gd_scene load_steps=20 format=3 uid="uid://cfecvvav8kkp6"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/player/Player.cs" id="1_xcol5"]
|
||||
[ext_resource type="Texture2D" uid="uid://bokx3h8kfdo5i" path="res://src/player/slash_0000_Classic_30.png" id="2_la11l"]
|
||||
@@ -115,6 +115,9 @@ bg_color = Color(0, 0.411765, 0, 1)
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_onron"]
|
||||
bg_color = Color(0, 0.411765, 0, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_hs4wf"]
|
||||
size = Vector3(1.94531, 2.43945, 1.08447)
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
collision_layer = 38
|
||||
collision_mask = 7
|
||||
@@ -209,3 +212,12 @@ custom_minimum_size = Vector2(0, 25)
|
||||
layout_mode = 2
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_onron")
|
||||
show_percentage = false
|
||||
|
||||
[node name="CollisionDetector" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 64
|
||||
collision_mask = 64
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CollisionDetector"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0479561, 0.982638, -0.04021)
|
||||
shape = SubResource("BoxShape3D_hs4wf")
|
||||
|
||||
Reference in New Issue
Block a user