Basic enemy attack pattern

This commit is contained in:
2024-09-04 23:05:49 -07:00
parent 6fc9568137
commit 54d9dcf9fa
14 changed files with 282 additions and 54 deletions

View File

@@ -84,6 +84,7 @@ Throw={
3d_physics/layer_4="Enemy" 3d_physics/layer_4="Enemy"
3d_physics/layer_5="Weapon" 3d_physics/layer_5="Weapon"
3d_physics/layer_6="Alert" 3d_physics/layer_6="Alert"
3d_physics/layer_7="PlayerHitbox"
[navigation] [navigation]
@@ -95,3 +96,4 @@ Throw={
3d/run_on_separate_thread=true 3d/run_on_separate_thread=true
common/physics_ticks_per_second=144 common/physics_ticks_per_second=144
3d/default_gravity=0.0

View File

@@ -19,6 +19,10 @@ public interface IEnemy : ICharacterBody3D
public NavigationAgent3D NavAgent { get; set; } public NavigationAgent3D NavAgent { get; set; }
public Area3D LineOfSight { get; set; } public Area3D LineOfSight { get; set; }
public AnimationPlayer AnimationPlayer { get; set; }
public Timer AttackTimer { get; set; }
} }
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
@@ -49,6 +53,10 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
[Node] public Timer PatrolTimer { get; set; } = default!; [Node] public Timer PatrolTimer { get; set; } = default!;
[Node] public Timer AttackTimer { get; set; } = default!;
[Node] public AnimationPlayer AnimationPlayer { get; set; } = default!;
public void Setup() public void Setup()
{ {
EnemyLogic = new EnemyLogic(); EnemyLogic = new EnemyLogic();
@@ -63,6 +71,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
CurrentHP.Sync += OnHPChanged; CurrentHP.Sync += OnHPChanged;
LineOfSight.BodyEntered += LineOfSight_BodyEntered; LineOfSight.BodyEntered += LineOfSight_BodyEntered;
PatrolTimer.Timeout += OnPatrolTimeout; PatrolTimer.Timeout += OnPatrolTimeout;
AttackTimer.Timeout += OnAttackTimeout;
var rng = new RandomNumberGenerator(); var rng = new RandomNumberGenerator();
rng.Randomize(); rng.Randomize();
PatrolTimer.WaitTime = rng.RandfRange(7.0f, 15.0f); PatrolTimer.WaitTime = rng.RandfRange(7.0f, 15.0f);
@@ -77,6 +86,17 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
PatrolTimer.WaitTime = rng.RandfRange(7.0f, 15.0f); PatrolTimer.WaitTime = rng.RandfRange(7.0f, 15.0f);
} }
private void OnAttackTimeout()
{
if (GlobalPosition.DistanceTo(GameRepo.PlayerGlobalPosition.Value) > 2.5f)
return;
var rng = new RandomNumberGenerator();
rng.Randomize();
EnemyLogic.Input(new EnemyLogic.Input.AttackTimer());
AttackTimer.WaitTime = rng.RandfRange(2f, 3.0f);
}
private void LineOfSight_BodyEntered(Node3D body) private void LineOfSight_BodyEntered(Node3D body)
{ {
EnemyLogic.Input(new EnemyLogic.Input.Alerted()); EnemyLogic.Input(new EnemyLogic.Input.Alerted());

View File

@@ -22,5 +22,14 @@ namespace GameJamDungeon
[Export] [Export]
public double ElementCResistance { get; set; } public double ElementCResistance { get; set; }
[Export]
public double BaseElementADamageBonus { get; set; }
[Export]
public double BaseElementBDamageBonus { get; set; }
[Export]
public double BaseElementCDamageBonus { get; set; }
} }
} }

View File

@@ -5,8 +5,11 @@
[resource] [resource]
script = ExtResource("1_oabqi") script = ExtResource("1_oabqi")
MaximumHP = 50.0 MaximumHP = 50.0
BaseAttack = 2 BaseAttack = 10
BaseDefense = 1 BaseDefense = 1
ElementAResistance = 15.0 ElementAResistance = 15.0
ElementBResistance = -20.0 ElementBResistance = -20.0
ElementCResistance = 0.0 ElementCResistance = 0.0
BaseElementADamageBonus = 0.0
BaseElementBDamageBonus = 0.0
BaseElementCDamageBonus = 0.0

View File

@@ -1,7 +1,8 @@
[gd_scene load_steps=10 format=4 uid="uid://dcgj5i52i76gj"] [gd_scene load_steps=15 format=4 uid="uid://dcgj5i52i76gj"]
[ext_resource type="Script" path="res://src/enemy/Enemy.cs" id="1_jw471"] [ext_resource type="Script" path="res://src/enemy/Enemy.cs" id="1_jw471"]
[ext_resource type="Resource" uid="uid://c8h26ip4ly18r" path="res://src/enemy/enemy_types/floating_enemy/FloatingEnemy.tres" id="2_ewaf6"] [ext_resource type="Resource" uid="uid://c8h26ip4ly18r" path="res://src/enemy/enemy_types/floating_enemy/FloatingEnemy.tres" id="2_ewaf6"]
[ext_resource type="Script" path="res://src/hitbox/Hitbox.cs" id="3_erpyl"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5tio6"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5tio6"]
resource_name = "Material.001" resource_name = "Material.001"
@@ -108,6 +109,70 @@ height = 1.0
height = 3.0 height = 3.0
radius = 1.0 radius = 1.0
[sub_resource type="Animation" id="Animation_ce86e"]
resource_name = "attack"
length = 0.7
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("DISSAPPEARING ENEMY:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.366667, 0.7),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(1, 1, 1), Vector3(1.77, 1.77, 1.77), Vector3(1, 1, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Hitbox/CollisionShape3D:disabled")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.3, 0.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 1,
"values": [true, false, true]
}
[sub_resource type="Animation" id="Animation_kr7ax"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("DISSAPPEARING ENEMY:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(1, 1, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Hitbox/CollisionShape3D:disabled")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_346xs"]
_data = {
"RESET": SubResource("Animation_kr7ax"),
"attack": SubResource("Animation_ce86e")
}
[sub_resource type="BoxShape3D" id="BoxShape3D_0yire"]
size = Vector3(1, 0.564941, 1.14453)
[node name="EnemyGuy" type="CharacterBody3D"] [node name="EnemyGuy" type="CharacterBody3D"]
collision_layer = 10 collision_layer = 10
collision_mask = 9 collision_mask = 9
@@ -144,3 +209,24 @@ shape = SubResource("CylinderShape3D_jbgmx")
unique_name_in_owner = true unique_name_in_owner = true
wait_time = 10.0 wait_time = 10.0
autostart = true autostart = true
[node name="AttackTimer" type="Timer" parent="."]
unique_name_in_owner = true
wait_time = 1.8
autostart = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
unique_name_in_owner = true
libraries = {
"": SubResource("AnimationLibrary_346xs")
}
[node name="Hitbox" type="Area3D" parent="."]
collision_layer = 64
collision_mask = 64
script = ExtResource("3_erpyl")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.189337, 0.217529, -0.78415)
shape = SubResource("BoxShape3D_0yire")
disabled = true

View File

@@ -18,6 +18,8 @@ namespace GameJamDungeon
public readonly record struct Killed(); public readonly record struct Killed();
public readonly record struct PatrolToRandomSpot(Vector3 PatrolTarget); public readonly record struct PatrolToRandomSpot(Vector3 PatrolTarget);
public readonly record struct AttackTimer;
} }
} }
} }

View File

@@ -8,7 +8,7 @@ namespace GameJamDungeon
public partial record State public partial record State
{ {
[Meta, Id("enemy_logic_state_alive")] [Meta, Id("enemy_logic_state_alive")]
public abstract partial record Alive : State, IGet<Input.HitByPlayer>, IGet<Input.Killed> public abstract partial record Alive : State, IGet<Input.HitByPlayer>, IGet<Input.Killed>, IGet<Input.AttackTimer>
{ {
public Transition On(in Input.HitByPlayer input) public Transition On(in Input.HitByPlayer input)
{ {
@@ -27,6 +27,11 @@ namespace GameJamDungeon
Output(new Output.Die()); Output(new Output.Die());
return To<Idle>(); return To<Idle>();
} }
public Transition On(in Input.AttackTimer input)
{
return To<Attack>();
}
} }
} }
} }

View File

@@ -0,0 +1,42 @@
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
using Godot;
namespace GameJamDungeon
{
public partial class EnemyLogic
{
public partial record State
{
[Meta, Id("enemy_logic_state_attack")]
public partial record Attack : Alive, IGet<Input.Alerted>
{
public Attack()
{
this.OnEnter(() =>
{
var animationPlayer = Get<IEnemy>().AnimationPlayer;
animationPlayer.AnimationFinished += AnimationPlayer_AnimationFinished;
Get<IEnemy>().AnimationPlayer.Play("attack");
});
this.OnExit(() =>
{
var animationPlayer = Get<IEnemy>().AnimationPlayer;
animationPlayer.AnimationFinished -= AnimationPlayer_AnimationFinished;
});
}
public Transition On(in Input.Alerted input)
{
return To<FollowPlayer>();
}
private void AnimationPlayer_AnimationFinished(StringName animName)
{
Get<IEnemy>().EnemyLogic.Input(new Input.Alerted());
}
}
}
}
}

View File

@@ -23,9 +23,7 @@ namespace GameJamDungeon
} }
if (enemy.GlobalPosition.DistanceTo(gameRepo.PlayerGlobalPosition.Value) > 20f) if (enemy.GlobalPosition.DistanceTo(gameRepo.PlayerGlobalPosition.Value) > 20f)
{
return To<Idle>(); return To<Idle>();
}
enemy.NavAgent.TargetPosition = gameRepo.PlayerGlobalPosition.Value; enemy.NavAgent.TargetPosition = gameRepo.PlayerGlobalPosition.Value;
var nextPosition = enemy.NavAgent.GetNextPathPosition(); var nextPosition = enemy.NavAgent.GetNextPathPosition();

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=3 uid="uid://33ek675mfb5n"] [gd_scene load_steps=14 format=3 uid="uid://33ek675mfb5n"]
[ext_resource type="Script" path="res://src/game/Game.cs" id="1_ytcii"] [ext_resource type="Script" path="res://src/game/Game.cs" id="1_ytcii"]
[ext_resource type="PackedScene" uid="uid://cfecvvav8kkp6" path="res://src/player/Player.tscn" id="3_kk6ly"] [ext_resource type="PackedScene" uid="uid://cfecvvav8kkp6" path="res://src/player/Player.tscn" id="3_kk6ly"]
@@ -8,6 +8,7 @@
[ext_resource type="PackedScene" uid="uid://bwbofurcvf3yh" path="res://src/minimap/Minimap.tscn" id="6_owlf4"] [ext_resource type="PackedScene" uid="uid://bwbofurcvf3yh" path="res://src/minimap/Minimap.tscn" id="6_owlf4"]
[ext_resource type="PackedScene" uid="uid://bn4gslp2gk8ds" path="res://src/map/dungeon/corridor/Corridor.tscn" id="6_swtay"] [ext_resource type="PackedScene" uid="uid://bn4gslp2gk8ds" path="res://src/map/dungeon/corridor/Corridor.tscn" id="6_swtay"]
[ext_resource type="PackedScene" uid="uid://bbwgmqy3evhh2" path="res://src/map/dungeon/rooms/Room2.tscn" id="7_1ynbc"] [ext_resource type="PackedScene" uid="uid://bbwgmqy3evhh2" path="res://src/map/dungeon/rooms/Room2.tscn" id="7_1ynbc"]
[ext_resource type="Script" path="res://addons/SimpleDungeons/DungeonRoom3D.gd" id="9_fpt3w"]
[sub_resource type="Environment" id="Environment_fke5g"] [sub_resource type="Environment" id="Environment_fke5g"]
@@ -66,68 +67,88 @@ dungeon_size = Vector3i(10, 1, 10)
[node name="RoomsContainer" type="Node3D" parent="DungeonGenerator3D"] [node name="RoomsContainer" type="Node3D" parent="DungeonGenerator3D"]
[node name="DungeonRoom3D_0" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("7_1ynbc")] [node name="DungeonRoom3D_0" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("7_1ynbc")]
transform = Transform3D(1.19249e-08, 0, -1, 0, 1, 0, 1, 0, 1.19249e-08, -15, 0, 15) transform = Transform3D(1.19249e-08, 0, -1, 0, 1, 0, 1, 0, 1.19249e-08, -35, 0, -5)
script = ExtResource("9_fpt3w")
size_in_voxels = Vector3i(5, 1, 1)
[node name="DungeonRoom3D_1" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_04w8n")] [node name="DungeonRoom3D_1" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_04w8n")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, -35) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, -35)
script = ExtResource("9_fpt3w")
[node name="DungeonRoom3D_2" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_04w8n")] [node name="DungeonRoom3D_2" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_04w8n")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 25, 0, -45) transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -5, 0, 5)
script = ExtResource("9_fpt3w")
[node name="DungeonRoom3D_3" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("7_1ynbc")] [node name="DungeonRoom3D_3" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("7_1ynbc")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 15, 0, -25) transform = Transform3D(1.19249e-08, 0, -1, 0, 1, 0, 1, 0, 1.19249e-08, -25, 0, -15)
script = ExtResource("9_fpt3w")
size_in_voxels = Vector3i(5, 1, 1)
[node name="Corridor_4" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_4" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, -15) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -35, 0, -35)
script = ExtResource("9_fpt3w")
[node name="Corridor_5" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_5" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, -25) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -35, 0, -45)
script = ExtResource("9_fpt3w")
[node name="Corridor_6" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_6" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, -45)
script = ExtResource("9_fpt3w")
[node name="Corridor_7" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, -45) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, -45)
script = ExtResource("9_fpt3w")
[node name="Corridor_7" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_8" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -45) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -45)
script = ExtResource("9_fpt3w")
[node name="Corridor_8" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_9" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, -45) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, -45)
script = ExtResource("9_fpt3w")
[node name="Corridor_9" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_10" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, -45) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, -45)
script = ExtResource("9_fpt3w")
[node name="Corridor_10" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_11" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, 45) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, -25)
script = ExtResource("9_fpt3w")
[node name="Corridor_11" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_12" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 45) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, -15)
script = ExtResource("9_fpt3w")
[node name="Corridor_12" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_13" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 35) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15, 0, -5)
script = ExtResource("9_fpt3w")
[node name="Corridor_13" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_14" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, -5)
script = ExtResource("9_fpt3w")
[node name="Corridor_15" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5, 0, 5)
script = ExtResource("9_fpt3w")
[node name="Corridor_16" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -35, 0, 25)
script = ExtResource("9_fpt3w")
[node name="Corridor_17" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 25) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 25)
script = ExtResource("9_fpt3w")
[node name="Corridor_14" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_18" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 15) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 15)
script = ExtResource("9_fpt3w")
[node name="Corridor_15" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_19" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 5) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, 5)
script = ExtResource("9_fpt3w")
[node name="Corridor_16" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")] [node name="Corridor_20" type="Node3D" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, -5) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15, 0, 15)
script = ExtResource("9_fpt3w")
[node name="Corridor_17" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, -15)
[node name="Corridor_18" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 35, 0, -45)
[node name="Corridor_19" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 35, 0, -35)
[node name="Corridor_20" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45, 0, -35)
[node name="Corridor_21" parent="DungeonGenerator3D/RoomsContainer" instance=ExtResource("6_swtay")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45, 0, -25)

View File

@@ -26,8 +26,8 @@ albedo_color = Color(0.0470588, 0, 1, 1)
albedo_color = Color(0.0470588, 0, 1, 1) albedo_color = Color(0.0470588, 0, 1, 1)
[sub_resource type="NavigationMesh" id="NavigationMesh_3rglr"] [sub_resource type="NavigationMesh" id="NavigationMesh_3rglr"]
vertices = PackedVector3Array(-24.9253, -3.84337, -1.20581, -24.9253, -3.84337, 1.64419, -22.6753, -3.84337, 1.64419, -22.6753, -3.84337, -1.20581, -22.5253, -3.84337, 2.99419, 22.3247, -3.84337, 2.99419, 22.4747, -3.84337, 1.49419, 22.3247, -3.84337, -2.70581, -22.5253, -3.84337, -2.70581, 24.7247, -3.84337, 1.49419, 24.7247, -3.84337, -1.35581, 22.4747, -3.84337, -1.35581) vertices = PackedVector3Array(23.3747, -3.84337, 1.77095, 24.7247, -3.84337, 1.62095, 24.7247, -3.84337, -1.22905, 23.3747, -3.84337, -1.37905, -23.4253, -3.84337, -1.37905, -23.4253, -3.84337, 1.77095, 23.3747, -3.84337, -3.02905, -23.4253, -3.84337, -3.02905, -24.9253, -3.84337, -1.22905, -24.9253, -3.84337, 1.62095, -23.4253, -3.84337, 3.72095, 23.3747, -3.84337, 3.72095)
polygons = [PackedInt32Array(3, 2, 0), PackedInt32Array(0, 2, 1), PackedInt32Array(3, 8, 4), PackedInt32Array(4, 8, 7), PackedInt32Array(4, 7, 6), PackedInt32Array(4, 6, 5), PackedInt32Array(11, 10, 6), PackedInt32Array(6, 10, 9), PackedInt32Array(4, 2, 3), PackedInt32Array(7, 11, 6)] polygons = [PackedInt32Array(1, 0, 2), PackedInt32Array(2, 0, 3), PackedInt32Array(3, 0, 5), PackedInt32Array(3, 5, 4), PackedInt32Array(4, 7, 3), PackedInt32Array(3, 7, 6), PackedInt32Array(8, 4, 9), PackedInt32Array(9, 4, 5), PackedInt32Array(0, 11, 5), PackedInt32Array(5, 11, 10)]
cell_size = 0.15 cell_size = 0.15
agent_radius = 0.15 agent_radius = 0.15
@@ -35,7 +35,7 @@ agent_radius = 0.15
size = Vector3(3, 1, 50) size = Vector3(3, 1, 50)
[sub_resource type="BoxShape3D" id="BoxShape3D_q0wqs"] [sub_resource type="BoxShape3D" id="BoxShape3D_q0wqs"]
size = Vector3(6, 1, 45) size = Vector3(7, 1, 47)
[node name="DungeonRoom3D" type="Node3D"] [node name="DungeonRoom3D" type="Node3D"]
script = ExtResource("1_o02dd") script = ExtResource("1_o02dd")
@@ -122,5 +122,5 @@ shape = SubResource("BoxShape3D_tph0j")
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0) transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="NavigationRegion3D/StaticBody3D3"] [node name="CollisionShape3D" type="CollisionShape3D" parent="NavigationRegion3D/StaticBody3D3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.144196, -4.84337, -0.0752945) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.320954, -4.84337, -0.0752945)
shape = SubResource("BoxShape3D_q0wqs") shape = SubResource("BoxShape3D_q0wqs")

View File

@@ -73,6 +73,8 @@ namespace GameJamDungeon
[Node] public ProgressBar VTBar { get; set; } = default!; [Node] public ProgressBar VTBar { get; set; } = default!;
[Node] public IArea3D CollisionDetector { get; set; } = default!;
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!; private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
private AutoProp<double> _currentHP { get; set; } = default!; private AutoProp<double> _currentHP { get; set; } = default!;
@@ -112,6 +114,7 @@ namespace GameJamDungeon
VTBar.Value = _currentVT.Value; VTBar.Value = _currentVT.Value;
HealthTimer.Timeout += OnHealthTimerTimeout; HealthTimer.Timeout += OnHealthTimerTimeout;
CollisionDetector.AreaEntered += OnEnemyHitBoxEntered;
} }
public void OnResolved() public void OnResolved()
@@ -144,6 +147,20 @@ namespace GameJamDungeon
SetPhysicsProcess(true); 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) public void OnPhysicsProcess(double delta)
{ {
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta)); PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));

View File

@@ -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="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"] [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"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_onron"]
bg_color = Color(0, 0.411765, 0, 1) 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"] [node name="Player" type="CharacterBody3D"]
collision_layer = 38 collision_layer = 38
collision_mask = 7 collision_mask = 7
@@ -209,3 +212,12 @@ custom_minimum_size = Vector2(0, 25)
layout_mode = 2 layout_mode = 2
theme_override_styles/background = SubResource("StyleBoxFlat_onron") theme_override_styles/background = SubResource("StyleBoxFlat_onron")
show_percentage = false 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")

View File

@@ -14,5 +14,16 @@ namespace GameJamDungeon
var calculatedDamage = elementalBonusDamage - enemyStatInfo.BaseDefense; var calculatedDamage = elementalBonusDamage - enemyStatInfo.BaseDefense;
return calculatedDamage; return calculatedDamage;
} }
public static double CalculateEnemyDamage(int attackDamage, PlayerStatInfo playerStatInfo, EnemyStatInfo enemyStatInfo)
{
var baseDamage = attackDamage + enemyStatInfo.BaseAttack;
var elementADamage = (enemyStatInfo.BaseElementADamageBonus > 0 ? enemyStatInfo.BaseElementADamageBonus - playerStatInfo.ElementAResistance : 0) / 100;
var elementBDamage = (enemyStatInfo.BaseElementBDamageBonus > 0 ? enemyStatInfo.BaseElementBDamageBonus - playerStatInfo.ElementBResistance : 0) / 100;
var elementCDamage = (enemyStatInfo.BaseElementCDamageBonus > 0 ? enemyStatInfo.BaseElementCDamageBonus - playerStatInfo.ElementCResistance : 0) / 100;
var elementalBonusDamage = baseDamage + (baseDamage * elementADamage) + (baseDamage * elementBDamage) + (baseDamage * elementCDamage);
var calculatedDamage = elementalBonusDamage - enemyStatInfo.BaseDefense;
return calculatedDamage;
}
} }
} }