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
26class ObjectFireSnake;
27
28class ObjectFireSnake : public ObjectProjectile, public StateManager<ObjectFireSnake> {
30
31public:
33 ~ObjectFireSnake() override;
34
35 void init() override;
36 void calc() override;
37
39 [[nodiscard]] u32 loadFlags() const override {
40 return 1;
41 }
42
43 void initProjectile(const EGG::Vector3f &pos) override;
44 void onLaunch() override;
45
46 void enterDespawned();
47 void enterFalling();
48 void enterHighBounce();
49 void enterRest();
50 void enterBounce() {}
51 void enterDespawning() {}
52
53 void calcDespawned() {}
54 void calcFalling();
55 void calcHighBounce();
56 void calcRest();
57 void calcBounce();
58 void calcDespawning() {}
59
60private:
61 void calcChildren();
62 void calcBounce(f32 initialVel);
63
64 bool isCollisionEnabled() const {
65 return m_currentStateId == 2 || m_currentStateId == 3 || m_currentStateId == 4;
66 }
67
68 std::array<ObjectFireSnakeKid *, 2> m_kids;
69 const s16 m_maxAge;
70 EGG::Vector3f m_sunPos;
71 const EGG::Vector3f m_initialPos;
72 EGG::Vector3f m_xzSunDist;
73 EGG::Vector3f m_fallAxis;
74 f32 m_xzSpeed;
76 EGG::Vector3f m_initRot;
77 std::array<EGG::Matrix34f, 21> m_prevTransforms;
78 EGG::Vector3f m_visualPos;
79 EGG::Vector3f m_bounceDir;
81
82 static constexpr std::array<StateManagerEntry<ObjectFireSnake>, 6> STATE_ENTRIES = {{
83 {0, &ObjectFireSnake::enterDespawned, &ObjectFireSnake::calcDespawned},
84 {1, &ObjectFireSnake::enterFalling, &ObjectFireSnake::calcFalling},
85 {2, &ObjectFireSnake::enterHighBounce, &ObjectFireSnake::calcHighBounce},
86 {3, &ObjectFireSnake::enterRest, &ObjectFireSnake::calcRest},
87 {4, &ObjectFireSnake::enterBounce, &ObjectFireSnake::calcBounce},
88 {5, &ObjectFireSnake::enterDespawning, &ObjectFireSnake::calcDespawning},
89 }};
90
91 static constexpr f32 GRAVITY = 3.0f;
92};
93
94} // 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.
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