Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/CPZ/Reagent.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Reagent Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectReagent *Reagent;
11
12
void Reagent_Update(void)
13
{
14
RSDK_THIS(Reagent);
15
16
StateMachine_Run(self->state);
17
}
18
19
void Reagent_LateUpdate(void) {}
20
21
void Reagent_StaticUpdate(void) {}
22
23
void Reagent_Draw(void)
24
{
25
RSDK_THIS(Reagent);
26
27
RSDK.DrawSprite(&self->animator, NULL, false);
28
}
29
30
void Reagent_Create(void *data)
31
{
32
RSDK_THIS(Reagent);
33
34
if (!SceneInfo->inEditor) {
35
self->visible = true;
36
self->drawGroup = Zone->objectDrawGroup[0];
37
self->active = ACTIVE_NORMAL;
38
self->updateRange.x = 0x800000;
39
self->updateRange.y = 0x2000000;
40
self->inkEffect = INK_ALPHA;
41
self->alpha = 0xC0;
42
self->velocity.x = ZONE_RAND(-0xC000, 0xC000);
43
self->type = VOID_TO_INT(data);
44
self->state = Reagent_State_CheckPoolCollisions;
45
46
switch (self->type) {
47
case CHEMICALPOOL_BLUE:
48
self->r = 0x00;
49
self->g = 0x08;
50
self->b = 0xC0;
51
break;
52
53
case CHEMICALPOOL_GREEN:
54
self->r = 0x18;
55
self->g = 0x90;
56
self->b = 0x00;
57
break;
58
59
case CHEMICALPOOL_CYAN:
60
self->r = 0x00;
61
self->g = 0x80;
62
self->b = 0xB0;
63
break;
64
}
65
66
RSDK.SetSpriteAnimation(Reagent->aniFrames, self->type + 1, &self->animator, true, ZONE_RAND(0, 2));
67
}
68
}
69
70
void Reagent_StageLoad(void)
71
{
72
Reagent->aniFrames = RSDK.LoadSpriteAnimation("CPZ/Syringe.bin", SCOPE_STAGE);
73
74
Reagent->hitbox.left = -2;
75
Reagent->hitbox.top = -2;
76
Reagent->hitbox.right = 2;
77
Reagent->hitbox.bottom = 2;
78
79
Reagent->sfxLand = RSDK.GetSfx("Puyo/Land.wav");
80
}
81
82
void Reagent_State_CheckPoolCollisions(void)
83
{
84
RSDK_THIS(Reagent);
85
86
self->velocity.y += 0x3800;
87
self->position.x += self->velocity.x;
88
self->position.y += self->velocity.y;
89
90
foreach_all(ChemicalPool, chemPool)
91
{
92
if (RSDK.CheckObjectCollisionTouchBox(self, &Reagent->hitbox, chemPool, &chemPool->hitbox)) {
93
self->velocity.y >>= 2;
94
self->originPos.x = self->position.x;
95
self->state = Reagent_State_ChangingPoolType;
96
chemPool->active = ACTIVE_NORMAL;
97
ChemicalPool_ChangeState(chemPool, self->type, self->r, self->g, self->b);
98
RSDK.PlaySfx(Reagent->sfxLand, false, 255);
99
}
100
}
101
102
if (!RSDK.CheckOnScreen(self, NULL))
103
destroyEntity(self);
104
}
105
106
void Reagent_State_ChangingPoolType(void)
107
{
108
RSDK_THIS(Reagent);
109
110
self->velocity.y -= 0x1800;
111
self->alpha -= 4;
112
++self->timer;
113
self->position.x = self->originPos.x + (RSDK.Sin256(self->timer) << 10);
114
self->position.y += self->velocity.y;
115
116
if (self->timer == 64)
117
destroyEntity(self);
118
}
119
120
#if GAME_INCLUDE_EDITOR
121
void Reagent_EditorDraw(void)
122
{
123
RSDK_THIS(Reagent);
124
125
self->updateRange.x = 0x800000;
126
self->updateRange.y = 0x2000000;
127
self->inkEffect = INK_ALPHA;
128
self->alpha = 0xC0;
129
130
switch (self->type) {
131
case CHEMICALPOOL_BLUE:
132
self->r = 0x00;
133
self->g = 0x08;
134
self->b = 192;
135
break;
136
137
case CHEMICALPOOL_GREEN:
138
self->r = 0x18;
139
self->g = 0x90;
140
self->b = 0x00;
141
break;
142
143
case CHEMICALPOOL_CYAN:
144
self->r = 0x00;
145
self->g = 0x80;
146
self->b = 0xB0;
147
break;
148
}
149
150
RSDK.SetSpriteAnimation(Reagent->aniFrames, self->type + 1, &self->animator, true, 0);
151
152
Reagent_Draw();
153
}
154
155
void Reagent_EditorLoad(void) { Reagent->aniFrames = RSDK.LoadSpriteAnimation("CPZ/Syringe.bin", SCOPE_STAGE); }
156
#endif
157
158
void Reagent_Serialize(void) {}
159
160