41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
|
#include "camera_effects.hpp"
|
||
|
#include "utils/util_functions.hpp"
|
||
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||
|
|
||
|
void CameraEffects::_bind_methods() {}
|
||
|
|
||
|
void CameraEffects::_ready() {
|
||
|
this->home = this->get_position();
|
||
|
this->target = this->home;
|
||
|
}
|
||
|
|
||
|
void CameraEffects::_process(double delta [[maybe_unused]]) {
|
||
|
this->home = this->get_position();
|
||
|
if(utils::time_seconds() > this->end_time) {
|
||
|
intensity = 0.f;
|
||
|
this->set_position(this->home);
|
||
|
}
|
||
|
if(intensity == 0.f)
|
||
|
return;
|
||
|
gd::Vector3 pos{this->get_position()};
|
||
|
pos = this->target;
|
||
|
this->set_position(this->home + pos);
|
||
|
this->select_target();
|
||
|
}
|
||
|
|
||
|
void CameraEffects::push_effect(float time, float intensity) {
|
||
|
if(intensity > this->intensity) {
|
||
|
this->intensity = intensity;
|
||
|
this->end_time = utils::time_seconds() + time;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CameraEffects::select_target() {
|
||
|
float const intensity_mod{this->intensity * 0.01f};
|
||
|
this->target = {
|
||
|
float(gd::UtilityFunctions::randf_range(0.f, 1.f) * -gd::Math::sign(this->target.x) * intensity_mod),
|
||
|
float(gd::UtilityFunctions::randf_range(-1.f, 1.f) * intensity_mod),
|
||
|
0.f
|
||
|
};
|
||
|
}
|