Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/PGZ/PSZ1Setup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PSZ1Setup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPSZ1Setup *PSZ1Setup;
11
12
void PSZ1Setup_Update(void) {}
13
14
void PSZ1Setup_LateUpdate(void) {}
15
16
void PSZ1Setup_StaticUpdate(void)
17
{
18
PSZ1Setup->newspaperHAniFrame -= 8;
19
PSZ1Setup->newspaperHAniFrame &= 0x3F;
20
21
PSZ1Setup->newspaperVAniFrame += 4;
22
if (PSZ1Setup->newspaperVAniFrame == 80)
23
PSZ1Setup->newspaperVAniFrame = 0;
24
25
RSDK.DrawAniTiles(PSZ1Setup->aniTiles2, 985, 0, PSZ1Setup->newspaperVAniFrame, 48, 80);
26
RSDK.DrawAniTiles(PSZ1Setup->aniTiles3, 716, PSZ1Setup->newspaperHAniFrame, 0, 64, 48);
27
28
if (!(Zone->timer & 1))
29
RSDK.RotatePalette(0, 236, 239, false);
30
31
if (++PSZ1Setup->inkRollerAniDuration == 3) {
32
PSZ1Setup->inkRollerAniDuration = 0;
33
34
++PSZ1Setup->inkRollerAniFrame;
35
PSZ1Setup->inkRollerAniFrame &= 0xF;
36
37
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 552, 16 * PSZ1Setup->inkRollerAniFrame, 0, 16, 128);
38
}
39
40
if (--PSZ1Setup->buttonFrontAniDuration < 1) {
41
++PSZ1Setup->buttonFrontAniFrame;
42
43
PSZ1Setup->buttonFrontAniFrame %= 7;
44
PSZ1Setup->buttonFrontAniDuration = PSZ1Setup->buttonSideAniDurationTable[PSZ1Setup->buttonFrontAniFrame];
45
46
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 216, 16 * PSZ1Setup->buttonFrontAniFrame, 128, 16, 16);
47
}
48
49
if (--PSZ1Setup->buttonBackAniDuration < 1) {
50
++PSZ1Setup->buttonBackAniFrame;
51
52
PSZ1Setup->buttonBackAniFrame %= 7;
53
PSZ1Setup->buttonBackAniDuration = PSZ1Setup->buttonSideAniDurationTable[PSZ1Setup->buttonBackAniFrame];
54
55
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 217, 16 * (PSZ1Setup->buttonBackAniFrame + 7), 128, 16, 16);
56
}
57
58
if (--PSZ1Setup->buttonSideFrontAniDuration < 1) {
59
++PSZ1Setup->buttonSideFrontAniFrame;
60
61
PSZ1Setup->buttonSideFrontAniFrame %= 14;
62
PSZ1Setup->buttonSideFrontAniDuration = PSZ1Setup->buttonSideBackAniDurationTable[PSZ1Setup->buttonSideFrontAniFrame];
63
64
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 218, 16 * PSZ1Setup->buttonSideFrontAniFrame, 144, 16, 32);
65
}
66
67
if (--PSZ1Setup->buttonSideBackAniDuration < 1) {
68
++PSZ1Setup->buttonSideBackAniFrame;
69
70
PSZ1Setup->buttonSideBackAniFrame %= 14;
71
PSZ1Setup->buttonSideBackAniDuration = PSZ1Setup->buttonSideBackAniDurationTable[PSZ1Setup->buttonSideBackAniFrame];
72
73
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 220, 16 * PSZ1Setup->buttonSideBackAniFrame, 176, 16, 48);
74
}
75
76
if (--PSZ1Setup->buttonSideAniDuration < 1) {
77
++PSZ1Setup->buttonSideAniFrame;
78
79
PSZ1Setup->buttonSideAniFrame %= 7;
80
PSZ1Setup->buttonSideAniDuration = PSZ1Setup->buttonSideAniDurationTable[PSZ1Setup->buttonSideAniFrame];
81
82
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 223, 16 * PSZ1Setup->buttonSideAniFrame, 224, 16, 32);
83
}
84
85
if (!(Zone->timer & 1)) {
86
++PSZ1Setup->buttonBladeAniFrame;
87
88
PSZ1Setup->buttonBladeAniFrame %= 3;
89
switch (PSZ1Setup->buttonBladeAniFrame) {
90
case 0: RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 227, 112, 224, 48, 32); break;
91
92
case 1:
93
case 3: RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 227, 160, 224, 48, 32); break;
94
95
case 2: RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 227, 208, 224, 48, 32); break;
96
97
default: break;
98
}
99
}
100
101
if (Zone->cameraBoundsB[0] == 2944) {
102
EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
103
104
if (player->position.y < 0xAA00000) {
105
if (player->position.y <= 0x900000) {
106
EntityCamera *camera = player->camera;
107
108
camera->position.y += 0xA000000;
109
camera->center.y += 0xA00;
110
ScreenInfo[camera->screenID].position.y += 0xA00;
111
player->position.y += 0xA000000;
112
113
TileLayer *background1 = RSDK.GetTileLayer(0);
114
TileLayer *background2 = RSDK.GetTileLayer(1);
115
background1->scrollPos -= 0xA00000;
116
background2->scrollPos -= 0x2800000;
117
118
if (background1->scrollPos < 0)
119
background1->scrollPos += 0x4000000;
120
121
if (background2->scrollPos < 0)
122
background2->scrollPos += 0x6000000;
123
124
if (ScreenInfo->position.y >= 0x180)
125
ScreenInfo->position.y += 0xA00;
126
}
127
}
128
else {
129
EntityCamera *camera = player->camera;
130
131
camera->position.y -= 0xA000000;
132
camera->center.y -= 0xA00;
133
ScreenInfo[camera->screenID].position.y -= 0xA00;
134
player->position.y -= 0xA000000;
135
136
TileLayer *background1 = RSDK.GetTileLayer(0);
137
TileLayer *background2 = RSDK.GetTileLayer(1);
138
background1->scrollPos += 0xA00000;
139
background2->scrollPos += 0x2800000;
140
141
if (background1->scrollPos >= 0x6E000000)
142
background1->scrollPos -= 0x4000000;
143
144
if (background2->scrollPos >= 0x6E000000)
145
background2->scrollPos -= 0x6000000;
146
147
if (ScreenInfo->position.y >= 0xA00)
148
ScreenInfo->position.y -= 0xA00;
149
}
150
151
if (player->camera->position.y < 0x6100000) {
152
if (player->camera->position.y <= 0x2800000) {
153
if (PSZ1Setup->levelWrapType == PSZ1_WRAP_BOTTOM) {
154
PSZ1Setup->levelWrapType = PSZ1_WRAP_TOP;
155
PSZ1Setup_LevelWrap_Top();
156
}
157
}
158
}
159
else {
160
if (PSZ1Setup->levelWrapType == PSZ1_WRAP_TOP) {
161
PSZ1Setup->levelWrapType = PSZ1_WRAP_BOTTOM;
162
PSZ1Setup_LevelWrap_Bottom();
163
}
164
}
165
}
166
167
if (PSZ1Setup->petalBehaviourActive) {
168
if (PSZ1Setup->petalTimer <= 0) {
169
foreach_active(Player, player)
170
{
171
Hitbox *playerHitbox = Player_GetHitbox(player);
172
173
uint16 tile = RSDK.GetTile(Zone->fgLayer[0], player->position.x >> 20, (player->position.y + (playerHitbox->bottom << 16)) >> 20);
174
bool32 isLowLayer = true;
175
if (tile == (uint16)-1) {
176
tile = RSDK.GetTile(Zone->fgLayer[1], player->position.x >> 20, (player->position.y + (playerHitbox->bottom << 16)) >> 20);
177
isLowLayer = false;
178
}
179
180
if (RSDK.GetTileFlags(tile, player->collisionPlane)) {
181
if (abs(player->groundVel) >= 0x60000 || player->state == Player_State_DropDash) {
182
RSDK_THIS(PSZ1Setup); // not sure what this is meant to be since this is a StaticUpdate event...
183
184
EntityPetalPile *pile = CREATE_ENTITY(PetalPile, self, player->position.x, player->position.y + (playerHitbox->bottom << 16));
185
pile->leafPattern = PETALPILE_PATTERN_4;
186
pile->tileLayer = isLowLayer;
187
pile->pileSize.x = 0x40000;
188
pile->pileSize.y = 0x40000;
189
pile->noRemoveTiles = true;
190
pile->petalRadius = 0xB5555;
191
pile->petalDir = 2 * (player->direction != FLIP_NONE) - 1;
192
pile->petalVel = player->groundVel >> 1;
193
PSZ1Setup->petalTimer = 3;
194
}
195
}
196
}
197
}
198
else {
199
PSZ1Setup->petalTimer--;
200
}
201
}
202
}
203
204
void PSZ1Setup_Draw(void) {}
205
206
void PSZ1Setup_Create(void *data) {}
207
208
void PSZ1Setup_StageLoad(void)
209
{
210
PSZ1Setup->aniTiles1 = RSDK.LoadSpriteSheet("PSZ1/AniTiles.gif", SCOPE_STAGE);
211
PSZ1Setup->aniTiles2 = RSDK.LoadSpriteSheet("PSZ1/AniTiles2.gif", SCOPE_STAGE);
212
PSZ1Setup->aniTiles3 = RSDK.LoadSpriteSheet("PSZ1/AniTiles3.gif", SCOPE_STAGE);
213
214
PSZ1Setup->petalBehaviourActive = false;
215
PSZ1Setup->levelWrapType = PSZ1_WRAP_TOP;
216
217
GenericTrigger->callbacks[GENERICTRIGGER_PSZ1_PETALSINACTIVE] = PSZ1Setup_Trigger_DeactivatePetalBehaviour;
218
GenericTrigger->callbacks[GENERICTRIGGER_PSZ1_PETALSACTIVE] = PSZ1Setup_Trigger_ActivatePetalBehaviour;
219
GenericTrigger->callbacks[GENERICTRIGGER_PSZ1_ACHIEVEMENT] = PSZ1Setup_Trigger_AwardAchievement;
220
221
PSZ1Setup->buttonFrontAniDuration = 12;
222
PSZ1Setup->buttonFrontAniFrame = 0;
223
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 216, 0, 128, 16, 16);
224
225
PSZ1Setup->buttonBackAniDuration = 24;
226
PSZ1Setup->buttonBackAniFrame = 0;
227
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 217, 112, 128, 16, 16);
228
229
PSZ1Setup->buttonSideFrontAniDuration = 36;
230
PSZ1Setup->buttonSideFrontAniFrame = 0;
231
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 218, 0, 144, 16, 32);
232
233
PSZ1Setup->buttonSideBackAniDuration = 48;
234
PSZ1Setup->buttonSideBackAniFrame = 0;
235
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 220, 0, 176, 16, 48);
236
237
PSZ1Setup->buttonSideAniDuration = 64;
238
PSZ1Setup->buttonSideAniFrame = 0;
239
RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 223, 0, 224, 16, 32);
240
241
if (isMainGameMode() && CutsceneRules_IsAct1())
242
Zone->stageFinishCallback = PSZ1Setup_StageFinish_EndAct1;
243
244
#if MANIA_USE_PLUS
245
if (SceneInfo->filter & FILTER_ENCORE)
246
RSDK.LoadPalette(0, "EncorePSZ1.act", 0b0000000011111111);
247
248
// Fun Fact: Pre-Plus didn't have animal types set for PGZ! It'd always be flickies due to that being the default value!
249
Animals->animalTypes[0] = ANIMAL_POCKY;
250
Animals->animalTypes[1] = ANIMAL_BECKY;
251
252
BGSwitch->switchCallback[PSZ1_BG_INSIDE] = PSZ1Setup_BGSwitch_Inside;
253
BGSwitch->switchCallback[PSZ1_BG_OUTSIDE] = PSZ1Setup_BGSwitch_Outside;
254
255
BGSwitch->layerIDs[0] = PSZ1_BG_INSIDE;
256
BGSwitch->layerIDs[1] = PSZ1_BG_INSIDE;
257
BGSwitch->layerIDs[2] = PSZ1_BG_INSIDE;
258
BGSwitch->layerIDs[3] = PSZ1_BG_INSIDE;
259
#endif
260
}
261
262
#if MANIA_USE_PLUS
263
void PSZ1Setup_BGSwitch_Inside(void)
264
{
265
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0; // Background 1
266
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0; // Background 2
267
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = 0; // Background 3
268
}
269
270
void PSZ1Setup_BGSwitch_Outside(void)
271
{
272
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0; // Background 1
273
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT; // Background 2
274
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT; // Background 3
275
}
276
#endif
277
278
void PSZ1Setup_Trigger_DeactivatePetalBehaviour(void) { PSZ1Setup->petalBehaviourActive = true; }
279
280
void PSZ1Setup_Trigger_ActivatePetalBehaviour(void) { PSZ1Setup->petalBehaviourActive = false; }
281
282
void PSZ1Setup_Trigger_AwardAchievement(void)
283
{
284
RSDK_THIS(GenericTrigger);
285
286
if (!PSZ1Setup->hasAchievement) {
287
int32 count = 0;
288
foreach_all(Crate, crate)
289
{
290
if (MathHelpers_PointInHitbox(self->position.x, self->position.y, crate->position.x, crate->position.y, self->direction, &self->hitbox)) {
291
if (crate->frameID == 1)
292
++count;
293
}
294
}
295
296
if (!count) {
297
API_UnlockAchievement(&achievementList[ACH_PGZ]);
298
PSZ1Setup->hasAchievement = true;
299
}
300
}
301
}
302
303
void PSZ1Setup_StageFinish_EndAct1(void)
304
{
305
++SceneInfo->listPos;
306
globals->enableIntro = true;
307
globals->suppressTitlecard = true;
308
globals->suppressAutoMusic = true;
309
310
for (int32 p = 0; p < Player->playerCount; ++p) StarPost->postIDs[p] = 0;
311
312
SaveGame_SavePlayerState();
313
Zone_StoreEntities(15876 << 16, 1316 << 16);
314
315
RSDK.LoadScene();
316
}
317
318
void PSZ1Setup_LevelWrap_Top(void)
319
{
320
for (int32 i = 1; i < ENTITY_COUNT; ++i) {
321
EntityPlatform *entity = RSDK_GET_ENTITY(i, Platform);
322
if (entity->classID != BoundsMarker->classID) {
323
if (entity->position.y >= 0x6800000) {
324
entity->position.y -= 0xA000000;
325
326
if (entity->classID == PrintBlock->classID || entity->classID == Platform->classID || entity->classID == Crate->classID) {
327
EntityPlatform *platform = entity;
328
platform->drawPos.y -= 0xA000000;
329
platform->centerPos.y -= 0xA000000;
330
}
331
}
332
}
333
}
334
}
335
336
void PSZ1Setup_LevelWrap_Bottom(void)
337
{
338
for (int32 i = 1; i < ENTITY_COUNT; ++i) {
339
EntityPlatform *entity = RSDK_GET_ENTITY(i, Platform);
340
if (entity->classID != BoundsMarker->classID) {
341
if (entity->position.y <= 0x1800000) {
342
entity->position.y += 0xA000000;
343
344
if (entity->classID == PrintBlock->classID || entity->classID == Platform->classID || entity->classID == Crate->classID) {
345
EntityPlatform *platform = entity;
346
platform->drawPos.y += 0xA000000;
347
platform->centerPos.y += 0xA000000;
348
}
349
}
350
}
351
}
352
}
353
354
#if GAME_INCLUDE_EDITOR
355
void PSZ1Setup_EditorDraw(void) {}
356
357
void PSZ1Setup_EditorLoad(void)
358
{
359
RSDK_ACTIVE_VAR(BGSwitch, bgID);
360
RSDK_ENUM_VAR("Inside BG", PSZ1_BG_INSIDE);
361
RSDK_ENUM_VAR("Outside BG", PSZ1_BG_OUTSIDE);
362
363
RSDK_ACTIVE_VAR(GenericTrigger, triggerID);
364
RSDK_ENUM_VAR("Stop Petal Behaviour", GENERICTRIGGER_PSZ1_PETALSINACTIVE);
365
RSDK_ENUM_VAR("Start Petal Behaviour", GENERICTRIGGER_PSZ1_PETALSACTIVE);
366
RSDK_ENUM_VAR("PSZ1 Achievement Area", GENERICTRIGGER_PSZ1_ACHIEVEMENT);
367
}
368
#endif
369
370
void PSZ1Setup_Serialize(void) {}
371
372