Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Global/Debris.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Debris Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectDebris *Debris;
11
12
void Debris_Update(void)
13
{
14
RSDK_THIS(Debris);
15
16
if (self->delay <= 0) {
17
RSDK.ProcessAnimation(&self->animator);
18
19
StateMachine_Run(self->state);
20
21
if (self->drawFX & FX_ROTATE)
22
self->rotation = (self->rotation + self->rotSpeed) & 0x1FF;
23
24
if (self->drawFX & FX_SCALE) {
25
if (self->scaleSpeed.x > 0 || self->scaleSpeed.y > 0) {
26
self->scale.x += self->scaleSpeed.x;
27
self->scale.y += self->scaleSpeed.y;
28
29
if (self->scale.x < 0)
30
self->scale.x = 0;
31
32
if (self->scale.y < 0)
33
self->scale.y = 0;
34
}
35
}
36
}
37
else
38
self->delay--;
39
}
40
41
void Debris_LateUpdate(void) {}
42
43
void Debris_StaticUpdate(void) {}
44
45
void Debris_Draw(void)
46
{
47
RSDK_THIS(Debris);
48
49
RSDK.DrawSprite(&self->animator, NULL, false);
50
}
51
52
void Debris_Create(void *data)
53
{
54
RSDK_THIS(Debris);
55
56
self->active = ACTIVE_NORMAL;
57
self->visible = true;
58
self->state = (Type_StateMachine)data;
59
}
60
61
void Debris_StageLoad(void) {}
62
63
void Debris_CreateFromEntries(int32 aniFrames, int32 *entries, int32 animationID)
64
{
65
RSDK_THIS(Debris);
66
67
if (entries) {
68
int32 entryCount = *entries;
69
DebrisEntry *entry = (DebrisEntry *)&entries[1];
70
71
self->drawFX = FX_FLIP;
72
for (int32 e = 0; e < entryCount; ++e) {
73
EntityDebris *debris = CREATE_ENTITY(Debris, (void *)Debris_State_FallAndFlicker, self->position.x, self->position.y);
74
75
RSDK.SetSpriteAnimation(aniFrames, animationID, &debris->animator, true, entry->frame);
76
debris->direction = entry->direction;
77
debris->velocity = entry->velocity;
78
debris->gravityStrength = 0x3800;
79
debris->drawGroup = Zone->objectDrawGroup[1];
80
debris->updateRange.x = TO_FIXED(128);
81
debris->updateRange.y = TO_FIXED(128);
82
83
entry++;
84
}
85
}
86
}
87
88
void Debris_CreateFromEntries_UseOffset(int32 aniFrames, int32 *entries)
89
{
90
RSDK_THIS(Debris);
91
92
if (entries) {
93
int32 entryCount = *entries;
94
DebrisOffsetEntry *entry = (DebrisOffsetEntry *)&entries[1];
95
96
self->drawFX = FX_FLIP;
97
for (int32 e = 0; e < entryCount; ++e) {
98
int32 x = self->position.x + entry->offset.x;
99
int32 y = self->position.y + entry->offset.y;
100
EntityDebris *debris = CREATE_ENTITY(Debris, (void *)Debris_State_FallAndFlicker, x, y);
101
102
RSDK.SetSpriteAnimation(aniFrames, 0, &debris->animator, true, entry->frame);
103
debris->direction = entry->direction;
104
debris->velocity = entry->velocity;
105
debris->gravityStrength = 0x3800;
106
debris->drawGroup = Zone->objectDrawGroup[1];
107
debris->updateRange.x = TO_FIXED(128);
108
debris->updateRange.y = TO_FIXED(128);
109
110
entry++;
111
}
112
}
113
}
114
115
void Debris_State_Move(void)
116
{
117
RSDK_THIS(Debris);
118
119
self->position.x += self->velocity.x;
120
self->position.y += self->velocity.y;
121
122
if (self->timer <= 0) {
123
if (!RSDK.CheckOnScreen(self, NULL))
124
destroyEntity(self);
125
}
126
else {
127
if (!--self->timer)
128
destroyEntity(self);
129
}
130
}
131
132
void Debris_State_Fall(void)
133
{
134
RSDK_THIS(Debris);
135
136
self->position.x += self->velocity.x;
137
self->position.y += self->velocity.y;
138
self->velocity.y += self->gravityStrength;
139
140
if (self->timer <= 0) {
141
if (!RSDK.CheckOnScreen(self, NULL))
142
destroyEntity(self);
143
}
144
else {
145
if (!--self->timer)
146
destroyEntity(self);
147
}
148
}
149
150
void Debris_State_FallAndFlicker(void)
151
{
152
RSDK_THIS(Debris);
153
154
Debris_State_Fall(); // is this cheating
155
156
self->visible = Zone->timer & 1;
157
}
158
159
#if GAME_INCLUDE_EDITOR
160
void Debris_EditorDraw(void) {}
161
162
void Debris_EditorLoad(void) {}
163
#endif
164
165
void Debris_Serialize(void) {}
166
167