feat: implemented enemy rifleman combat

This commit is contained in:
Sara Gerretsen 2026-02-09 13:29:37 +01:00
parent f1c4fe75f2
commit 18c8154576
10 changed files with 8267 additions and 6 deletions

View file

@ -1,11 +1,15 @@
#include "enemy_rifleman.h"
#include "core/os/memory.h"
#include "scene/animation/animation_player.h"
#include "wave_survival/macros.h"
#include "wave_survival/npc_unit.h"
#include "wave_survival/player_body.h"
#include "wave_survival/player_detector.h"
#include "wave_survival/state_machine.h"
void EnemyRifleman::_bind_methods() {
BIND_PROPERTY(Variant::INT, damage_amount);
ClassDB::bind_method(D_METHOD("shoot"), &self_type::shoot);
}
void EnemyRifleman::ready() {
@ -27,6 +31,20 @@ void EnemyRifleman::_notification(int what) {
}
}
void EnemyRifleman::shoot() {
if (get_detector()->line_of_sight_exists()) {
PlayerBody::get_singleton()->get_health()->damage(this->damage_amount);
}
}
void EnemyRifleman::set_damage_amount(int amount) {
this->damage_amount = amount;
}
int EnemyRifleman::get_damage_amount() const {
return this->damage_amount;
}
EnemyRifleman *RiflemanState::get_target() const {
return cast_to<EnemyRifleman>(get_body());
}
@ -50,9 +68,16 @@ void RiflemanFireState::enter_state() {
get_target()->set_movement_direction(Vector2());
}
void RiflemanFireState::process(double delta) {
Vector3 const body_pos{ get_target()->get_global_position() };
Vector3 player_pos{ PlayerBody::get_singleton()->get_global_position() };
player_pos.y = body_pos.y;
get_target()->look_at(body_pos + player_pos - body_pos);
}
String RiflemanFireState::get_next_state() const {
if (get_anim()->get_current_animation().is_empty()) {
return RiflemanFireState::get_class_static();
return RiflemanChaseState::get_class_static();
}
return get_class();
}

View file

@ -14,6 +14,14 @@ class EnemyRifleman : public EnemyBody {
protected:
void _notification(int what);
public:
void shoot();
void set_damage_amount(int amount);
int get_damage_amount() const;
private:
int damage_amount{ 1 };
};
/* ============================== STATES ============================== */
@ -48,6 +56,7 @@ class RiflemanFireState : public RiflemanState {
public:
void enter_state() override;
void process(double delta) override;
String get_next_state() const override;
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -46,9 +46,9 @@ 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="rifleman" parent="." unique_id=1463524398 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")]
[node name="Hitbox" type="Hitbox" parent="rifleman/Character/Skeleton3D" parent_id_path=PackedInt32Array(1463524398, 1950882827) 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
@ -61,7 +61,7 @@ transform = Transform3D(1.0000024, -1.4661055e-09, 2.3283064e-09, 6.548362e-11,
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]
[node name="SpineAttach" type="BoneAttachment3D" parent="rifleman/Character/Skeleton3D" parent_id_path=PackedInt32Array(1463524398, 1950882827) 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
@ -79,7 +79,7 @@ transform = Transform3D(1.0000024, -1.4661055e-09, 2.3283064e-09, 6.548362e-11,
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]
[node name="HeadAttach" type="BoneAttachment3D" parent="rifleman/Character/Skeleton3D" parent_id_path=PackedInt32Array(1463524398, 1950882827) 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