wave-survival/modules/wave_survival/enemy_body.cpp

59 lines
1.2 KiB
C++

#include "enemy_body.h"
#include "macros.h"
#include "npc_unit.h"
void EnemyBody::_bind_methods() {}
void EnemyBody::ready() {
this->fsm = cast_to<StateMachine>(get_node(NodePath("%StateMachine")));
this->nav = cast_to<NavigationAgent3D>(get_node(NodePath("%NavigationAgent3D")));
}
void EnemyBody::physics_process(double delta) {
GETSET(velocity, {
velocity = Vector3{ this->movement_direction.x, velocity.y, this->movement_direction.y };
});
move_and_slide();
}
void EnemyBody::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (what) {
default:
return;
case NOTIFICATION_READY:
set_physics_process(true);
ready();
return;
case NOTIFICATION_PHYSICS_PROCESS:
physics_process(get_physics_process_delta_time());
return;
}
}
void EnemyBody::set_movement_direction(Vector2 direction) {
this->movement_direction = direction;
}
void EnemyBody::set_unit(NpcUnit *unit) {
this->unit = unit;
}
NpcUnit *EnemyBody::get_unit() const {
return this->unit;
}
NavigationAgent3D *EnemyBody::get_nav() const {
return this->nav;
}
void EnemyBody::set_movement_speed(float value) {
this->movement_speed = value;
}
float EnemyBody::get_movement_speed() const {
return this->movement_speed;
}