feat: implemented basics of enemy rifleman

This commit is contained in:
Sara Gerretsen 2026-02-09 12:53:09 +01:00
parent 13daa093d1
commit f1c4fe75f2
8 changed files with 155 additions and 6 deletions

View file

@ -31,6 +31,13 @@ void MapRegion::on_child_entered_tree(Node *node) {
}
}
void MapRegion::set_hunt_phase(bool hunt) {
if (this->hunt_phase != hunt) {
this->hunt_phase = hunt;
emit_signal(sig_phase_changed, hunt);
}
}
void MapRegion::enter_tree() {
connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered_tree));
}
@ -58,12 +65,21 @@ void MapRegion::_notification(int what) {
void MapRegion::register_unit(NpcUnit *unit) {
if (!this->units.has(unit)) {
this->units.insert(unit);
if (this->hunt_phase) {
this->hunt_phase_units++;
}
}
}
void MapRegion::remove_unit(NpcUnit *unit) {
if (this->units.has(unit)) {
this->units.erase(unit);
if (this->hunt_phase) {
this->hunt_phase_units--;
if (this->hunt_phase_units == 0) {
set_hunt_phase(false);
}
}
}
}
@ -77,8 +93,7 @@ void MapRegion::raise_difficulty(double amount) {
if (new_trunc != old_trunc) {
print_line("Hunt Phase Started");
emit_signal(sig_difficulty_increased);
emit_signal(sig_phase_changed, true);
this->hunt_phase = true;
set_hunt_phase(true);
}
}

View file

@ -11,6 +11,7 @@ class MapRegion : public Area3D {
void on_node_entered(Node3D *node);
void on_node_exited(Node3D *node);
void on_child_entered_tree(Node *node);
void set_hunt_phase(bool hunt);
void enter_tree();
void ready();
@ -27,6 +28,7 @@ private:
double difficulty{ 0.f };
bool hunt_phase{ false };
HashSet<NpcUnit *> units{ nullptr };
size_t hunt_phase_units{ 0 };
bool has_player{ false };
public:

View file

@ -2,6 +2,7 @@
#include "core/object/class_db.h"
#include "wave_survival/damage_box.h"
#include "wave_survival/enemies/enemy_rifleman.h"
#include "wave_survival/enemies/enemy_wretched.h"
#include "wave_survival/enemy_body.h"
#include "wave_survival/enemy_spawner.h"
@ -49,6 +50,10 @@ void initialize_wave_survival_module(ModuleInitializationLevel p_level) {
GDREGISTER_CLASS(WretchedPatrolState);
GDREGISTER_CLASS(WretchedChaseState);
GDREGISTER_CLASS(WretchedAttackState);
GDREGISTER_CLASS(EnemyRifleman);
GDREGISTER_CLASS(RiflemanPatrolState);
GDREGISTER_CLASS(RiflemanChaseState);
GDREGISTER_CLASS(RiflemanFireState);
GDREGISTER_CLASS(PlayerDetector);
GDREGISTER_CLASS(Hitbox);
GDREGISTER_CLASS(DamageBox);

View file

@ -0,0 +1,126 @@
[gd_scene format=3 uid="uid://qx1ywrcl3gf6"]
[ext_resource type="PackedScene" uid="uid://bcy5dxdvkkq4y" path="res://assets/models/enemies/rifleman.blend" id="1_l222e"]
[ext_resource type="PackedScene" uid="uid://clbq43giddldc" path="res://objects/effects/blood_effect.tscn" id="2_pe2i3"]
[sub_resource type="GDScript" id="GDScript_l222e"]
resource_name = "EnemyRiflemanScript"
script/source = "extends EnemyRifleman
@export var difficulty_weight : float = 0.1
var is_dead := false
func on_death() -> void:
%StateMachine.switch_to_state(null)
%NavigationAgent3D.process_mode = Node.PROCESS_MODE_DISABLED
$CollisionShape3D.disabled = true
set_movement_direction(Vector2())
func _on_health_status_death() -> void:
$rifleman/AnimationPlayer.play(\"death\")
get_unit().region.raise_difficulty(difficulty_weight)
on_death.call_deferred()
is_dead = true
func _enter_tree() -> void:
if is_dead and $rifleman/AnimationPlayer.current_animation != \"death\":
$rifleman/AnimationPlayer.play.call_deferred(\"death\")
$rifleman/AnimationPlayer.advance.call_deferred(INF)
elif is_dead:
$rifleman/AnimationPlayer.play.call_deferred(\"death\")
"
[sub_resource type="BoxShape3D" id="BoxShape3D_0dxtm"]
size = Vector3(0.2939453, 0.86813354, 0.18945313)
[sub_resource type="BoxShape3D" id="BoxShape3D_avqge"]
size = Vector3(0.2939453, 0.65130615, 0.18945313)
[sub_resource type="BoxShape3D" id="BoxShape3D_pe2i3"]
size = Vector3(0.24902344, 0.42858887, 0.2619629)
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_l222e"]
radius = 0.17480469
[node name="EnemyRifleman" type="EnemyRifleman" unique_id=1089821759]
script = SubResource("GDScript_l222e")
[node name="rifleman" parent="." unique_id=1838045343 instance=ExtResource("1_l222e")]
[node name="Hitbox" type="Hitbox" parent="rifleman/Character/Skeleton3D" parent_id_path=PackedInt32Array(1838045343, 1395072444) index="2" unique_id=1055859191 node_paths=PackedStringArray("health")]
transform = Transform3D(1, 2.1910389e-16, -2.2202524e-16, -2.2202514e-16, 0.9999124, -0.013243958, 2.1910394e-16, 0.01324396, 0.9999123, 6.209e-17, 0.097789526, 0.004007945)
collision_layer = 6
collision_mask = 0
monitoring = false
health = NodePath("../../../../HealthStatus")
impact_effect = ExtResource("2_pe2i3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="rifleman/Character/Skeleton3D/Hitbox" unique_id=769458773]
transform = Transform3D(1.0000024, -1.4661055e-09, 2.3283064e-09, 6.548362e-11, 0.99992234, 0.013243848, 4.0745363e-09, -0.013243998, 0.9999193, -4.6134344e-10, 0.3361803, -0.0015157582)
shape = SubResource("BoxShape3D_0dxtm")
debug_color = Color(0, 0.64368725, 0.30114147, 0.41960785)
[node name="SpineAttach" type="BoneAttachment3D" parent="rifleman/Character/Skeleton3D" parent_id_path=PackedInt32Array(1838045343, 1395072444) index="3" unique_id=1906380733]
transform = Transform3D(1, -2.2202518e-16, 2.1910394e-16, 2.1910388e-16, 0.9999122, 0.013243958, -2.220252e-16, -0.01324396, 0.99991226, -4.1256417e-17, 1.1546816, -0.0027124756)
bone_name = "spine.002"
bone_idx = 6
[node name="Hitbox2" type="Hitbox" parent="rifleman/Character/Skeleton3D/SpineAttach" unique_id=1699960919 node_paths=PackedStringArray("health")]
transform = Transform3D(1, 2.1910389e-16, -2.2202524e-16, -2.2202514e-16, 0.9999124, -0.013243958, 2.1910394e-16, 0.01324396, 0.9999123, -2.1234107e-16, -1.1546164, -0.012580322)
collision_layer = 4
collision_mask = 0
monitoring = false
health = NodePath("../../../../../HealthStatus")
impact_effect = ExtResource("2_pe2i3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="rifleman/Character/Skeleton3D/SpineAttach/Hitbox2" unique_id=184983678]
transform = Transform3D(1.0000024, -1.4661055e-09, 2.3283064e-09, 6.548362e-11, 0.9999224, 0.013243848, 4.0745363e-09, -0.013244033, 0.9999193, -3.0239777e-10, 1.1921785, -0.012853566)
shape = SubResource("BoxShape3D_avqge")
debug_color = Color(0, 0.64368725, 0.30114147, 0.41960785)
[node name="HeadAttach" type="BoneAttachment3D" parent="rifleman/Character/Skeleton3D" parent_id_path=PackedInt32Array(1838045343, 1395072444) index="4" unique_id=174540097]
transform = Transform3D(1, -2.2186816e-16, 2.1319254e-16, 2.1319254e-16, 0.99920464, 0.039866533, -2.2186818e-16, -0.039866537, 0.99920475, -1.3069549e-16, 1.5574794, -0.004068733)
bone_name = "Neck"
bone_idx = 8
[node name="Hitbox2" type="Hitbox" parent="rifleman/Character/Skeleton3D/HeadAttach" unique_id=1868610059 node_paths=PackedStringArray("health")]
transform = Transform3D(1, 2.1910389e-16, -2.2202524e-16, -2.2202514e-16, 0.9999124, -0.013243958, 2.1910394e-16, 0.01324396, 0.9999123, -2.1234107e-16, -1.1546164, -0.012580322)
collision_layer = 4
collision_mask = 0
monitoring = false
health = NodePath("../../../../../HealthStatus")
damage_modifier = 4.0
impact_effect = ExtResource("2_pe2i3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="rifleman/Character/Skeleton3D/HeadAttach/Hitbox2" unique_id=393334687]
transform = Transform3D(1.0000024, -1.4661055e-09, 2.3283064e-09, 6.548362e-11, 0.9999224, 0.013243848, 4.0745363e-09, -0.013244033, 0.9999193, -4.656613e-10, 1.3035285, -0.014328403)
shape = SubResource("BoxShape3D_pe2i3")
debug_color = Color(0, 0.64368725, 0.30114147, 0.41960785)
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1155449479]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("CapsuleShape3D_l222e")
[node name="StateMachine" type="StateMachine" parent="." unique_id=386183876]
unique_name_in_owner = true
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." unique_id=440954670]
unique_name_in_owner = true
simplify_path = true
simplify_epsilon = 0.647
avoidance_enabled = true
neighbor_distance = 10.0
time_horizon_agents = 0.7
[node name="PlayerDetector" type="PlayerDetector" parent="." unique_id=1321162569]
unique_name_in_owner = true
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, 1.5103652, 0)
[node name="HealthStatus" type="HealthStatus" parent="." unique_id=976044289]
unique_name_in_owner = true
health = 2
[connection signal="death" from="HealthStatus" to="." method="_on_health_status_death"]
[editable path="rifleman"]

View file

@ -5,7 +5,7 @@
[sub_resource type="GDScript" id="GDScript_qot2n"]
script/source = "extends EnemyWretched
@export var difficulty_weight : float = 0.1
@export var difficulty_weight : float
var is_dead := false
@ -37,7 +37,7 @@ slide_on_ceiling = false
wall_min_slide_angle = 0.0
floor_max_angle = 0.9773844
script = SubResource("GDScript_qot2n")
difficulty_weight = 0.15
difficulty_weight = 0.333
[node name="wretched" parent="." unique_id=1505510221 instance=ExtResource("1_qot2n")]

View file

@ -2,6 +2,7 @@
[ext_resource type="PackedScene" uid="uid://cclghy01gblif" path="res://objects/pickups/demo_pack_pickup.tscn" id="1_e0nd4"]
[ext_resource type="PackedScene" uid="uid://dqlqgk1veyos8" path="res://objects/enemies/enemy_wretched.tscn" id="2_avriu"]
[ext_resource type="PackedScene" uid="uid://qx1ywrcl3gf6" path="res://objects/enemies/enemy_rifleman.tscn" id="3_avriu"]
[node name="PatrolA" type="NpcUnit" unique_id=209119201]
patrol_speed = 3.0
@ -13,5 +14,5 @@ transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -0.2
[node name="EnemyWretched5" parent="." unique_id=833864271 instance=ExtResource("2_avriu")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.30714047, 0.023195954, 0.58812845)
[node name="EnemyWretched2" parent="." unique_id=80775110 instance=ExtResource("2_avriu")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.39819503, 0.023196908, -1.0185082)
[node name="EnemyRifleman" parent="." unique_id=1089821759 instance=ExtResource("3_avriu")]
transform = Transform3D(-1, 0, 8.742278e-08, 0, 1, 0, -8.742278e-08, 0, -1, 0.13146043, 0, -1.0506744)