Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/PGZ/Newspaper.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Newspaper Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectNewspaper *Newspaper;
11
12
void Newspaper_Update(void)
13
{
14
#if MANIA_USE_PLUS
15
RSDK_THIS(Newspaper);
16
17
StateMachine_Run(self->state);
18
#else
19
Platform_Update();
20
#endif
21
}
22
23
void Newspaper_LateUpdate(void) {}
24
25
void Newspaper_StaticUpdate(void) {}
26
27
void Newspaper_Draw(void)
28
{
29
RSDK_THIS(Newspaper);
30
31
#if MANIA_USE_PLUS
32
RSDK.DrawSprite(&self->animator, NULL, false);
33
#else
34
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
35
#endif
36
}
37
38
void Newspaper_Create(void *data)
39
{
40
RSDK_THIS(Newspaper);
41
42
#if MANIA_USE_PLUS
43
if (!SceneInfo->inEditor) {
44
self->visible = true;
45
self->active = ACTIVE_BOUNDS;
46
self->updateRange.x = 0x400000;
47
self->updateRange.y = 0x400000;
48
RSDK.SetSpriteAnimation(Newspaper->aniFrames, 1, &self->animator, true, self->type);
49
switch (self->type) {
50
case NEWSPAPER_WHITE_FG:
51
case NEWSPAPER_BLUE_FG:
52
self->state = Newspaper_HandleInteractions;
53
self->drawGroup = Zone->playerDrawGroup[0];
54
break;
55
56
case NEWSPAPER_WHITE_BG:
57
case NEWSPAPER_BLUE_BG: self->drawGroup = Zone->objectDrawGroup[0]; break;
58
59
default: break;
60
}
61
62
self->hitbox.left = -16;
63
self->hitbox.top = -16;
64
self->hitbox.right = 16;
65
self->hitbox.bottom = 16;
66
}
67
68
#else
69
self->collision = PLATFORM_C_SOLID;
70
self->type = PLATFORM_PATH;
71
Platform_Create(NULL);
72
RSDK.SetSpriteAnimation(Newspaper->aniFrames, 0, &self->animator, true, 0);
73
#endif
74
}
75
76
void Newspaper_StageLoad(void)
77
{
78
#if MANIA_USE_PLUS
79
Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);
80
81
Newspaper->sfxPaperStack = RSDK.GetSfx("PSZ/PaperStack.wav");
82
#else
83
if (RSDK.CheckSceneFolder("PSZ1"))
84
Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);
85
#endif
86
}
87
88
#if MANIA_USE_PLUS
89
void Newspaper_HandleInteractions(void)
90
{
91
RSDK_THIS(Newspaper);
92
93
if (self->timer <= 0) {
94
foreach_active(Player, player)
95
{
96
if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {
97
int32 x = self->position.x + RSDK.Rand(-0x80000, 0x80000);
98
int32 y = self->position.y + RSDK.Rand(-0x80000, 0x80000);
99
EntityDebris *debris = CREATE_ENTITY(Debris, NULL, x, y);
100
101
debris->state = Debris_State_Fall;
102
debris->gravityStrength = 0x400;
103
debris->velocity.x = RSDK.Rand(0, 0x20000);
104
debris->timer = 240;
105
self->timer = 2;
106
if (debris->position.x < self->position.x)
107
debris->velocity.x = -debris->velocity.x;
108
debris->drawGroup = Zone->objectDrawGroup[0];
109
RSDK.SetSpriteAnimation(Newspaper->aniFrames, RSDK.Rand(0, 2) + 2, &debris->animator, true, RSDK.Rand(0, 6));
110
111
if (Newspaper->sfxPaperStack) {
112
RSDK.PlaySfx(Newspaper->sfxPaperStack, false, 255);
113
Newspaper->sfxPaperStack = 0;
114
}
115
}
116
}
117
}
118
else {
119
self->timer--;
120
}
121
}
122
#endif
123
124
#if GAME_INCLUDE_EDITOR
125
void Newspaper_EditorDraw(void)
126
{
127
RSDK_THIS(Newspaper);
128
129
#if MANIA_USE_PLUS
130
self->active = ACTIVE_BOUNDS;
131
self->updateRange.x = 0x400000;
132
self->updateRange.y = 0x400000;
133
134
RSDK.SetSpriteAnimation(Newspaper->aniFrames, 1, &self->animator, true, self->type);
135
136
switch (self->type) {
137
case NEWSPAPER_WHITE_FG:
138
case NEWSPAPER_BLUE_FG:
139
self->state = Newspaper_HandleInteractions;
140
self->drawGroup = Zone->playerDrawGroup[0];
141
break;
142
143
case NEWSPAPER_WHITE_BG:
144
case NEWSPAPER_BLUE_BG: self->drawGroup = Zone->objectDrawGroup[0]; break;
145
default: break;
146
}
147
148
#else
149
RSDK.SetSpriteAnimation(Newspaper->aniFrames, 0, &self->animator, true, 0);
150
self->centerPos = self->position;
151
self->drawPos = self->position;
152
#endif
153
154
Newspaper_Draw();
155
156
#if !MANIA_USE_PLUS
157
if (showGizmos()) {
158
RSDK_DRAWING_OVERLAY(true);
159
160
for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {
161
Entity *child = RSDK_GET_ENTITY_GEN(s + i);
162
if (!child)
163
continue;
164
165
DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);
166
}
167
168
Entity *targetNode = RSDK_GET_ENTITY_GEN(self->node);
169
if (targetNode)
170
DrawHelpers_DrawArrow(self->position.x, self->position.y, targetNode->position.x, targetNode->position.y, 0xFFFF00, INK_NONE, 0xFF);
171
172
RSDK_DRAWING_OVERLAY(false);
173
}
174
#endif
175
}
176
177
void Newspaper_EditorLoad(void)
178
{
179
#if MANIA_USE_PLUS
180
Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);
181
182
RSDK_ACTIVE_VAR(Newspaper, type);
183
RSDK_ENUM_VAR("White (FG)", NEWSPAPER_WHITE_FG);
184
RSDK_ENUM_VAR("Blue (FG)", NEWSPAPER_WHITE_FG);
185
RSDK_ENUM_VAR("White (BG)", NEWSPAPER_WHITE_BG);
186
RSDK_ENUM_VAR("Blue (BG)", NEWSPAPER_WHITE_BG);
187
188
#else
189
if (RSDK.CheckSceneFolder("PSZ1"))
190
Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);
191
#endif
192
}
193
#endif
194
195
void Newspaper_Serialize(void)
196
{
197
#if MANIA_USE_PLUS
198
RSDK_EDITABLE_VAR(Newspaper, VAR_UINT8, type);
199
#else
200
RSDK_EDITABLE_VAR(Newspaper, VAR_ENUM, node); // slotID of the target PlatformNode
201
RSDK_EDITABLE_VAR(Newspaper, VAR_ENUM, childCount);
202
#endif
203
}
204
205