A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectFireSnake.hh
1#pragma once
2
3#include "game/field/StateManager.hh"
4#include "game/field/obj/ObjectProjectile.hh"
5
6namespace Field {
7
9public:
11 ~ObjectFireSnakeKid() override;
12
14 [[nodiscard]] u32 loadFlags() const override {
15 return 1;
16 }
17
19 void setTransform(const EGG::Matrix34f &mat) {
20 m_flags.setBit(eFlags::Matrix);
21 m_transform = mat;
22 m_pos = mat.base(3);
23 }
24};
25
27public:
29 ~ObjectFireSnake() override;
30
31 void init() override;
32 void calc() override;
33
35 [[nodiscard]] u32 loadFlags() const override {
36 return 1;
37 }
38
39 void initProjectile(const EGG::Vector3f &pos) override;
40 void onLaunch() override;
41
42 void enterDespawned();
43 void enterFalling();
44 void enterHighBounce();
45 void enterRest();
46 void enterBounce() {}
47 void enterDespawning() {}
48
49 void calcDespawned() {}
50 void calcFalling();
51 void calcHighBounce();
52 void calcRest();
53 void calcBounce();
54 void calcDespawning() {}
55
56private:
57 void calcChildren();
58 void calcBounce(f32 initialVel);
59
60 bool isCollisionEnabled() const {
61 return m_currentStateId == 2 || m_currentStateId == 3 || m_currentStateId == 4;
62 }
63
64 std::array<ObjectFireSnakeKid *, 2> m_kids;
65 const s16 m_maxAge;
66 EGG::Vector3f m_sunPos;
67 const EGG::Vector3f m_initialPos;
68 EGG::Vector3f m_xzSunDist;
69 EGG::Vector3f m_fallAxis;
70 f32 m_xzSpeed;
72 EGG::Vector3f m_initRot;
73 std::array<EGG::Matrix34f, 21> m_prevTransforms;
74 EGG::Vector3f m_visualPos;
75 EGG::Vector3f m_bounceDir;
77
78 static constexpr std::array<StateManagerEntry, 6> STATE_ENTRIES = {{
79 {StateEntry<ObjectFireSnake, &ObjectFireSnake::enterDespawned,
80 &ObjectFireSnake::calcDespawned>(0)},
81 {StateEntry<ObjectFireSnake, &ObjectFireSnake::enterFalling,
82 &ObjectFireSnake::calcFalling>(1)},
83 {StateEntry<ObjectFireSnake, &ObjectFireSnake::enterHighBounce,
84 &ObjectFireSnake::calcHighBounce>(2)},
85 {StateEntry<ObjectFireSnake, &ObjectFireSnake::enterRest, &ObjectFireSnake::calcRest>(
86 3)},
87 {StateEntry<ObjectFireSnake, &ObjectFireSnake::enterBounce,
88 &ObjectFireSnake::calcBounce>(4)},
89 {StateEntry<ObjectFireSnake, &ObjectFireSnake::enterDespawning,
90 &ObjectFireSnake::calcDespawning>(5)},
91 }};
92
93 static constexpr f32 GRAVITY = 3.0f;
94};
95
96} // namespace Field
A 3 x 4 matrix.
Definition Matrix.hh:8
Vector3f base(size_t col) const
Get a particular column from a matrix.
Definition Matrix.hh:70
u16 m_fallDuration
How long the firesnake falls from the sun.
u16 m_age
How long the firesnake has been spawned.
const s16 m_maxAge
Number of frames until the snake will disappear.
std::array< EGG::Matrix34f, 21 > m_prevTransforms
The last 21 transformation matrices.
void onLaunch() override
Callback function use by the ObjectSniper that wants to throw this projectile.
void initProjectile(const EGG::Vector3f &pos) override
Callback function called by the managing ObjectSniper.
Abstract class that represents an object thrown by an ObjectProjectileLauncher.
Base class that represents different "states" for an object.
Pertains to collision.
constexpr TBitFlag< T, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:57
A 3D float vector.
Definition Vector.hh:88