feat: first basic enemy patrolling behaviour
This commit is contained in:
parent
7c4c75d193
commit
526f756736
15 changed files with 801 additions and 386 deletions
52
modules/wave_survival/npc_unit.cpp
Normal file
52
modules/wave_survival/npc_unit.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "npc_unit.h"
|
||||
#include "enemy_body.h"
|
||||
#include "macros.h"
|
||||
#include "patrol_path.h"
|
||||
|
||||
void NpcUnit::_bind_methods() {
|
||||
BIND_HPROPERTY(Variant::OBJECT, patrol_path, PROPERTY_HINT_NODE_TYPE, "PatrolPath");
|
||||
}
|
||||
|
||||
void NpcUnit::child_added(Node *node) {
|
||||
if (EnemyBody * npc{ cast_to<EnemyBody>(node) }) {
|
||||
this->npcs.push_back(npc);
|
||||
npc->set_unit(this);
|
||||
}
|
||||
}
|
||||
|
||||
void NpcUnit::enter_tree() {
|
||||
this->connect("child_entered_tree", callable_mp(this, &self_type::child_added));
|
||||
}
|
||||
|
||||
void NpcUnit::_notification(int what) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
enter_tree();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void NpcUnit::set_patrol_path(PatrolPath *path) {
|
||||
this->patrol_path = path;
|
||||
}
|
||||
|
||||
PatrolPath *NpcUnit::get_patrol_path() const {
|
||||
return this->patrol_path;
|
||||
}
|
||||
|
||||
bool NpcUnit::is_aware_of_player() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void NpcUnit::set_patrol_speed(float speed) {
|
||||
this->patrol_speed = speed;
|
||||
}
|
||||
|
||||
float NpcUnit::get_patrol_speed() const {
|
||||
return this->patrol_speed;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue