2022-01-20 08:52:14 +01:00
|
|
|
#include "KSettings.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cmath>
|
|
|
|
#include "Constants.h"
|
|
|
|
|
|
|
|
namespace KapitanGame
|
|
|
|
{
|
|
|
|
KSettings::KSettings(const float maxJumpHeight, const float horizontalDistanceToMaxJumpHeight) : MaxJumpHeightValue(maxJumpHeight),
|
|
|
|
HorizontalDistanceToMaxJumpHeightValue(horizontalDistanceToMaxJumpHeight),
|
|
|
|
TimeToMaxHeightValue(NAN),
|
|
|
|
GravityValue(NAN),
|
|
|
|
JumpInitialVelocityValue(NAN),
|
|
|
|
ShortJumpVelocityValue(NAN),
|
|
|
|
CollisionEnabledValue(true),
|
|
|
|
Dirty(true),
|
2022-01-20 14:07:29 +01:00
|
|
|
BgPrl0Value(0.5f),
|
|
|
|
BgPrl1Value(0.75f),
|
|
|
|
BgPrl2Value(1.0f),
|
2022-01-20 08:52:14 +01:00
|
|
|
MaxJumpHeight(this, &KSettings::GetMaxJumpHeight, &KSettings::SetMaxJumpHeight),
|
|
|
|
HorizontalDistanceToMaxJumpHeight(this, &KSettings::GetHorizontalDistanceToMaxJumpHeight, &KSettings::SetHorizontalDistanceToMaxJumpHeight),
|
2022-01-20 14:07:29 +01:00
|
|
|
BgPrl0(this, &KSettings::GetBgPrl0, &KSettings::SetBgPrl0),
|
|
|
|
BgPrl1(this, &KSettings::GetBgPrl1, &KSettings::SetBgPrl1),
|
|
|
|
BgPrl2(this, &KSettings::GetBgPrl2, &KSettings::SetBgPrl2),
|
2022-01-20 08:52:14 +01:00
|
|
|
TimeToMaxHeight(this, &KSettings::GetTimeToMaxHeight),
|
|
|
|
Gravity(this, &KSettings::GetGravity),
|
|
|
|
JumpInitialVelocity(this, &KSettings::GetJumpInitialVelocity),
|
|
|
|
ShortJumpVelocity(this, &KSettings::GetShortJumpVelocity),
|
|
|
|
CollisionEnabled(this, &KSettings::GetCollisionEnabled, &KSettings::SetCollisionEnabled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void KSettings::SetCollisionEnabled(const bool value)
|
|
|
|
{
|
|
|
|
if (value != CollisionEnabledValue)
|
|
|
|
CollisionEnabledValue = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KSettings::SetMaxJumpHeight(const float h)
|
|
|
|
{
|
|
|
|
if (h <= 0.f && MaxJumpHeightValue <= 0.f) return;
|
|
|
|
if (MaxJumpHeightValue != h) { // NOLINT(clang-diagnostic-float-equal)
|
|
|
|
MaxJumpHeightValue = std::max(h, 0.f);
|
|
|
|
Dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 14:07:29 +01:00
|
|
|
void KSettings::SetBgPrl0(const float value) {
|
|
|
|
if (value > 1.f) return;
|
|
|
|
if (value != BgPrl0Value)
|
|
|
|
BgPrl0Value = value;
|
|
|
|
}
|
|
|
|
void KSettings::SetBgPrl1(const float value) {
|
|
|
|
if (value > 1.f) return;
|
|
|
|
if (value != BgPrl1Value)
|
|
|
|
BgPrl1Value = value;
|
|
|
|
}
|
|
|
|
void KSettings::SetBgPrl2(const float value) {
|
|
|
|
if (value > 1.f) return;
|
|
|
|
if (value != BgPrl2Value)
|
|
|
|
BgPrl2Value = value;
|
|
|
|
}
|
|
|
|
|
2022-01-20 08:52:14 +01:00
|
|
|
void KSettings::SetHorizontalDistanceToMaxJumpHeight(const float xn)
|
|
|
|
{
|
|
|
|
if (xn <= 0.f && HorizontalDistanceToMaxJumpHeightValue <= 0.f) return;
|
|
|
|
if (HorizontalDistanceToMaxJumpHeightValue != xn) { // NOLINT(clang-diagnostic-float-equal)
|
|
|
|
HorizontalDistanceToMaxJumpHeightValue = std::max(xn, 0.f);
|
|
|
|
Dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReSharper disable once CppMemberFunctionMayBeConst
|
|
|
|
bool KSettings::GetCollisionEnabled()
|
|
|
|
{
|
|
|
|
return CollisionEnabledValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float KSettings::GetTimeToMaxHeight()
|
|
|
|
{
|
|
|
|
if (Dirty)
|
|
|
|
TimeToMaxHeightValue = HorizontalDistanceToMaxJumpHeightValue / Constants::SPEED;
|
|
|
|
return TimeToMaxHeightValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float KSettings::GetGravity()
|
|
|
|
{
|
|
|
|
if (Dirty) {
|
|
|
|
const auto timeToMaxHeight = GetTimeToMaxHeight();
|
|
|
|
GravityValue = 2.0f * MaxJumpHeightValue / (timeToMaxHeight * timeToMaxHeight);
|
|
|
|
}
|
|
|
|
return GravityValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float KSettings::GetJumpInitialVelocity()
|
|
|
|
{
|
|
|
|
if (Dirty)
|
|
|
|
JumpInitialVelocityValue = 2.0f * MaxJumpHeightValue / GetTimeToMaxHeight();
|
|
|
|
return JumpInitialVelocityValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float KSettings::GetShortJumpVelocity()
|
|
|
|
{
|
|
|
|
if (Dirty)
|
|
|
|
ShortJumpVelocityValue = GetJumpInitialVelocity() / 2.f;
|
|
|
|
return ShortJumpVelocityValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReSharper disable once CppMemberFunctionMayBeConst
|
|
|
|
float KSettings::GetMaxJumpHeight()
|
|
|
|
{
|
|
|
|
return MaxJumpHeightValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReSharper disable once CppMemberFunctionMayBeConst
|
|
|
|
float KSettings::GetHorizontalDistanceToMaxJumpHeight()
|
|
|
|
{
|
|
|
|
return HorizontalDistanceToMaxJumpHeightValue;
|
|
|
|
}
|
2022-01-20 14:07:29 +01:00
|
|
|
|
|
|
|
float KSettings::GetBgPrl(const int i) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
return GetBgPrl0();
|
|
|
|
case 1:
|
|
|
|
return GetBgPrl1();
|
|
|
|
case 2:
|
|
|
|
return GetBgPrl2();
|
|
|
|
|
|
|
|
default: return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReSharper disable once CppMemberFunctionMayBeConst
|
|
|
|
float KSettings::GetBgPrl0()
|
|
|
|
{
|
|
|
|
return BgPrl0Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReSharper disable once CppMemberFunctionMayBeConst
|
|
|
|
float KSettings::GetBgPrl1()
|
|
|
|
{
|
|
|
|
return BgPrl1Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReSharper disable once CppMemberFunctionMayBeConst
|
|
|
|
float KSettings::GetBgPrl2()
|
|
|
|
{
|
|
|
|
return BgPrl2Value;
|
|
|
|
}
|
2022-01-20 08:52:14 +01:00
|
|
|
}
|