Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/LRZ/LRZConvSwitch.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: LRZConvSwitch Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectLRZConvSwitch *LRZConvSwitch;
11
12
void LRZConvSwitch_Update(void)
13
{
14
RSDK_THIS(LRZConvSwitch);
15
16
if ((LRZ2Setup->conveyorDir != self->conveyorDir) != self->calibration)
17
LRZConvSwitch_Calibrate();
18
19
int32 extendX2 = self->position.x;
20
int32 extendY2 = self->position.y - 0x180000;
21
22
foreach_active(Player, player)
23
{
24
int32 playerID = RSDK.GetEntitySlot(player);
25
26
if (self->playerPositions[playerID].x || self->playerPositions[playerID].y) {
27
int32 dir = 0;
28
if (player->position.x <= self->playerPositions[playerID].x) {
29
if (player->position.x < self->playerPositions[playerID].x)
30
dir = -1;
31
}
32
else {
33
dir = 1;
34
}
35
36
bool32 collided =
37
MathHelpers_CheckPositionOverlap(player->position.x, player->position.y, self->playerPositions[playerID].x,
38
self->playerPositions[playerID].y, self->position.x, self->position.y, extendX2, extendY2);
39
40
if (!self->dir && !player->sidekick) {
41
if (dir < 0) {
42
if (collided && !self->conveyorDir) {
43
RSDK.PlaySfx(LRZConvSwitch->sfxClack, false, 255);
44
RSDK.SetSpriteAnimation(LRZConvSwitch->aniFrames, 1, &self->animator, true, 0);
45
self->conveyorDir = 1;
46
LRZ2Setup->conveyorDir = self->calibration ^ 1;
47
self->dir = 1;
48
}
49
}
50
if (dir > 0 && collided && self->conveyorDir == 1) {
51
RSDK.PlaySfx(LRZConvSwitch->sfxClack, false, 255);
52
RSDK.SetSpriteAnimation(LRZConvSwitch->aniFrames, 3, &self->animator, true, 0);
53
self->conveyorDir = 0;
54
LRZ2Setup->conveyorDir = self->calibration;
55
self->dir = 1;
56
}
57
}
58
}
59
60
self->playerPositions[playerID].x = player->position.x;
61
self->playerPositions[playerID].y = player->position.y;
62
}
63
64
RSDK.ProcessAnimation(&self->animator);
65
66
if (self->animator.animationID == 1 && self->animator.frameID == self->animator.frameCount - 1) {
67
RSDK.SetSpriteAnimation(LRZConvSwitch->aniFrames, 2, &self->animator, true, 0);
68
self->dir = 0;
69
}
70
71
if (self->animator.animationID == 3 && self->animator.frameID == self->animator.frameCount - 1) {
72
RSDK.SetSpriteAnimation(LRZConvSwitch->aniFrames, 0, &self->animator, true, 0);
73
self->dir = 0;
74
}
75
}
76
77
void LRZConvSwitch_LateUpdate(void) {}
78
79
void LRZConvSwitch_StaticUpdate(void) {}
80
81
void LRZConvSwitch_Draw(void)
82
{
83
RSDK_THIS(LRZConvSwitch);
84
85
RSDK.DrawSprite(&self->animator, NULL, false);
86
}
87
88
void LRZConvSwitch_Create(void *data)
89
{
90
RSDK_THIS(LRZConvSwitch);
91
92
self->active = ACTIVE_BOUNDS;
93
self->drawGroup = Zone->objectDrawGroup[0];
94
self->startPos = self->position;
95
self->visible = true;
96
self->drawFX = FX_FLIP;
97
self->updateRange.x = 0x800000;
98
self->updateRange.y = 0x800000;
99
100
LRZConvSwitch_Calibrate();
101
}
102
103
void LRZConvSwitch_StageLoad(void)
104
{
105
LRZConvSwitch->aniFrames = RSDK.LoadSpriteAnimation("LRZ2/LRZConvSwitch.bin", SCOPE_STAGE);
106
107
LRZConvSwitch->sfxClack = RSDK.GetSfx("Stage/Clack.wav");
108
}
109
110
void LRZConvSwitch_Calibrate(void)
111
{
112
RSDK_THIS(LRZConvSwitch);
113
114
self->conveyorDir = self->calibration ^ LRZ2Setup->conveyorDir;
115
116
if (!self->conveyorDir)
117
RSDK.SetSpriteAnimation(LRZConvSwitch->aniFrames, 0, &self->animator, true, 0);
118
else if (self->conveyorDir == 1)
119
RSDK.SetSpriteAnimation(LRZConvSwitch->aniFrames, 2, &self->animator, true, 0);
120
}
121
122
#if GAME_INCLUDE_EDITOR
123
void LRZConvSwitch_EditorDraw(void)
124
{
125
LRZConvSwitch_Calibrate();
126
LRZConvSwitch_Draw();
127
}
128
129
void LRZConvSwitch_EditorLoad(void)
130
{
131
LRZConvSwitch->aniFrames = RSDK.LoadSpriteAnimation("LRZ2/LRZConvSwitch.bin", SCOPE_STAGE);
132
133
RSDK_ACTIVE_VAR(LRZConvSwitch, calibration);
134
RSDK_ENUM_VAR("Right", LRZCONVSWITCH_RIGHT);
135
RSDK_ENUM_VAR("Left", LRZCONVSWITCH_LEFT);
136
}
137
#endif
138
139
void LRZConvSwitch_Serialize(void) { RSDK_EDITABLE_VAR(LRZConvSwitch, VAR_UINT8, calibration); }
140
141