Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
KartBoost.cc
1
#include "KartBoost.hh"
2
3
namespace
Kinoko::Kart
{
4
6
KartBoost::KartBoost() : m_timers{0}, m_active{false} {
7
m_multiplier = 1.0f;
8
m_acceleration = 1.0f;
9
m_speedLimit = -1.0f;
10
}
11
13
KartBoost::~KartBoost() =
default
;
14
21
bool
KartBoost::activate
(Type type, s16 frames) {
22
bool
activated =
false
;
23
24
size_t
t =
static_cast<
size_t
>
(type);
25
if
(!
m_active
[t] ||
m_timers
[t] < frames) {
26
m_timers
[t] = frames;
27
activated =
true
;
28
m_active
[t] =
true
;
29
}
30
31
return
activated;
32
}
33
38
bool
KartBoost::calc
() {
39
static
constexpr
std::array<f32, BOOST_TYPE_COUNT> MULTIPLIERS = {{
40
0.2f,
41
0.4f,
42
0.3f,
43
}};
44
45
static
constexpr
std::array<f32, BOOST_TYPE_COUNT> ACCELERATIONS = {{
46
3.0f,
47
7.0f,
48
6.0f,
49
}};
50
51
static
constexpr
std::array<f32, BOOST_TYPE_COUNT> LIMITS = {{
52
-1.0f,
53
115.0f,
54
-1.0f,
55
}};
56
57
m_multiplier
= 1.0f;
58
m_acceleration = 1.0f;
59
m_speedLimit = -1.0f;
60
61
for
(
size_t
i = 0; i < BOOST_TYPE_COUNT; ++i) {
62
if
(!
m_active
[i]) {
63
continue
;
64
}
65
66
m_multiplier
= 1.0f + MULTIPLIERS[i];
67
m_acceleration = ACCELERATIONS[i];
68
m_speedLimit = LIMITS[i];
69
70
if
(--
m_timers
[i] <= 0) {
71
m_active
[i] =
false
;
72
}
73
}
74
75
return
m_multiplier
> 1.0f || m_speedLimit > 0.0f;
76
}
77
79
void
KartBoost::reset() {
80
m_timers.fill(0);
81
m_multiplier = 1.0f;
82
m_acceleration = 1.0f;
83
m_speedLimit = -1.0f;
84
}
85
86
}
// namespace Kinoko::Kart
Kinoko::Kart::KartBoost::m_timers
std::array< s16, BOOST_TYPE_COUNT > m_timers
Durations for the different boost types.
Definition
KartBoost.hh:48
Kinoko::Kart::KartBoost::m_active
std::array< bool, BOOST_TYPE_COUNT > m_active
Whether the different boost types are active.
Definition
KartBoost.hh:49
Kinoko::Kart::KartBoost::m_multiplier
f32 m_multiplier
Multiplier applied to vehicle speed.
Definition
KartBoost.hh:50
Kinoko::Kart::KartBoost::activate
bool activate(Type type, s16 frames)
Starts/restarts a boost of the given type.
Definition
KartBoost.cc:21
Kinoko::Kart::KartBoost::calc
bool calc()
Computes the current frame's boost multiplier, acceleration, and speed limit.
Definition
KartBoost.cc:38
Kinoko::Kart
Pertains to kart-related functionality.
Definition
BoxColManager.hh:14
game
kart
KartBoost.cc
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0