Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/FBZ/FBZFan.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: FBZFan Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectFBZFan *FBZFan;
11
12
void FBZFan_Update(void)
13
{
14
RSDK_THIS(FBZFan);
15
16
FBZFan->hitboxFan.top = (RSDK.Sin256(2 * Zone->timer) >> 5) - 80;
17
FBZFan->hitboxFan.bottom = FBZFan->hitboxFan.top + 96;
18
19
self->hitboxTrigger.top = -96;
20
self->hitboxTrigger.bottom = -8;
21
22
foreach_active(Player, player)
23
{
24
bool32 isFanning = false;
25
26
int32 playerID = RSDK.GetEntitySlot(player);
27
Player_CheckCollisionBox(player, self, &FBZFan->hitboxSolid);
28
29
if (player->state != Player_State_Static && Player_CheckValidState(player) && player->animator.animationID != ANI_HURT
30
&& RSDK.CheckObjectCollisionTouchBox(self, &FBZFan->hitboxFan, player, &FBZFan->hitboxPlayer)) {
31
isFanning = true;
32
RSDK.SetSpriteAnimation(player->aniFrames, ANI_FAN, &player->animator, false, 0);
33
player->state = Player_State_Air;
34
player->onGround = false;
35
36
int32 vel = (self->position.y + (FBZFan->hitboxFan.top << 16) - player->position.y) >> 4;
37
if (player->velocity.y <= vel) {
38
player->velocity.y = vel;
39
}
40
else {
41
player->velocity.y += ((self->position.y + (FBZFan->hitboxFan.top << 16) - player->position.y) >> 6)
42
+ ((self->position.y + (FBZFan->hitboxFan.top << 16) - player->position.y) >> 5);
43
44
if (player->velocity.y < vel)
45
player->velocity.y = vel;
46
}
47
48
if (!((1 << playerID) & FBZFan->activePlayers)) {
49
if (player->velocity.y > -0x40000 && player->velocity.y < 0)
50
player->velocity.x += (32 * player->velocity.x / 31) >> 5;
51
52
FBZFan->activePlayers |= 1 << playerID;
53
}
54
}
55
56
if (RSDK.CheckObjectCollisionTouchBox(self, &self->hitboxTrigger, player, &FBZFan->hitboxPlayer)) {
57
if (!((1 << playerID) & self->activePlayers) && isFanning) {
58
RSDK.PlaySfx(FBZFan->sfxFan, false, 255);
59
self->activePlayers |= (1 << playerID);
60
}
61
}
62
else {
63
self->activePlayers &= ~(1 << playerID);
64
}
65
}
66
}
67
68
void FBZFan_LateUpdate(void) {}
69
70
void FBZFan_StaticUpdate(void)
71
{
72
RSDK.ProcessAnimation(&FBZFan->fanAnimator);
73
RSDK.ProcessAnimation(&FBZFan->fan2Animator);
74
75
FBZFan->activePlayers = 0;
76
}
77
78
void FBZFan_Draw(void)
79
{
80
RSDK.DrawSprite(&FBZFan->baseAnimator, NULL, false);
81
RSDK.DrawSprite(&FBZFan->fanAnimator, NULL, false);
82
RSDK.DrawSprite(&FBZFan->fan2Animator, NULL, false);
83
}
84
85
void FBZFan_Create(void *data)
86
{
87
RSDK_THIS(FBZFan);
88
if (!SceneInfo->inEditor) {
89
self->active = ACTIVE_BOUNDS;
90
self->visible = true;
91
self->drawGroup = Zone->objectDrawGroup[0] + 1;
92
self->updateRange.x = 0x800000;
93
self->updateRange.y = 0x800000;
94
95
self->hitboxTrigger.left = -64;
96
self->hitboxTrigger.right = 64;
97
}
98
}
99
100
void FBZFan_StageLoad(void)
101
{
102
FBZFan->aniFrames = RSDK.LoadSpriteAnimation("FBZ/FBZFan.bin", SCOPE_STAGE);
103
104
FBZFan->sfxFan = RSDK.GetSfx("FBZ/FBZFan.wav");
105
106
RSDK.SetSpriteAnimation(FBZFan->aniFrames, 0, &FBZFan->baseAnimator, true, 0);
107
RSDK.SetSpriteAnimation(FBZFan->aniFrames, 1, &FBZFan->fanAnimator, true, 0);
108
RSDK.SetSpriteAnimation(FBZFan->aniFrames, 2, &FBZFan->fan2Animator, true, 0);
109
110
FBZFan->hitboxSolid.left = -64;
111
FBZFan->hitboxSolid.top = -16;
112
FBZFan->hitboxSolid.right = 64;
113
FBZFan->hitboxSolid.bottom = 16;
114
115
FBZFan->hitboxFan.left = -64;
116
FBZFan->hitboxFan.right = 64;
117
118
FBZFan->hitboxPlayer.left = -1;
119
FBZFan->hitboxPlayer.top = -1;
120
FBZFan->hitboxPlayer.right = 1;
121
FBZFan->hitboxPlayer.bottom = 1;
122
}
123
124
#if GAME_INCLUDE_EDITOR
125
void FBZFan_EditorDraw(void) { FBZFan_Draw(); }
126
127
void FBZFan_EditorLoad(void)
128
{
129
FBZFan->aniFrames = RSDK.LoadSpriteAnimation("FBZ/FBZFan.bin", SCOPE_STAGE);
130
131
RSDK.SetSpriteAnimation(FBZFan->aniFrames, 0, &FBZFan->baseAnimator, true, 0);
132
RSDK.SetSpriteAnimation(FBZFan->aniFrames, 1, &FBZFan->fanAnimator, true, 0);
133
RSDK.SetSpriteAnimation(FBZFan->aniFrames, 2, &FBZFan->fan2Animator, true, 0);
134
}
135
#endif
136
137
void FBZFan_Serialize(void) {}
138
139