break-utopia/modules/break_utopia/level_status.cpp

62 lines
1.7 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")));
BIND_PROPERTY(Variant::FLOAT, energy);
BIND_PROPERTY(Variant::FLOAT, style);
BIND_PROPERTY(Variant::INT, score);
BIND_PROPERTY(Variant::FLOAT, player_health);
}
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->style += style_value;
if (this->style > 6) {
this->style = 6;
}
this->score += value * style_value;
this->energy += double(value * style_value) * 0.01;
if (this->energy > 1.0) {
this->energy = 1.0;
}
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;
}