Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/PGZ/PSZ2Setup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PSZ2Setup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPSZ2Setup *PSZ2Setup;
11
12
void PSZ2Setup_Update(void) {}
13
14
void PSZ2Setup_LateUpdate(void) {}
15
16
void PSZ2Setup_StaticUpdate(void)
17
{
18
if (--PSZ2Setup->petalAniDuration < 1) {
19
++PSZ2Setup->petalAniFrame;
20
PSZ2Setup->petalAniFrame &= 7;
21
PSZ2Setup->petalAniDuration = PSZ2Setup->petalAniDurationTable[PSZ2Setup->petalAniFrame];
22
23
int32 sheetY = 32 * PSZ2Setup->petalAniFrame;
24
RSDK.DrawAniTiles(PSZ2Setup->aniTiles1, 260, 0, sheetY, 64, 32);
25
RSDK.DrawAniTiles(PSZ2Setup->aniTiles1, 268, 80, sheetY, 48, 16);
26
RSDK.DrawAniTiles(PSZ2Setup->aniTiles1, 271, 64, sheetY + 16, 64, 16);
27
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 159, 0, sheetY, 16, 32);
28
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 276, 16, sheetY, 32, 16);
29
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 281, 16, sheetY + 16, 32, 16);
30
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 279, 48, sheetY, 32, 16);
31
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 286, 48, sheetY + 16, 32, 16);
32
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 284, 80, sheetY, 32, 16);
33
RSDK.DrawAniTiles(PSZ2Setup->aniTiles2, 289, 80, sheetY + 16, 32, 16);
34
}
35
36
RSDK.SetLimitedFade(0, 1, 2, abs(RSDK.Sin256(16 * Zone->timer)), 224, 227);
37
38
if (PSZ2Setup->petalBehaviourActive) {
39
if (PSZ2Setup->petalTimer <= 0) {
40
foreach_active(Player, player)
41
{
42
Hitbox *playerHitbox = Player_GetHitbox(player);
43
44
uint16 tile = RSDK.GetTile(Zone->fgLayer[0], player->position.x >> 20, (player->position.y + (playerHitbox->bottom << 16)) >> 20);
45
bool32 isLowLayer = true;
46
if (tile == (uint16)-1) {
47
tile = RSDK.GetTile(Zone->fgLayer[1], player->position.x >> 20, (player->position.y + (playerHitbox->bottom << 16)) >> 20);
48
isLowLayer = false;
49
}
50
51
if (RSDK.GetTileFlags(tile, player->collisionPlane)) {
52
if (abs(player->groundVel) >= 0x60000 || player->state == Player_State_DropDash) {
53
RSDK_THIS(PSZ2Setup); // not sure what this is meant to be since this is a StaticUpdate event...
54
55
EntityPetalPile *pile = CREATE_ENTITY(PetalPile, self, player->position.x, player->position.y + (playerHitbox->bottom << 16));
56
pile->leafPattern = PETALPILE_PATTERN_4;
57
pile->tileLayer = isLowLayer;
58
pile->pileSize.x = 0x40000;
59
pile->pileSize.y = 0x40000;
60
pile->noRemoveTiles = true;
61
pile->petalRadius = 0xB5555;
62
pile->petalDir = 2 * (player->direction != FLIP_NONE) - 1;
63
pile->petalVel = player->groundVel >> 1;
64
PSZ2Setup->petalTimer = 3;
65
}
66
}
67
}
68
}
69
else {
70
PSZ2Setup->petalTimer--;
71
}
72
}
73
}
74
75
void PSZ2Setup_Draw(void) {}
76
77
void PSZ2Setup_Create(void *data) {}
78
79
void PSZ2Setup_StageLoad(void)
80
{
81
PSZ2Setup->petalBehaviourActive = false;
82
83
GenericTrigger->callbacks[GENERICTRIGGER_PSZ2_PETALSINACTIVE] = PSZ2Setup_Trigger_DeactivatePetalBehaviour;
84
GenericTrigger->callbacks[GENERICTRIGGER_PSZ2_PETALSACTIVE] = PSZ2Setup_Trigger_ActivatePetalBehaviour;
85
86
PSZ2Setup->aniTiles1 = RSDK.LoadSpriteSheet("PSZ2/AniTiles.gif", SCOPE_STAGE);
87
PSZ2Setup->aniTiles2 = RSDK.LoadSpriteSheet("PSZ2/AniTiles2.gif", SCOPE_STAGE);
88
89
if (!isMainGameMode() || !globals->atlEnabled || CutsceneRules_CheckStageReload()) {
90
Zone->cameraBoundsL[0] = 1024;
91
Zone->cameraBoundsL[1] = 1024;
92
Zone->cameraBoundsL[2] = 1024;
93
Zone->cameraBoundsL[3] = 1024;
94
FXFade_StopAll();
95
}
96
else {
97
Zone->cameraBoundsB[0] = 1556;
98
Zone->cameraBoundsB[1] = 1556;
99
Zone->cameraBoundsB[2] = 1556;
100
Zone->cameraBoundsB[3] = 1556;
101
PSZ2Setup_ActTransitionLoad();
102
}
103
104
if (isMainGameMode() && CutsceneRules_IsAct2())
105
Zone->stageFinishCallback = PSZ2Setup_StageFinish_EndAct2;
106
107
#if MANIA_USE_PLUS
108
if (SceneInfo->filter & FILTER_ENCORE)
109
RSDK.LoadPalette(0, "EncorePSZ2.act", 0b0000000011111111);
110
111
// Fun Fact: Pre-Plus didn't have animal types set for PGZ! It'd always be flickies due to that being the default value!
112
Animals->animalTypes[0] = ANIMAL_POCKY;
113
Animals->animalTypes[1] = ANIMAL_BECKY;
114
#endif
115
}
116
117
void PSZ2Setup_Trigger_ActivatePetalBehaviour(void) { PSZ2Setup->petalBehaviourActive = true; }
118
119
void PSZ2Setup_Trigger_DeactivatePetalBehaviour(void) { PSZ2Setup->petalBehaviourActive = false; }
120
121
void PSZ2Setup_ActTransitionLoad(void)
122
{
123
SaveGame_LoadPlayerState();
124
Zone_ReloadStoredEntities(472 << 16, 1556 << 16, false);
125
126
globals->recallEntities = false;
127
globals->restartMilliseconds = 0;
128
globals->restartSeconds = 0;
129
globals->restartMinutes = 0;
130
memset(globals->atlEntityData, 0, TEMPENTITY_START * sizeof(int32));
131
132
Zone->cameraBoundsL[0] = 0;
133
Zone->cameraBoundsR[0] = 944;
134
Zone->cameraBoundsT[0] = 0;
135
Zone->cameraBoundsB[0] = 1556;
136
Zone->cameraBoundsL[1] = 0;
137
Zone->cameraBoundsR[1] = 944;
138
Zone->cameraBoundsT[1] = 0;
139
Zone->cameraBoundsB[1] = 1556;
140
Zone->cameraBoundsL[2] = 0;
141
Zone->cameraBoundsR[2] = 944;
142
Zone->cameraBoundsT[2] = 0;
143
Zone->cameraBoundsB[2] = 1556;
144
Zone->cameraBoundsL[3] = 0;
145
Zone->cameraBoundsR[3] = 944;
146
Zone->cameraBoundsT[3] = 0;
147
Zone->cameraBoundsB[3] = 1556;
148
}
149
150
void PSZ2Setup_StageFinish_EndAct2(void) { CREATE_ENTITY(PSZ2Outro, NULL, 0, 0); }
151
152
#if GAME_INCLUDE_EDITOR
153
void PSZ2Setup_EditorDraw(void) {}
154
155
void PSZ2Setup_EditorLoad(void)
156
{
157
RSDK_ACTIVE_VAR(GenericTrigger, triggerID);
158
RSDK_ENUM_VAR("Stop Petal Behaviour", GENERICTRIGGER_PSZ2_PETALSINACTIVE);
159
RSDK_ENUM_VAR("Start Petal Behaviour", GENERICTRIGGER_PSZ2_PETALSACTIVE);
160
}
161
#endif
162
163
void PSZ2Setup_Serialize(void) {}
164
165