Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Global/Dust.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Dust Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectDust *Dust;
11
12
void Dust_Update(void) {}
13
14
void Dust_LateUpdate(void)
15
{
16
RSDK_THIS(Dust);
17
18
StateMachine_Run(self->state);
19
}
20
21
void Dust_StaticUpdate(void) {}
22
23
void Dust_Draw(void)
24
{
25
RSDK_THIS(Dust);
26
27
RSDK.DrawSprite(&self->animator, NULL, false);
28
}
29
30
void Dust_Create(void *data)
31
{
32
RSDK_THIS(Dust);
33
34
RSDK.SetSpriteAnimation(Dust->aniFrames, 0, &self->animator, true, 0);
35
36
if (!SceneInfo->inEditor) {
37
self->active = ACTIVE_NORMAL;
38
self->visible = true;
39
self->drawFX = FX_FLIP | FX_ROTATE;
40
self->drawGroup = Zone->objectDrawGroup[1];
41
self->parent = (Entity *)data;
42
}
43
}
44
45
void Dust_StageLoad(void) { Dust->aniFrames = RSDK.LoadSpriteAnimation("Global/Dust.bin", SCOPE_STAGE); }
46
47
void Dust_State_SpinDash(void)
48
{
49
RSDK_THIS(Dust);
50
51
EntityPlayer *player = (EntityPlayer *)self->parent;
52
if (!player) {
53
destroyEntity(self);
54
}
55
else {
56
Hitbox *playerHitbox = Player_GetHitbox(player);
57
58
self->position.x = player->position.x;
59
self->position.y = player->position.y;
60
int32 bottom = playerHitbox->bottom << 16;
61
if (player->invertGravity)
62
self->position.y -= bottom;
63
else
64
self->position.y += bottom;
65
self->direction = player->direction;
66
self->drawGroup = player->drawGroup;
67
self->rotation = player->rotation;
68
69
RSDK.ProcessAnimation(&self->animator);
70
71
if (player->state != Player_State_Spindash)
72
destroyEntity(self);
73
}
74
}
75
void Dust_State_DustTrail(void)
76
{
77
RSDK_THIS(Dust);
78
79
EntityPlayer *player = (EntityPlayer *)self->parent;
80
if (!player) {
81
destroyEntity(self);
82
}
83
else {
84
self->visible = false;
85
if (!self->timer && player->onGround) {
86
Hitbox *playerHitbox = Player_GetHitbox(player);
87
EntityDust *dust = CREATE_ENTITY(Dust, self, player->position.x, player->position.y);
88
dust->state = Dust_State_DustPuff;
89
dust->position.y += playerHitbox->bottom << 16;
90
dust->drawGroup = player->drawGroup;
91
}
92
93
self->timer = (self->timer + 1) & 7;
94
if (player->animator.animationID != ANI_SKID)
95
destroyEntity(self);
96
}
97
}
98
void Dust_State_GlideTrail(void)
99
{
100
RSDK_THIS(Dust);
101
102
EntityPlayer *player = (EntityPlayer *)self->parent;
103
if (!player) {
104
destroyEntity(self);
105
}
106
else {
107
self->visible = false;
108
if (!self->timer && player->onGround) {
109
Hitbox *playerHitbox = Player_GetHitbox(player);
110
EntityDust *dust = CREATE_ENTITY(Dust, self, player->position.x, player->position.y - TO_FIXED(4));
111
dust->state = Dust_State_DustPuff;
112
dust->position.y += playerHitbox->bottom << 16;
113
dust->drawGroup = player->drawGroup;
114
}
115
116
self->timer = (self->timer + 1) & 7;
117
if (player->animator.animationID != ANI_GLIDE_SLIDE || !player->groundVel)
118
destroyEntity(self);
119
}
120
}
121
void Dust_State_DustPuff(void)
122
{
123
RSDK_THIS(Dust);
124
125
self->position.x += self->velocity.x;
126
self->position.y += self->velocity.y;
127
128
RSDK.ProcessAnimation(&self->animator);
129
130
if (self->animator.frameID == self->animator.frameCount - 1)
131
destroyEntity(self);
132
}
133
#if MANIA_USE_PLUS
134
void Dust_State_DustPuff_Collide(void)
135
{
136
RSDK_THIS(Dust);
137
138
self->position.x += self->velocity.x;
139
self->position.y += self->velocity.y;
140
141
RSDK.ObjectTileGrip(self, self->collisionLayers, self->collisionMode, self->collisionPlane, 0, 0, 8);
142
143
RSDK.ProcessAnimation(&self->animator);
144
145
if (self->animator.frameID == self->animator.frameCount - 1)
146
destroyEntity(self);
147
}
148
#endif
149
void Dust_State_DustPuff_Friction(void)
150
{
151
RSDK_THIS(Dust);
152
153
RSDK.ProcessAnimation(&self->animator);
154
155
self->velocity.x -= 0x2000;
156
self->position.x += self->velocity.x;
157
self->position.y += self->velocity.y;
158
159
if (self->animator.frameID == self->animator.frameCount - 1)
160
destroyEntity(self);
161
}
162
163
#if GAME_INCLUDE_EDITOR
164
void Dust_EditorDraw(void) {}
165
166
void Dust_EditorLoad(void) {}
167
#endif
168
169
void Dust_Serialize(void) {}
170
171