Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/SSZ/MSBomb.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: MSBomb Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
#if MANIA_USE_PLUS
11
ObjectMSBomb *MSBomb;
12
13
void MSBomb_Update(void)
14
{
15
RSDK_THIS(MSBomb);
16
17
RSDK.ProcessAnimation(&self->animator);
18
19
StateMachine_Run(self->state);
20
}
21
22
void MSBomb_LateUpdate(void) {}
23
24
void MSBomb_StaticUpdate(void) {}
25
26
void MSBomb_Draw(void)
27
{
28
RSDK_THIS(MSBomb);
29
30
RSDK.DrawSprite(&self->animator, NULL, false);
31
}
32
33
void MSBomb_Create(void *data)
34
{
35
RSDK_THIS(MSBomb);
36
37
self->active = ACTIVE_NORMAL;
38
self->visible = true;
39
self->drawGroup = Zone->objectDrawGroup[0];
40
41
if (data) {
42
RSDK.SetSpriteAnimation(MSBomb->aniFrames, 1, &self->animator, true, 0);
43
44
self->hitbox.left = -4;
45
self->hitbox.top = -4;
46
self->hitbox.right = 4;
47
self->hitbox.bottom = 4;
48
49
self->state = MSBomb_State_Projectile;
50
}
51
else {
52
RSDK.SetSpriteAnimation(MSBomb->aniFrames, 0, &self->animator, true, 0);
53
54
self->hitbox.left = -8;
55
self->hitbox.top = -8;
56
self->hitbox.right = 8;
57
self->hitbox.bottom = 8;
58
59
self->drawFX = FX_SCALE;
60
self->scale.x = 0xC0;
61
self->scale.y = 0xC0;
62
self->state = MSBomb_State_EnterBomb;
63
}
64
}
65
66
void MSBomb_StageLoad(void)
67
{
68
MSBomb->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSBomb.bin", SCOPE_STAGE);
69
70
MSBomb->sfxExplosion = RSDK.GetSfx("Stage/Explosion4.wav");
71
}
72
73
void MSBomb_State_EnterBomb(void)
74
{
75
RSDK_THIS(MSBomb);
76
77
self->position.x += self->velocity.x;
78
self->position.y += self->velocity.y;
79
self->velocity.y += 0x3800;
80
81
if (self->scale.x >= 0x200) {
82
self->drawFX = FX_NONE;
83
self->state = MSBomb_State_Bouncing;
84
}
85
else {
86
self->scale.x += 0x40;
87
self->scale.y = self->scale.x;
88
}
89
}
90
91
// Not sure why this is part of MSBomb but alright
92
void MSBomb_State_SilverSonicExplode(void)
93
{
94
RSDK_THIS(SilverSonic);
95
96
self->position.x += self->velocity.x;
97
self->position.y += self->velocity.y;
98
self->velocity.y += 0x3800;
99
100
if (self->scale.x >= 0x200) {
101
int32 yVel = 0x18000;
102
int32 xVel = 0x30000;
103
104
foreach_active(MetalSonic, metal)
105
{
106
xVel = MAX(abs(self->position.x - metal->position.x) >> 6, 0x20000);
107
yVel = abs(self->position.y - metal->position.y) >> 6;
108
}
109
110
EntityMSBomb *bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);
111
bomb->velocity.x = -xVel;
112
bomb->velocity.y = -yVel;
113
114
bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);
115
bomb->velocity.x = xVel;
116
bomb->velocity.y = -yVel;
117
118
bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);
119
yVel = -(yVel >> 1);
120
bomb->velocity.x = -xVel;
121
bomb->velocity.y = yVel;
122
123
bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);
124
bomb->velocity.x = xVel;
125
bomb->velocity.y = yVel;
126
127
RSDK.PlaySfx(MSBomb->sfxExplosion, false, 0xFF);
128
RSDK.ResetEntity(self, Explosion->classID, INT_TO_VOID(EXPLOSION_BOSS));
129
self->position.x = bomb->position.x;
130
self->position.y = bomb->position.y;
131
}
132
else {
133
self->scale.x += 0x40;
134
self->scale.y = self->scale.x;
135
}
136
}
137
138
void MSBomb_State_Bouncing(void)
139
{
140
RSDK_THIS(MSBomb);
141
142
self->position.x += self->velocity.x;
143
self->position.y += self->velocity.y;
144
self->velocity.y += 0x3800;
145
146
if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, 0xA0000, true)) {
147
// Bounce
148
self->velocity.y = -0x40000;
149
150
if (self->timer > 0) {
151
if (!--self->timer) {
152
int32 storeX = self->position.x;
153
int32 storeY = self->position.y;
154
RSDK.ResetEntity(self, Explosion->classID, INT_TO_VOID(EXPLOSION_BOSS));
155
self->position.x = storeX;
156
self->position.y = storeY;
157
RSDK.PlaySfx(MSBomb->sfxExplosion, false, 255);
158
}
159
}
160
}
161
else if (!self->timer && !RSDK.CheckOnScreen(self, NULL)) {
162
destroyEntity(self);
163
}
164
165
if (self->classID == MSBomb->classID) {
166
foreach_active(Player, player)
167
{
168
if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {
169
if (Player_Hurt(player, self))
170
player->velocity.x = abs(player->velocity.x) + Zone->autoScrollSpeed;
171
172
CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_ENEMY), self->position.x, self->position.y);
173
RSDK.PlaySfx(MSBomb->sfxExplosion, false, 255);
174
destroyEntity(self);
175
}
176
}
177
}
178
}
179
180
void MSBomb_State_Projectile(void)
181
{
182
RSDK_THIS(MSBomb);
183
184
self->position.x += self->velocity.x;
185
self->position.y += self->velocity.y;
186
187
foreach_active(Player, player)
188
{
189
if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {
190
Player_Hurt(player, self);
191
}
192
}
193
194
foreach_active(MetalSonic, metal)
195
{
196
if (RSDK.CheckObjectCollisionTouchBox(metal, metal->outerBox, self, &self->hitbox)) {
197
MetalSonic->invincibilityTimerPanel = 16;
198
199
if (--metal->health <= 0) {
200
metal->timer = 0;
201
metal->state = MetalSonic_State_PanelExplosion;
202
}
203
204
RSDK.PlaySfx(MetalSonic->sfxHit, false, 255);
205
destroyEntity(self);
206
foreach_break;
207
}
208
}
209
210
if (!RSDK.CheckOnScreen(self, NULL))
211
destroyEntity(self);
212
}
213
214
#if GAME_INCLUDE_EDITOR
215
void MSBomb_EditorDraw(void)
216
{
217
RSDK_THIS(MSBomb);
218
RSDK.SetSpriteAnimation(MSBomb->aniFrames, 0, &self->animator, true, 0);
219
220
MSBomb_Draw();
221
}
222
223
void MSBomb_EditorLoad(void) { MSBomb->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSBomb.bin", SCOPE_STAGE); }
224
#endif
225
226
void MSBomb_Serialize(void) {}
227
#endif
228
229