Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/PGZ/PrintBlock.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PrintBlock Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPrintBlock *PrintBlock;
11
12
void PrintBlock_Update(void)
13
{
14
RSDK_THIS(PrintBlock);
15
16
if (self->state == Platform_State_Fixed) {
17
if (self->interval != (uint16)-1) {
18
int32 timer = (Zone->timer + self->intervalOffset) % self->interval;
19
20
if (timer >= self->duration) {
21
if (timer >= self->duration + 12) {
22
self->animator.frameID = 1;
23
self->animator.timer = 0;
24
}
25
else {
26
self->active = ACTIVE_NORMAL;
27
self->state = PrintBlock_State_Disappear;
28
self->timer = timer - self->duration;
29
self->animator.frameID = 4 - self->timer / 3;
30
self->animator.timer = self->timer % 3;
31
}
32
}
33
else {
34
self->active = ACTIVE_NORMAL;
35
self->timer = timer;
36
if (self->timer > 12) {
37
self->animator.frameID = 4;
38
self->animator.timer = 0;
39
}
40
else {
41
self->animator.timer = self->timer % 3;
42
self->animator.frameID = self->timer / 3 + 1;
43
}
44
45
Vector2 pos;
46
pos.x = 0x200000;
47
pos.y = 0x200000;
48
if (RSDK.CheckOnScreen(self, &pos)) {
49
int32 channel = RSDK.PlaySfx(PrintBlock->sfxLetter, false, 255);
50
RSDK.SetChannelAttributes(channel, 1.0, 0.0, 1.0);
51
}
52
53
self->state = PrintBlock_State_Appear;
54
}
55
}
56
}
57
58
if (self->animator.frameID <= 2) {
59
self->stateCollide = Platform_Collision_None;
60
self->collision = PLATFORM_C_NONE;
61
}
62
else {
63
self->stateCollide = Platform_Collision_Solid;
64
self->collision = PLATFORM_C_SOLID;
65
}
66
67
Platform_Update();
68
}
69
70
void PrintBlock_LateUpdate(void) {}
71
72
void PrintBlock_StaticUpdate(void) {}
73
74
void PrintBlock_Draw(void)
75
{
76
RSDK_THIS(PrintBlock);
77
78
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
79
80
self->inkEffect = INK_SUB;
81
PrintBlock->animator.frameID = self->animator.frameID;
82
RSDK.DrawSprite(&PrintBlock->animator, &self->drawPos, false);
83
84
self->inkEffect = INK_NONE;
85
}
86
87
void PrintBlock_Create(void *data)
88
{
89
RSDK_THIS(PrintBlock);
90
91
self->collision = PLATFORM_C_SOLID;
92
Platform_Create(NULL);
93
94
RSDK.SetSpriteAnimation(PrintBlock->aniFrames, self->letter, &self->animator, true, 0);
95
96
self->alpha = 128;
97
self->drawGroup = Zone->objectDrawGroup[0];
98
self->state = Platform_State_Fixed;
99
}
100
101
void PrintBlock_StageLoad(void)
102
{
103
if (RSDK.CheckSceneFolder("PSZ1"))
104
PrintBlock->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PrintBlock.bin", SCOPE_STAGE);
105
106
RSDK.SetSpriteAnimation(PrintBlock->aniFrames, 12, &PrintBlock->animator, true, 0);
107
108
PrintBlock->sfxLetter = RSDK.GetSfx("PSZ/Letter.wav");
109
}
110
111
void PrintBlock_State_Appear(void)
112
{
113
RSDK_THIS(PrintBlock);
114
115
++self->timer;
116
if (++self->animator.timer == 3) {
117
self->animator.timer = 0;
118
if (self->animator.frameID < 4)
119
self->animator.frameID++;
120
}
121
122
if (self->timer == self->duration)
123
self->state = PrintBlock_State_Disappear;
124
}
125
126
void PrintBlock_State_Disappear(void)
127
{
128
RSDK_THIS(PrintBlock);
129
130
if (++self->animator.timer == 3) {
131
self->animator.timer = 0;
132
133
if (self->animator.frameID <= 1) {
134
self->active = ACTIVE_BOUNDS;
135
self->state = Platform_State_Fixed;
136
}
137
else {
138
self->animator.frameID--;
139
}
140
}
141
}
142
143
#if GAME_INCLUDE_EDITOR
144
void PrintBlock_EditorDraw(void)
145
{
146
RSDK_THIS(PrintBlock);
147
148
RSDK.SetSpriteAnimation(PrintBlock->aniFrames, self->letter, &self->animator, true, self->interval == (uint16)-1 ? 0 : 4);
149
self->alpha = 0x80;
150
self->drawPos = self->position;
151
152
PrintBlock_Draw();
153
154
if (showGizmos()) {
155
RSDK_DRAWING_OVERLAY(true);
156
157
for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {
158
Entity *child = RSDK_GET_ENTITY_GEN(s + i);
159
if (!child)
160
continue;
161
162
DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);
163
}
164
165
RSDK_DRAWING_OVERLAY(false);
166
}
167
}
168
169
void PrintBlock_EditorLoad(void)
170
{
171
PrintBlock->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PrintBlock.bin", SCOPE_STAGE);
172
173
RSDK.SetSpriteAnimation(-1, 12, &PrintBlock->animator, true, 0);
174
175
RSDK_ACTIVE_VAR(PrintBlock, letter);
176
RSDK_ENUM_VAR("E", PRINTBLOCK_LETTER_E);
177
RSDK_ENUM_VAR("T", PRINTBLOCK_LETTER_T);
178
RSDK_ENUM_VAR("A", PRINTBLOCK_LETTER_A);
179
RSDK_ENUM_VAR("O", PRINTBLOCK_LETTER_O);
180
RSDK_ENUM_VAR("I", PRINTBLOCK_LETTER_I);
181
RSDK_ENUM_VAR("N", PRINTBLOCK_LETTER_N);
182
RSDK_ENUM_VAR("S", PRINTBLOCK_LETTER_S);
183
RSDK_ENUM_VAR("H", PRINTBLOCK_LETTER_H);
184
RSDK_ENUM_VAR("R", PRINTBLOCK_LETTER_R);
185
RSDK_ENUM_VAR("D", PRINTBLOCK_LETTER_D);
186
RSDK_ENUM_VAR("L", PRINTBLOCK_LETTER_L);
187
RSDK_ENUM_VAR("U", PRINTBLOCK_LETTER_U);
188
}
189
#endif
190
191
void PrintBlock_Serialize(void)
192
{
193
RSDK_EDITABLE_VAR(PrintBlock, VAR_ENUM, childCount);
194
RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT16, interval);
195
RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT16, intervalOffset);
196
RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT16, duration);
197
RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT8, letter);
198
}
199
200