52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
#include "level_status.h"
|
|
#include "core/config/engine.h"
|
|
|
|
void LevelStatus::_bind_methods() {
|
|
ClassDB::bind_static_method("LevelStatus", "get_instance", &self_type::get_instance);
|
|
ClassDB::bind_method(D_METHOD("notify_object_destroyed", "value"), &self_type::notify_object_destroyed);
|
|
ADD_SIGNAL(MethodInfo(sig_object_destroyed, PropertyInfo(Variant::FLOAT, "style"), PropertyInfo(Variant::INT, "score")));
|
|
}
|
|
|
|
void LevelStatus::process(double delta) {
|
|
this->time_since_last += delta;
|
|
}
|
|
|
|
void LevelStatus::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_ENTER_TREE:
|
|
instance = this;
|
|
return;
|
|
case NOTIFICATION_EXIT_TREE:
|
|
if (instance == this) {
|
|
instance = nullptr;
|
|
}
|
|
return;
|
|
case NOTIFICATION_READY:
|
|
set_process(true);
|
|
return;
|
|
case NOTIFICATION_PROCESS:
|
|
process(get_process_delta_time());
|
|
return;
|
|
}
|
|
}
|
|
|
|
void LevelStatus::notify_object_destroyed(int value) {
|
|
double style_value{ 1 + (this->max_time_between > this->time_since_last ? (this->max_time_between - this->time_since_last) : 0.0) };
|
|
this->time_since_last = 0.0;
|
|
this->style += this->base_style_per_object * style_value * this->max_style_mult;
|
|
this->score += value * (1 + this->style) * style_value * this->max_score_mult;
|
|
emit_signal(sig_object_destroyed, this->style, this->score);
|
|
}
|
|
|
|
String const LevelStatus::sig_object_destroyed{ "object_destroyed" };
|
|
|
|
LevelStatus *LevelStatus::instance{ nullptr };
|
|
|
|
LevelStatus *LevelStatus::get_instance() {
|
|
return instance;
|
|
}
|