Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Common/ForceUnstick.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ForceUnstick Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectForceUnstick *ForceUnstick;
11
12
void ForceUnstick_Update(void)
13
{
14
RSDK_THIS(ForceUnstick);
15
16
foreach_active(Player, player)
17
{
18
if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {
19
player->collisionMode = CMODE_FLOOR;
20
21
if (self->breakClimb && player->state == Player_State_KnuxWallClimb) {
22
RSDK.SetSpriteAnimation(player->aniFrames, ANI_GLIDE_DROP, &player->animator, false, 2);
23
player->state = Player_State_KnuxGlideDrop;
24
}
25
}
26
}
27
28
self->visible = DebugMode->debugActive;
29
}
30
31
void ForceUnstick_LateUpdate(void) {}
32
33
void ForceUnstick_StaticUpdate(void) {}
34
35
void ForceUnstick_Draw(void) { ForceUnstick_DrawSprites(); }
36
37
void ForceUnstick_Create(void *data)
38
{
39
RSDK_THIS(ForceUnstick);
40
41
if (!SceneInfo->inEditor) {
42
self->updateRange.x = self->width << 19;
43
self->updateRange.y = self->height << 19;
44
45
self->hitbox.right = 8 * self->width + 8;
46
self->hitbox.left = -self->hitbox.right;
47
self->hitbox.bottom = 8 * self->height + 8;
48
self->hitbox.top = -self->hitbox.bottom;
49
50
self->visible = false;
51
self->active = ACTIVE_BOUNDS;
52
self->drawGroup = Zone->objectDrawGroup[1];
53
}
54
}
55
56
void ForceUnstick_StageLoad(void)
57
{
58
ForceUnstick->aniFrames = RSDK.LoadSpriteAnimation("Global/ItemBox.bin", SCOPE_STAGE);
59
RSDK.SetSpriteAnimation(ForceUnstick->aniFrames, 2, &ForceUnstick->animator, true, 6);
60
}
61
62
void ForceUnstick_DrawSprites(void)
63
{
64
RSDK_THIS(ForceUnstick);
65
66
Vector2 drawPos;
67
drawPos.x = self->position.x - (self->width << 19);
68
drawPos.y = self->position.y - (self->height << 19);
69
70
ForceUnstick->animator.frameID = self->breakClimb ? 9 : 6;
71
for (int32 y = 0; y < self->height + 1; ++y) {
72
for (int32 x = 0; x < self->width + 1; ++x) {
73
RSDK.DrawSprite(&ForceUnstick->animator, &drawPos, false);
74
drawPos.x += TO_FIXED(16);
75
}
76
drawPos.x += -TO_FIXED(16) - (self->width << 20);
77
drawPos.y += TO_FIXED(16);
78
}
79
}
80
81
#if GAME_INCLUDE_EDITOR
82
void ForceUnstick_EditorDraw(void) { ForceUnstick_DrawSprites(); }
83
84
void ForceUnstick_EditorLoad(void)
85
{
86
ForceUnstick->aniFrames = RSDK.LoadSpriteAnimation("Global/ItemBox.bin", SCOPE_STAGE);
87
RSDK.SetSpriteAnimation(ForceUnstick->aniFrames, 2, &ForceUnstick->animator, true, 6);
88
}
89
#endif
90
91
void ForceUnstick_Serialize(void)
92
{
93
RSDK_EDITABLE_VAR(ForceUnstick, VAR_UINT8, width);
94
RSDK_EDITABLE_VAR(ForceUnstick, VAR_UINT8, height);
95
RSDK_EDITABLE_VAR(ForceUnstick, VAR_BOOL, breakClimb);
96
}
97
98