77 lines
2.3 KiB
C++
77 lines
2.3 KiB
C++
#include "rifle.h"
|
|
#include "scene/animation/animation_player.h"
|
|
#include "wave_survival/player_body.h"
|
|
#include "wave_survival/player_input.h"
|
|
|
|
void Rifle::_bind_methods() {}
|
|
|
|
void Rifle::on_primary_fire(bool pressed) {
|
|
if (pressed && get_anim()->get_queue().size() == 0) {
|
|
if (this->request_alt_mode) {
|
|
get_anim()->queue("fire_aim");
|
|
} else if (get_anim()->get_current_animation() == "") {
|
|
get_anim()->queue("fire_hip");
|
|
}
|
|
}
|
|
}
|
|
|
|
void Rifle::on_alt_mode(bool alt_mode) {
|
|
this->request_alt_mode = alt_mode;
|
|
}
|
|
|
|
void Rifle::on_animation_changed(String new_animation) {
|
|
if (new_animation == "aim") {
|
|
this->in_alt_mode = true;
|
|
get_camera()->set_fov_factor(this->ads_factor);
|
|
} else if (new_animation == "RESET") {
|
|
this->in_alt_mode = false;
|
|
get_camera()->set_fov_factor(1.f);
|
|
}
|
|
}
|
|
|
|
void Rifle::ready() {
|
|
get_anim()->connect("current_animation_changed", callable_mp(this, &self_type::on_animation_changed));
|
|
PlayerInput *input{ cast_to<PlayerInput>(get_node(NodePath("%PlayerInput"))) };
|
|
input->connect(PlayerInput::sig_primary_fire, callable_mp(this, &self_type::on_primary_fire));
|
|
input->connect(PlayerInput::sig_alt_mode, callable_mp(this, &self_type::on_alt_mode));
|
|
|
|
get_anim()->animation_set_next("hip_to_aim", "aim");
|
|
get_anim()->animation_set_next("fire_aim", "aim");
|
|
get_anim()->animation_set_next("aim_to_hip", "RESET");
|
|
get_anim()->animation_set_next("fire_hip", "RESET");
|
|
}
|
|
|
|
void Rifle::process(double delta) {
|
|
String const current{ get_anim()->get_current_animation() };
|
|
float const progress{ float(CLAMP(get_anim()->get_current_animation_position() / get_anim()->get_current_animation_length(), 0.0, 1.0)) };
|
|
if (current == "hip_to_aim") {
|
|
get_camera()->set_fov_factor(Math::lerp(1.f, this->ads_factor, progress));
|
|
} else if (current == "aim_to_hip") {
|
|
get_camera()->set_fov_factor(Math::lerp(this->ads_factor, 1.f, progress));
|
|
} else if (this->request_alt_mode != this->in_alt_mode && current.is_empty()) {
|
|
get_anim()->clear_queue();
|
|
if (this->request_alt_mode) {
|
|
get_anim()->queue("hip_to_aim");
|
|
} else {
|
|
get_anim()->queue("aim_to_hip");
|
|
}
|
|
}
|
|
}
|
|
|
|
void Rifle::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_READY:
|
|
set_process(true);
|
|
ready();
|
|
return;
|
|
case NOTIFICATION_PROCESS:
|
|
process(get_process_delta_time());
|
|
return;
|
|
}
|
|
}
|