-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
551 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "KartBoost.hh" | ||
|
||
namespace Kart { | ||
|
||
KartBoost::KartBoost() : m_timers{0}, m_active{false} { | ||
m_multiplier = 1.0f; | ||
m_acceleration = 1.0f; | ||
m_speedLimit = -1.0f; | ||
} | ||
|
||
KartBoost::~KartBoost() = default; | ||
|
||
bool KartBoost::activate(Type type, s16 frames) { | ||
bool activated = false; | ||
|
||
size_t t = static_cast<size_t>(type); | ||
if (!m_active[t] || m_timers[t] < frames) { | ||
m_timers[t] = frames; | ||
activated = true; | ||
m_active[t] = true; | ||
} | ||
|
||
return activated; | ||
} | ||
|
||
bool KartBoost::calc() { | ||
static constexpr std::array<f32, BOOST_TYPE_COUNT> MULTIPLIERS = {{ | ||
0.2f, | ||
}}; | ||
|
||
static constexpr std::array<f32, BOOST_TYPE_COUNT> ACCELERATIONS = {{ | ||
3.0f, | ||
}}; | ||
|
||
static constexpr std::array<f32, BOOST_TYPE_COUNT> LIMITS = {{ | ||
-1.0f, | ||
}}; | ||
|
||
m_multiplier = 1.0f; | ||
m_acceleration = 1.0f; | ||
m_speedLimit = -1.0f; | ||
|
||
for (size_t i = 0; i < BOOST_TYPE_COUNT; ++i) { | ||
if (!m_active[i]) { | ||
continue; | ||
} | ||
|
||
m_multiplier = 1.0f + MULTIPLIERS[i]; | ||
m_acceleration = ACCELERATIONS[i]; | ||
m_speedLimit = LIMITS[i]; | ||
|
||
if (--m_timers[i] <= 0) { | ||
m_active[i] = false; | ||
} | ||
} | ||
|
||
return m_multiplier > 1.0f || m_speedLimit > 0.0f; | ||
} | ||
|
||
f32 KartBoost::multiplier() const { | ||
return m_multiplier; | ||
} | ||
|
||
f32 KartBoost::acceleration() const { | ||
return m_acceleration; | ||
} | ||
|
||
f32 KartBoost::speedLimit() const { | ||
return m_speedLimit; | ||
} | ||
|
||
} // namespace Kart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <Common.hh> | ||
|
||
namespace Kart { | ||
|
||
class KartBoost { | ||
public: | ||
enum class Type { | ||
AllMt, | ||
Max, | ||
}; | ||
|
||
KartBoost(); | ||
~KartBoost(); | ||
|
||
bool activate(Type type, s16 frames); | ||
bool calc(); | ||
|
||
f32 multiplier() const; | ||
f32 acceleration() const; | ||
f32 speedLimit() const; | ||
|
||
private: | ||
// We need to evaluate this expression early for the array initialization | ||
static constexpr size_t BOOST_TYPE_COUNT = static_cast<size_t>(Type::Max); | ||
|
||
std::array<s16, BOOST_TYPE_COUNT> m_timers; | ||
std::array<bool, BOOST_TYPE_COUNT> m_active; | ||
f32 m_multiplier; | ||
f32 m_acceleration; | ||
f32 m_speedLimit; | ||
}; | ||
|
||
} // namespace Kart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.