1#include "ObjectKoopaBall.hh"
3#include "game/field/CollisionDirector.hh"
5#include "game/kart/KartCollide.hh"
11 : ObjectCollidable(params), m_vel(
EGG::Vector3f::zero) {}
14ObjectKoopaBall::~ObjectKoopaBall() {
15 delete m_bombCoreDrawMdl;
19void ObjectKoopaBall::init() {
20 constexpr u32 START_COOLDOWN = 221;
22 m_state = State::Intangible;
23 m_cooldownTimer = START_COOLDOWN;
25 m_railInterpolator->init(0.0f, 0);
26 m_railInterpolator->setCurrVel(INITIAL_VELOCITY);
27 m_railInterpolator->calc();
29 m_initPosY = m_railInterpolator->curPos().y;
30 m_flags.setBit(eFlags::Position);
33 EGG::Vector3f curTanDirNorm = m_railInterpolator->curTangentDir();
35 setMatrixFromOrthonormalBasisAndPos(curTanDirNorm);
39 m_angSpeed = INITIAL_ANGULAR_SPEED;
40 m_vel.y = INITIAL_Y_VEL;
44 auto *resMgr = System::ResourceManager::Instance();
45 const void *file = resMgr->getFile(
"bombCore.brres",
nullptr, System::ArchiveId::Core);
49 m_bombCoreDrawMdl->linkAnims(0, &resFile,
"bombCore", Render::AnmType::Chr);
50 auto *anmMgr = m_bombCoreDrawMdl->anmMgr();
51 anmMgr->playAnim(0.0f, 1.0f, 0);
52 m_animFramecount = anmMgr->activeAnim(Render::AnmType::Chr)->frameCount();
58 resize(RADIUS_AABB, 0.0f);
62void ObjectKoopaBall::calc() {
67 case State::Intangible:
70 case State::Exploding:
79 EGG::Vector3f railVel = m_railInterpolator->curTangentDir() * m_railInterpolator->getCurrVel();
86 Kart::Reaction reactionOnKart, Kart::Reaction ,
88 return m_explodeTimer > 0 ? Kart::Reaction::ExplosionLoseItem : reactionOnKart;
92void ObjectKoopaBall::calcTangible() {
93 constexpr f32 END_VELOCITY = 60.0f;
94 constexpr f32 GRAVITY = 2.0f;
96 auto railStatus = m_railInterpolator->calc();
99 case RailInterpolator::Status::SegmentEnd:
100 m_vel.y = END_VELOCITY;
101 m_railInterpolator->setCurrVel(INITIAL_VELOCITY / INITIAL_ANGULAR_SPEED);
103 case RailInterpolator::Status::ChangingDirection: {
104 m_state = State::Exploding;
105 m_flags.setBit(eFlags::Scale);
106 m_curScale = SCALE_INITIAL;
107 m_scale =
EGG::Vector3f(SCALE_INITIAL, SCALE_INITIAL, SCALE_INITIAL);
108 m_explodeTimer = m_animFramecount;
114 m_flags.setBit(eFlags::Position);
115 m_pos.x = m_railInterpolator->curPos().x;
116 m_pos.z = m_railInterpolator->curPos().z;
118 m_vel.y = m_vel.y - GRAVITY;
119 m_pos.y = m_vel.y + m_pos.y;
123 m_angleRad += -m_angSpeed * DEG2RAD;
127 m_flags.setBit(eFlags::Matrix);
128 m_transform = m_transform.multiplyTo(mat);
129 m_transform.setBase(3, m_pos);
133void ObjectKoopaBall::calcExploding() {
134 constexpr s32 EXPLODE_COLLISION_DURATION = 20;
135 constexpr s32 EXPLOSION_EXPAND_FRAME = 30;
136 constexpr f32 INIT_FACTOR = 1.01f;
139 if (m_explodeTimer > EXPLOSION_EXPAND_FRAME) {
140 m_flags.setBit(eFlags::Scale);
141 m_curScale += SCALE_DELTA;
145 if (m_explodeTimer == EXPLODE_COLLISION_DURATION) {
149 if (--m_explodeTimer == 0) {
150 m_curScale = INIT_FACTOR;
151 m_flags.setBit(eFlags::Scale);
152 m_scale = INIT_SCALE;
153 m_railInterpolator->init(0.0f, 0);
154 m_pos = m_railInterpolator->curPos();
155 m_pos.y = m_initPosY;
156 m_flags.setBit(eFlags::Position);
158 m_state = State::Intangible;
163void ObjectKoopaBall::calcIntangible() {
164 constexpr s32 COOLDOWN_FRAMES = 210;
166 if (m_cooldownTimer >= 0) {
170 m_state = State::Tangible;
171 m_railInterpolator->setCurrVel(INITIAL_VELOCITY);
172 m_angSpeed = INITIAL_ANGULAR_SPEED;
173 m_vel.y = INITIAL_Y_VEL;
174 m_cooldownTimer = COOLDOWN_FRAMES;
178void ObjectKoopaBall::checkSphereFull() {
180 constexpr f32 RADIUS = 100.0f;
181 constexpr f32 BOUNCE_FACTOR = -0.4f;
182 constexpr f32 MIN_ANG_SPEED = 10.0f;
187 if (CollisionDirector::Instance()->checkSphereFull(RADIUS, pos, EGG::Vector3f::inf,
189 m_vel.y *= BOUNCE_FACTOR;
190 m_angSpeed = std::max(MIN_ANG_SPEED, m_angSpeed);
191 m_pos += info.tangentOff;
192 m_flags.setBit(eFlags::Position);
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
Represents a binary resource file which contains object models, textures, and animations.
void makeR(const Vector3f &r)
Sets 3x3 rotation matrix from a vector of Euler angles.
The highest level abstraction for a kart.
f32 normalise()
Normalizes the vector and returns the original length.