Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/MSZ/Flipper.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Flipper Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectFlipper *Flipper;
11
12
void Flipper_Update(void)
13
{
14
RSDK_THIS(Flipper);
15
16
RSDK.ProcessAnimation(&self->animator);
17
18
if (self->animator.animationID == 1 && self->animator.frameID == self->animator.frameCount - 1)
19
RSDK.SetSpriteAnimation(Flipper->aniFrames, 0, &self->animator, false, 0);
20
21
if (self->direction == FLIP_NONE) {
22
foreach_active(Player, player)
23
{
24
int32 playerID = RSDK.GetEntitySlot(player);
25
26
if (player->position.x >= self->position.x + 0x40000)
27
self->hitbox.top = ((player->position.x - self->position.x - 0x40000) >> 17) - 20;
28
else
29
self->hitbox.top = -20;
30
31
self->hitbox.bottom = self->hitbox.top + 16;
32
33
if (Player_CheckCollisionPlatform(player, self, &self->hitbox)) {
34
self->activePlayers |= 1 << playerID;
35
player->position.y += 0x80000;
36
37
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
38
39
if (player->jumpPress) {
40
for (int32 i = SLOT_PLAYER1; i < Player->playerCount; ++i) {
41
if ((1 << i) & self->activePlayers) {
42
EntityPlayer *playerPtr = RSDK_GET_ENTITY(i, Player);
43
int32 vel = (playerPtr->position.x - self->position.x) - 0x40000;
44
playerPtr->animator.speed = 120;
45
playerPtr->state = Player_State_Air;
46
playerPtr->jumpAbilityState = 1;
47
playerPtr->onGround = false;
48
playerPtr->velocity.x = vel / 7;
49
playerPtr->velocity.y = -0x68000 - (vel >> 3);
50
}
51
}
52
53
RSDK.SetSpriteAnimation(Flipper->aniFrames, 1, &self->animator, false, 0);
54
RSDK.PlaySfx(Flipper->sfxFlipper, false, 255);
55
}
56
else {
57
player->tileCollisions = TILECOLLISION_DOWN;
58
player->state = Player_State_Air;
59
60
if (player->groundVel >= 0x10000) {
61
if (player->groundVel > 0x20000)
62
player->groundVel = 0x20000;
63
64
player->groundVel += 0x1000;
65
}
66
else {
67
player->groundVel = 0x10000;
68
player->groundVel += 0x1000;
69
}
70
}
71
}
72
else {
73
self->activePlayers &= ~(1 << playerID);
74
}
75
}
76
}
77
else {
78
foreach_active(Player, player)
79
{
80
int32 playerID = RSDK.GetEntitySlot(player);
81
82
if (player->position.x <= self->position.x - 0x40000)
83
self->hitbox.top = ((self->position.x - player->position.x - 0x40000) >> 17) - 20;
84
else
85
self->hitbox.top = -20;
86
87
self->hitbox.bottom = self->hitbox.top + 16;
88
89
if (Player_CheckCollisionPlatform(player, self, &self->hitbox)) {
90
self->activePlayers |= 1 << playerID;
91
player->position.y += 0x80000;
92
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
93
94
if (player->jumpPress) {
95
for (int32 i = SLOT_PLAYER1; i < Player->playerCount; ++i) {
96
if ((1 << i) & self->activePlayers) {
97
EntityPlayer *playerPtr = RSDK_GET_ENTITY(i, Player);
98
int32 vel = (self->position.x - player->position.x) - 0x40000;
99
playerPtr->animator.speed = 120;
100
playerPtr->state = Player_State_Air;
101
playerPtr->jumpAbilityState = 1;
102
playerPtr->onGround = false;
103
playerPtr->velocity.x = -(vel / 7);
104
playerPtr->velocity.y = -0x68000 - (vel >> 3);
105
}
106
}
107
108
RSDK.SetSpriteAnimation(Flipper->aniFrames, 1, &self->animator, false, 0);
109
RSDK.PlaySfx(Flipper->sfxFlipper, false, 255);
110
}
111
else {
112
player->tileCollisions = TILECOLLISION_DOWN;
113
player->state = Player_State_Air;
114
if (player->groundVel <= -0x10000) {
115
if (player->groundVel < -0x20000)
116
player->groundVel = -0x20000;
117
118
player->groundVel -= 0x1000;
119
}
120
else {
121
player->groundVel = -0x10000;
122
player->groundVel -= 0x1000;
123
}
124
}
125
}
126
else {
127
self->activePlayers &= ~(1 << playerID);
128
}
129
}
130
}
131
}
132
133
void Flipper_LateUpdate(void) {}
134
135
void Flipper_StaticUpdate(void) {}
136
137
void Flipper_Draw(void)
138
{
139
RSDK_THIS(Flipper);
140
141
RSDK.DrawSprite(&self->animator, NULL, false);
142
}
143
144
void Flipper_Create(void *data)
145
{
146
RSDK_THIS(Flipper);
147
148
self->drawFX = FX_FLIP;
149
if (!SceneInfo->inEditor) {
150
151
RSDK.SetSpriteAnimation(Flipper->aniFrames, 0, &self->animator, true, 0);
152
self->active = ACTIVE_BOUNDS;
153
self->updateRange.x = 0x800000;
154
self->updateRange.y = 0x800000;
155
self->hitbox.left = Flipper->hitbox.left;
156
self->hitbox.right = Flipper->hitbox.right;
157
self->visible = true;
158
self->drawGroup = Zone->objectDrawGroup[0];
159
}
160
}
161
162
void Flipper_StageLoad(void)
163
{
164
Flipper->aniFrames = RSDK.LoadSpriteAnimation("MSZ/Flipper.bin", SCOPE_STAGE);
165
166
Flipper->hitbox.left = -12;
167
Flipper->hitbox.right = 56;
168
169
Flipper->sfxFlipper = RSDK.GetSfx("Stage/Flipper.wav");
170
}
171
172
#if GAME_INCLUDE_EDITOR
173
void Flipper_EditorDraw(void)
174
{
175
RSDK_THIS(Flipper);
176
177
RSDK.SetSpriteAnimation(Flipper->aniFrames, 0, &self->animator, true, 0);
178
179
Flipper_Draw();
180
}
181
182
void Flipper_EditorLoad(void)
183
{
184
Flipper->aniFrames = RSDK.LoadSpriteAnimation("MSZ/Flipper.bin", SCOPE_STAGE);
185
186
RSDK_ACTIVE_VAR(Flipper, direction);
187
RSDK_ENUM_VAR("Right", FLIP_NONE);
188
RSDK_ENUM_VAR("Left", FLIP_X);
189
}
190
#endif
191
192
void Flipper_Serialize(void) { RSDK_EDITABLE_VAR(Flipper, VAR_UINT8, direction); }
193
194