Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Common/Eggman.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Eggman Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectEggman *Eggman;
11
12
void Eggman_Update(void)
13
{
14
RSDK_THIS(Eggman);
15
16
StateMachine_Run(self->state);
17
}
18
19
void Eggman_LateUpdate(void) {}
20
21
void Eggman_StaticUpdate(void) {}
22
23
void Eggman_Draw(void)
24
{
25
RSDK_THIS(Eggman);
26
27
if (self->parent) {
28
self->position.x = self->parent->position.x + self->offset.x;
29
self->position.y = self->parent->position.y + self->offset.y;
30
}
31
32
RSDK.DrawSprite(&self->animator, NULL, false);
33
}
34
35
void Eggman_Create(void *data)
36
{
37
RSDK_THIS(Eggman);
38
39
if (!SceneInfo->inEditor) {
40
if (globals->gameMode < MODE_TIMEATTACK) {
41
RSDK.SetSpriteAnimation(Eggman->aniFrames, 0, &self->animator, true, 0);
42
self->active = ACTIVE_NORMAL;
43
self->visible = true;
44
self->drawFX = FX_FLIP;
45
self->drawGroup = Zone->objectDrawGroup[0];
46
self->parent = (Entity *)data;
47
self->updateRange.x = TO_FIXED(64);
48
self->updateRange.y = TO_FIXED(128);
49
self->hitbox.left = -10;
50
self->hitbox.top = -24;
51
self->hitbox.right = 10;
52
self->hitbox.bottom = 27;
53
}
54
else {
55
destroyEntity(self);
56
}
57
}
58
}
59
60
void Eggman_StageLoad(void)
61
{
62
if (RSDK.CheckSceneFolder("GHZCutscene"))
63
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanGHZCutt.bin", SCOPE_STAGE);
64
else if (RSDK.CheckSceneFolder("FBZ"))
65
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanFBZ.bin", SCOPE_STAGE);
66
else if (RSDK.CheckSceneFolder("TMZ3"))
67
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanTMZ.bin", SCOPE_STAGE);
68
else
69
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanAll.bin", SCOPE_STAGE);
70
}
71
72
void Eggman_State_ProcessAnimation(void)
73
{
74
RSDK_THIS(Eggman);
75
76
RSDK.ProcessAnimation(&self->animator);
77
}
78
79
void Eggman_State_ProcessThenSet(void)
80
{
81
RSDK_THIS(Eggman);
82
83
RSDK.ProcessAnimation(&self->animator);
84
85
if (self->animator.frameID >= self->animator.frameCount - 1) {
86
RSDK.SetSpriteAnimation(Eggman->aniFrames, self->animID, &self->animator, true, 0);
87
self->state = Eggman_State_ProcessAnimation;
88
}
89
}
90
91
void Eggman_State_ProcessUntilEnd(void)
92
{
93
RSDK_THIS(Eggman);
94
95
if (self->animator.frameID < self->animator.frameCount - 1)
96
RSDK.ProcessAnimation(&self->animator);
97
}
98
99
void Eggman_State_ProcessAirThenSet(void)
100
{
101
RSDK_THIS(Eggman);
102
103
RSDK.ProcessAnimation(&self->animator);
104
105
if (self->onGround) {
106
RSDK.SetSpriteAnimation(Eggman->aniFrames, self->animID, &self->animator, true, 0);
107
self->state = Eggman_State_ProcessAnimation;
108
}
109
else {
110
self->velocity.y += 0x3800;
111
self->position.x += self->velocity.x;
112
self->position.y += self->velocity.y;
113
}
114
}
115
116
void Eggman_State_FallUntilTimerReset(void)
117
{
118
RSDK_THIS(Eggman);
119
120
RSDK.ProcessAnimation(&self->animator);
121
122
if (self->timer <= 0) {
123
RSDK.SetSpriteAnimation(Eggman->aniFrames, self->animID, &self->animator, true, 0);
124
self->velocity.x = 0;
125
self->velocity.y = 0;
126
self->state = self->nextState;
127
}
128
else {
129
self->velocity.y += 0x3800;
130
self->position.x += self->velocity.x;
131
self->position.y += self->velocity.y;
132
133
self->timer--;
134
}
135
}
136
137
void Eggman_State_FallAndCollide(void)
138
{
139
RSDK_THIS(Eggman);
140
141
RSDK.ProcessAnimation(&self->animator);
142
143
self->velocity.y += 0x3800;
144
self->position.y += self->velocity.y;
145
if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, self->collisionPlane, 0, TO_FIXED(16), true)) {
146
self->onGround = true;
147
self->state = Eggman_State_ProcessAnimation;
148
}
149
}
150
151
void Eggman_State_WalkOffScreen(void)
152
{
153
RSDK_THIS(Eggman);
154
155
RSDK.ProcessAnimation(&self->animator);
156
157
self->position.x += self->velocity.x;
158
self->velocity.x += 0x200;
159
160
if (!RSDK.CheckOnScreen(self, NULL)) {
161
self->active = ACTIVE_NEVER;
162
self->state = Eggman_State_ProcessAnimation;
163
}
164
}
165
166
#if GAME_INCLUDE_EDITOR
167
void Eggman_EditorDraw(void)
168
{
169
RSDK_THIS(Eggman);
170
171
RSDK.SetSpriteAnimation(Eggman->aniFrames, 0, &self->animator, true, 0);
172
self->active = ACTIVE_NORMAL;
173
self->visible = true;
174
self->drawFX = FX_FLIP;
175
self->updateRange.x = 0x400000;
176
self->updateRange.y = 0x800000;
177
178
RSDK.DrawSprite(&self->animator, NULL, false);
179
}
180
181
void Eggman_EditorLoad(void)
182
{
183
if (RSDK.CheckSceneFolder("GHZCutscene"))
184
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanGHZCutt.bin", SCOPE_STAGE);
185
else if (RSDK.CheckSceneFolder("FBZ"))
186
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanFBZ.bin", SCOPE_STAGE);
187
else if (RSDK.CheckSceneFolder("TMZ3"))
188
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanTMZ.bin", SCOPE_STAGE);
189
else
190
Eggman->aniFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanAll.bin", SCOPE_STAGE);
191
}
192
#endif
193
194
void Eggman_Serialize(void) {}
195
196