Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/FBZ/Launcher.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Launcher Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectLauncher *Launcher;
11
12
void Launcher_Update(void)
13
{
14
RSDK_THIS(Launcher);
15
16
Platform_Update();
17
18
RSDK.ProcessAnimation(&self->animator);
19
}
20
21
void Launcher_LateUpdate(void) {}
22
23
void Launcher_StaticUpdate(void) {}
24
25
void Launcher_Draw(void)
26
{
27
RSDK_THIS(Launcher);
28
29
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
30
}
31
32
void Launcher_Create(void *data)
33
{
34
RSDK_THIS(Launcher);
35
36
self->active = ACTIVE_BOUNDS;
37
Platform_Create(NULL);
38
39
RSDK.SetSpriteAnimation(Platform->aniFrames, 1, &self->animator, true, 0);
40
self->drawFX = FX_FLIP;
41
self->animator.frameID = 4;
42
self->stateCollide = Launcher_Collide_Normal;
43
self->state = Launcher_State_Idle;
44
}
45
46
void Launcher_StageLoad(void) { Launcher->sfxLaunch = RSDK.GetSfx("Stage/Launch.wav"); }
47
48
void Launcher_Collide_Normal(void)
49
{
50
RSDK_THIS(Launcher);
51
int32 stoodPlayers = self->stoodPlayers;
52
self->stoodPlayers = 0;
53
Hitbox *hitbox = RSDK.GetHitbox(&self->animator, 0);
54
55
foreach_active(Player, player)
56
{
57
int32 playerID = RSDK.GetEntitySlot(player);
58
59
if (Player_CheckCollisionPlatform(player, self, hitbox)) {
60
self->stoodPlayers |= 1 << playerID;
61
62
if (self->state == Launcher_State_Idle) {
63
self->active = ACTIVE_NORMAL;
64
self->velocity.x = self->direction == FLIP_NONE ? 0x10000 : -0x10000;
65
self->releaseDelay = 12;
66
self->accelTimer = 4;
67
RSDK.PlaySfx(Launcher->sfxLaunch, false, 255);
68
self->state = Launcher_State_HandleLaunch;
69
}
70
71
if (self->state == Launcher_State_ReturnToStart) {
72
player->position.x += self->collisionOffset.x;
73
}
74
else {
75
player->position.x = self->drawPos.x;
76
player->direction = self->direction;
77
player->velocity.x = 0;
78
player->groundVel = CLAMP(self->velocity.x, -0x60000, 0x60000);
79
player->pushing = false;
80
player->tileCollisions = TILECOLLISION_DOWN;
81
if (player->state != Player_State_Roll)
82
player->state = Player_State_Ground;
83
}
84
}
85
else if (((1 << playerID) & stoodPlayers) && self->state != Launcher_State_ReturnToStart) {
86
player->velocity.x = self->velocity.x;
87
player->groundVel = self->velocity.x;
88
}
89
}
90
}
91
92
void Launcher_State_Idle(void) {}
93
94
void Launcher_State_HandleLaunch(void)
95
{
96
RSDK_THIS(Launcher);
97
98
self->drawPos.x += self->velocity.x;
99
100
if (--self->accelTimer >= 0)
101
self->velocity.x <<= 1;
102
103
if (--self->releaseDelay < 0) {
104
foreach_active(Player, player)
105
{
106
if (((1 << RSDK.GetEntitySlot(player)) & self->stoodPlayers)) {
107
player->groundVel = self->velocity.x;
108
player->velocity.x = self->velocity.x;
109
}
110
}
111
112
self->state = Launcher_State_ReturnToStart;
113
}
114
}
115
116
void Launcher_State_ReturnToStart(void)
117
{
118
RSDK_THIS(Launcher);
119
120
self->drawPos.x += self->direction ? 0x10000 : -0x10000;
121
if (self->drawPos.x == self->centerPos.x) {
122
self->active = ACTIVE_BOUNDS;
123
self->state = Launcher_State_Idle;
124
}
125
}
126
127
#if GAME_INCLUDE_EDITOR
128
void Launcher_EditorDraw(void)
129
{
130
RSDK_THIS(Launcher);
131
132
RSDK.SetSpriteAnimation(Platform->aniFrames, 1, &self->animator, true, 0);
133
self->drawFX = FX_FLIP;
134
self->animator.frameID = 4;
135
self->drawPos = self->position;
136
137
Launcher_Draw();
138
139
if (showGizmos()) {
140
RSDK_DRAWING_OVERLAY(true);
141
142
self->velocity.x = self->direction == FLIP_NONE ? 0x10000 : -0x10000;
143
self->releaseDelay = 12;
144
145
self->accelTimer = 4;
146
while (--self->releaseDelay >= 0) {
147
self->drawPos.x += self->velocity.x;
148
149
if (--self->accelTimer >= 0)
150
self->velocity.x <<= 1;
151
}
152
153
self->inkEffect = INK_BLEND;
154
Launcher_Draw();
155
self->inkEffect = INK_NONE;
156
157
DrawHelpers_DrawArrow(self->position.x, self->position.y, self->drawPos.x, self->drawPos.y, 0x00FF00, INK_NONE, 0xFF);
158
159
RSDK_DRAWING_OVERLAY(false);
160
}
161
}
162
163
void Launcher_EditorLoad(void)
164
{
165
166
RSDK_ACTIVE_VAR(Launcher, direction);
167
RSDK_ENUM_VAR("Right", FLIP_NONE);
168
RSDK_ENUM_VAR("Left", FLIP_X);
169
}
170
#endif
171
172
void Launcher_Serialize(void) { RSDK_EDITABLE_VAR(Launcher, VAR_UINT8, direction); }
173
174