Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/MSZ/MSZSetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: MSZSetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectMSZSetup *MSZSetup;
11
12
void MSZSetup_Update(void)
13
{
14
RSDK_THIS(MSZSetup);
15
StateMachine_Run(self->state);
16
}
17
18
void MSZSetup_LateUpdate(void) {}
19
20
void MSZSetup_StaticUpdate(void)
21
{
22
if (MSZSetup->usingRegularPalette) {
23
if (!(Zone->timer & 3))
24
++MSZSetup->background1->deformationOffset;
25
26
MSZSetup->fadeTimer += 6;
27
if (MSZSetup->fadeTimer > 255) {
28
MSZSetup->fadeTimer -= 256;
29
RSDK.RotatePalette(1, 204, 207, false);
30
RSDK.RotatePalette(2, 204, 207, false);
31
}
32
33
RSDK.SetLimitedFade(0, 1, 2, MSZSetup->fadeTimer, 204, 207);
34
}
35
36
if (!(Zone->timer & 3))
37
RSDK.RotatePalette(0, 240, 243, false);
38
39
--MSZSetup->bladeCactusFlowerAniTimer;
40
if (MSZSetup->bladeCactusFlowerAniTimer < 1) {
41
++MSZSetup->bladeCactusFlowerAniFrame;
42
MSZSetup->bladeCactusFlowerAniFrame %= 13;
43
MSZSetup->bladeCactusFlowerAniTimer = MSZSetup->bladeCactusFlowerAniDuration[MSZSetup->bladeCactusFlowerAniFrame];
44
45
RSDK.DrawAniTiles(MSZSetup->aniTiles, 720, 16 * ((MSZSetup->bladeCactusFlowerAniSprPos[MSZSetup->bladeCactusFlowerAniFrame] & 0xFFFC) + 8),
46
32 * (MSZSetup->bladeCactusFlowerAniSprPos[MSZSetup->bladeCactusFlowerAniFrame] & 3), 64, 32);
47
}
48
49
--MSZSetup->bobbingCactusFlowerAniTimer;
50
if (MSZSetup->bobbingCactusFlowerAniTimer < 1) {
51
++MSZSetup->bobbingCactusFlowerAniFrame;
52
MSZSetup->bobbingCactusFlowerAniFrame &= 7;
53
MSZSetup->bobbingCactusFlowerAniTimer = MSZSetup->bobbingCactusFlowerAniDuration[MSZSetup->bobbingCactusFlowerAniFrame];
54
RSDK.DrawAniTiles(MSZSetup->aniTiles, 74, 0, 16 * (MSZSetup->bobbingCactusFlowerAniFrame + 8), 80, 16);
55
}
56
57
if (!(Zone->timer & 3)) {
58
MSZSetup->spinningCactusFlowerAniFrame += 16;
59
MSZSetup->spinningCactusFlowerAniFrame &= 0x7F;
60
RSDK.DrawAniTiles(MSZSetup->aniTiles, 89, MSZSetup->spinningCactusFlowerAniFrame, 96, 16, 32);
61
}
62
63
MSZSetup->parallaxPos += MSZSetup->parallaxMult;
64
globals->tempFlags = MSZSetup->usingRegularPalette;
65
66
if (MSZSetup->starPostID != StarPost->postIDs[0]) {
67
MSZSetup->starPostID = StarPost->postIDs[0];
68
globals->restartFlags = MSZSetup->usingRegularPalette;
69
}
70
}
71
72
void MSZSetup_Draw(void) {}
73
74
void MSZSetup_Create(void *data)
75
{
76
RSDK_THIS(MSZSetup);
77
78
self->active = ACTIVE_NORMAL;
79
if (data)
80
self->state = (Type_StateMachine)data;
81
82
if (SceneInfo->minutes || SceneInfo->seconds || SceneInfo->milliseconds) {
83
if (SceneInfo->minutes == globals->tempMinutes && SceneInfo->seconds == globals->tempSeconds
84
&& SceneInfo->milliseconds == globals->tempMilliseconds)
85
MSZSetup->usingRegularPalette = globals->tempFlags;
86
else
87
MSZSetup->usingRegularPalette = globals->restartFlags;
88
}
89
else {
90
globals->restartFlags = 0;
91
globals->tempFlags = 0;
92
MSZSetup->usingRegularPalette = false;
93
}
94
95
if (MSZSetup->usingRegularPalette) {
96
#if MANIA_USE_PLUS
97
if (SceneInfo->filter & FILTER_ENCORE) {
98
RSDK.LoadPalette(0, "EncoreMSZ2.act", 0b0000000011111111);
99
self->state = MSZSetup_State_CheckTrainStart;
100
}
101
else {
102
#endif
103
for (int32 i = 0; i < 0x400; ++i) MSZSetup->background1->deformationData[i] = MSZSetup->deformData[i & 0x1F];
104
RSDK.CopyPalette(4, 128, 0, 128, 128);
105
destroyEntity(self);
106
#if MANIA_USE_PLUS
107
}
108
109
RSDK.CopyPalette(0, 128, 1, 128, 128);
110
RSDK.CopyPalette(0, 128, 2, 128, 128);
111
RSDK.RotatePalette(2, 204, 207, false);
112
#endif
113
}
114
#if MANIA_USE_PLUS
115
else if (SceneInfo->filter & FILTER_ENCORE) {
116
RSDK.LoadPalette(0, "EncoreMSZ1.act", 0b0000000011111111);
117
RSDK.CopyPalette(0, 128, 3, 128, 80);
118
RSDK.LoadPalette(4, "EncoreMSZ2.act", 0b0000000011111111);
119
}
120
#endif
121
else {
122
#if !MANIA_USE_PLUS
123
RSDK.CopyPalette(0, 204, 4, 204, 4);
124
#endif
125
RSDK.CopyPalette(3, 128, 0, 128, 128);
126
}
127
}
128
129
void MSZSetup_StageLoad(void)
130
{
131
MSZSetup->aniTiles = RSDK.LoadSpriteSheet("MSZ/AniTiles.gif", SCOPE_STAGE);
132
MSZSetup->background1 = RSDK.GetTileLayer(0);
133
134
if (RSDK.CheckSceneFolder("MSZCutscene")) {
135
RSDK.CopyPalette(0, 204, 4, 204, 4);
136
RSDK.CopyPalette(3, 128, 0, 128, 128);
137
138
MSZSetup_StoreBGParallax();
139
MSZSetup_ReloadBGParallax_Multiply(0x400);
140
}
141
else {
142
#if MANIA_USE_PLUS
143
GiantPistol->inCutscene = false;
144
MSZSetup->chuggaVolume = 0;
145
#endif
146
147
if (Zone->actID) {
148
MSZSetup->usingRegularPalette = true;
149
RSDK.CopyPalette(4, 128, 0, 128, 128);
150
#if MANIA_USE_PLUS
151
if (SceneInfo->filter & FILTER_ENCORE) {
152
RSDK.CopyPalette(0, 128, 5, 128, 128);
153
RSDK.LoadPalette(0, "EncoreMSZ2.act", 0b0000000011111111);
154
RSDK.CopyPalette(0, 128, 1, 128, 128);
155
RSDK.CopyPalette(0, 128, 2, 128, 128);
156
RSDK.RotatePalette(2, 204, 207, false);
157
}
158
else {
159
for (int32 i = 0; i < 0x400; ++i) MSZSetup->background1->deformationData[i] = MSZSetup->deformData[i & 0x1F];
160
}
161
#else
162
for (int32 i = 0; i < 0x400; ++i) MSZSetup->background1->deformationData[i] = MSZSetup->deformData[i & 0x1F];
163
#endif
164
165
#if MANIA_USE_PLUS
166
if (!(SceneInfo->filter & FILTER_ENCORE) && GET_CHARACTER_ID(1) == ID_KNUCKLES) {
167
#else
168
if (GET_CHARACTER_ID(1) == ID_KNUCKLES) {
169
#endif
170
Zone->cameraBoundsL[0] = 0;
171
Zone->cameraBoundsL[1] = 0;
172
Zone->cameraBoundsL[2] = 0;
173
Zone->cameraBoundsL[3] = 0;
174
175
if (!CutsceneRules_CheckStageReload() && CutsceneRules_CheckPlayerPos(TO_FIXED(76), TO_FIXED(324), TO_FIXED(500), TO_FIXED(564))) {
176
Zone->cameraBoundsB[0] = 564;
177
Zone->cameraBoundsB[1] = 564;
178
Zone->cameraBoundsB[2] = 564;
179
Zone->cameraBoundsB[3] = 564;
180
}
181
182
if (isMainGameMode() && globals->atlEnabled && !CutsceneRules_CheckStageReload()) {
183
Zone_ReloadStoredEntities(TO_FIXED(288), TO_FIXED(560), true);
184
}
185
}
186
else if (isMainGameMode() && globals->atlEnabled) {
187
if (!CutsceneRules_CheckStageReload()) {
188
MSZSetup_HandleRestart();
189
}
190
else {
191
globals->parallaxOffset[0] = 0;
192
globals->parallaxOffset[1] = 0;
193
}
194
}
195
else {
196
globals->parallaxOffset[0] = 0;
197
globals->parallaxOffset[1] = 0;
198
}
199
200
if (isMainGameMode() && CutsceneRules_IsAct2()) {
201
foreach_all(MSZ2Cutscene, cutscene)
202
{
203
MSZSetup->msz2Cutscene = cutscene;
204
foreach_break;
205
}
206
207
Zone->stageFinishCallback = MSZSetup_StageFinish_EndAct2;
208
}
209
210
GenericTrigger->callbacks[MSZ_GENERICTRIGGER_ACHIEVEMENT] = MSZSetup_Trigger_AwardAchievement;
211
}
212
else {
213
#if MANIA_USE_PLUS
214
if ((SceneInfo->filter & FILTER_ENCORE)) {
215
RSDK.ResetEntitySlot(32, MSZSetup->classID, MSZSetup_State_ManageFade_E);
216
217
if (isMainGameMode()) {
218
if (CutsceneRules_IsAct1())
219
Zone->stageFinishCallback = MSZSetup_StageFinish_EndAct1E;
220
}
221
}
222
else {
223
if (RSDK.GetEntityCount(Tornado->classID, false) <= 0) {
224
RSDK.ResetEntitySlot(32, MSZSetup->classID, MSZSetup_State_ManageFade_K);
225
226
if (!CutsceneRules_IsIntroEnabled())
227
FXFade_StopAll();
228
229
if (CutsceneRules_IsAct1Regular()) {
230
Zone->shouldRecoverPlayers = true;
231
Zone->stageFinishCallback = MSZSetup_StageFinish_EndAct1K;
232
}
233
}
234
else {
235
MSZSetup_StoreBGParallax();
236
MSZSetup_ReloadBGParallax_Multiply(0x400);
237
RSDK.ResetEntitySlot(32, MSZSetup->classID, MSZSetup_State_ManageFade_ST);
238
239
if (CutsceneRules_IsAct1Regular())
240
Zone->stageFinishCallback = MSZSetup_StageFinish_EndAct1ST;
241
GiantPistol->inCutscene = true;
242
}
243
}
244
#else
245
if (CHECK_CHARACTER_ID(ID_KNUCKLES, 1)) {
246
RSDK.ResetEntitySlot(17, MSZSetup->classID, MSZSetup_State_ManageFade_K);
247
if (!CutsceneRules_IsIntroEnabled())
248
FXFade_StopAll();
249
250
if (CutsceneRules_IsAct1Regular()) {
251
Zone->shouldRecoverPlayers = true;
252
Zone->stageFinishCallback = MSZSetup_StageFinish_EndAct1K;
253
}
254
}
255
else {
256
MSZSetup_StoreBGParallax();
257
MSZSetup_ReloadBGParallax_Multiply(0x400);
258
RSDK.ResetEntitySlot(17, MSZSetup->classID, MSZSetup_State_ManageFade_ST);
259
260
if (CutsceneRules_IsAct1Regular())
261
Zone->stageFinishCallback = MSZSetup_StageFinish_EndAct1ST;
262
}
263
#endif
264
}
265
}
266
267
#if MANIA_USE_PLUS
268
MSZSetup->sfxLocoChugga = RSDK.GetSfx("MSZ/LocoChugga.wav");
269
#endif
270
271
Animals->animalTypes[0] = ANIMAL_LOCKY;
272
Animals->animalTypes[1] = ANIMAL_POCKY;
273
}
274
275
void MSZSetup_SetBGScrollOrigin(int32 x, int32 y)
276
{
277
int32 posX = x >> 8;
278
279
TileLayer *background1 = RSDK.GetTileLayer(0);
280
background1->scrollPos += (y >> 8) * background1->parallaxFactor;
281
for (int32 i = 0; i < background1->scrollInfoCount; ++i) {
282
background1->scrollInfo[i].scrollPos = posX * background1->scrollInfo[i].parallaxFactor;
283
}
284
285
TileLayer *background2 = RSDK.GetTileLayer(1);
286
background2->scrollPos += (y >> 8) * background2->parallaxFactor;
287
for (int32 i = 0; i < background2->scrollInfoCount; ++i) {
288
background2->scrollInfo[i].scrollPos = posX * background2->scrollInfo[i].parallaxFactor;
289
}
290
291
foreach_all(ParallaxSprite, sprite)
292
{
293
if (sprite->aniID < MSZ_PARALLAXSPRITE_OOZPEEK)
294
sprite->scrollPos.x += posX * (sprite->parallaxFactor.x >> 16);
295
}
296
}
297
298
void MSZSetup_StoreBGParallax(void)
299
{
300
int32 id = 0;
301
302
TileLayer *background1 = RSDK.GetTileLayer(0);
303
for (int32 i = 0; i < background1->scrollInfoCount; ++i) {
304
MSZSetup->storedParallax[id++] = background1->scrollInfo[i].parallaxFactor;
305
#if MANIA_USE_PLUS
306
if (SceneInfo->filter == (FILTER_BOTH | FILTER_MANIA))
307
#endif
308
background1->scrollInfo[i].parallaxFactor = 0;
309
}
310
311
TileLayer *background2 = RSDK.GetTileLayer(1);
312
for (int32 i = 0; i < background2->scrollInfoCount; ++i) {
313
MSZSetup->storedParallax[id++] = background2->scrollInfo[i].parallaxFactor;
314
#if MANIA_USE_PLUS
315
if (SceneInfo->filter == (FILTER_BOTH | FILTER_MANIA))
316
#endif
317
background2->scrollInfo[i].parallaxFactor = 0;
318
}
319
320
foreach_all(ParallaxSprite, parallaxSprite)
321
{
322
MSZSetup->storedParallax[id++] = (parallaxSprite->parallaxFactor.x >> 8);
323
#if MANIA_USE_PLUS
324
if (SceneInfo->filter == (FILTER_BOTH | FILTER_MANIA))
325
#endif
326
parallaxSprite->parallaxFactor.x = 0;
327
}
328
}
329
330
void MSZSetup_ReloadBGParallax(void)
331
{
332
int32 id = 0;
333
TileLayer *background1 = RSDK.GetTileLayer(0);
334
for (int32 i = 0; i < background1->scrollInfoCount; ++i) background1->scrollInfo[i].scrollSpeed = MSZSetup->storedParallax[id++];
335
336
TileLayer *background2 = RSDK.GetTileLayer(1);
337
for (int32 i = 0; i < background2->scrollInfoCount; ++i) background2->scrollInfo[i].scrollSpeed = MSZSetup->storedParallax[id++];
338
339
foreach_all(ParallaxSprite, parallaxSprite) { parallaxSprite->scrollSpeed.x = MSZSetup->storedParallax[id++] << 8; }
340
}
341
342
void MSZSetup_ReloadBGParallax_Multiply(int32 parallaxMultiplier)
343
{
344
int32 id = 0;
345
TileLayer *background1 = RSDK.GetTileLayer(0);
346
for (int32 i = 0; i < background1->scrollInfoCount; ++i)
347
background1->scrollInfo[i].scrollSpeed = parallaxMultiplier * MSZSetup->storedParallax[id++];
348
349
TileLayer *background2 = RSDK.GetTileLayer(1);
350
for (int32 i = 0; i < background2->scrollInfoCount; ++i)
351
background2->scrollInfo[i].scrollSpeed = parallaxMultiplier * MSZSetup->storedParallax[id++];
352
353
foreach_all(ParallaxSprite, parallaxSprite)
354
{
355
parallaxSprite->scrollSpeed.x = parallaxMultiplier * MSZSetup->storedParallax[id++];
356
#if MANIA_USE_PLUS
357
if (!(SceneInfo->filter & FILTER_ENCORE))
358
#endif
359
parallaxSprite->scrollSpeed.x >>= 8;
360
}
361
362
MSZSetup->parallaxMult = parallaxMultiplier << 8;
363
}
364
365
void MSZSetup_State_ManageFade_ST(void)
366
{
367
RSDK_THIS(MSZSetup);
368
369
#if GAME_VERSION == VER_100
370
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
371
if (player1->position.x > TO_FIXED(6528)) {
372
#else
373
if (ScreenInfo->position.x + ScreenInfo->center.x > 6528) {
374
#endif
375
self->state = MSZSetup_State_SwitchPalettes;
376
}
377
}
378
379
void MSZSetup_State_ManageFade_K(void)
380
{
381
RSDK_THIS(MSZSetup);
382
383
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
384
if (player1->position.x < TO_FIXED(8448) && player1->position.y < TO_FIXED(1600))
385
self->state = MSZSetup_State_SwitchPalettes;
386
}
387
388
#if MANIA_USE_PLUS
389
void MSZSetup_State_ManageFade_E(void)
390
{
391
RSDK_THIS(MSZSetup);
392
393
foreach_all(Decoration, decoration)
394
{
395
if (decoration->animator.animationID == 2 || decoration->animator.animationID == 3)
396
decoration->animator.speed = 0;
397
}
398
399
self->state = MSZSetup_State_CheckFadeTrigger_E;
400
}
401
#endif
402
403
void MSZSetup_StageFinish_EndAct1ST(void) { MSZCutsceneST->finishedAct = true; }
404
405
void MSZSetup_StageFinish_EndAct1K(void)
406
{
407
Zone_StoreEntities((Zone->cameraBoundsL[0] + ScreenInfo->center.x) << 16, Zone->cameraBoundsB[0] << 16);
408
RSDK.LoadScene();
409
}
410
411
#if MANIA_USE_PLUS
412
void MSZSetup_StageFinish_EndAct1E(void) {}
413
#endif
414
415
void MSZSetup_StageFinish_EndAct2(void) { MSZSetup->msz2Cutscene->active = ACTIVE_NORMAL; }
416
417
void MSZSetup_Trigger_AwardAchievement(void)
418
{
419
if (!MSZSetup->hasAchievement) {
420
API_UnlockAchievement(&achievementList[ACH_MSZ]);
421
MSZSetup->hasAchievement = true;
422
}
423
}
424
425
void MSZSetup_State_SwitchPalettes(void)
426
{
427
RSDK_THIS(MSZSetup);
428
429
self->timer += 4;
430
RSDK.SetLimitedFade(0, 3, 4, self->timer, 128, 255);
431
432
if (self->timer >= 256) {
433
#if MANIA_USE_PLUS
434
if (!(SceneInfo->filter & FILTER_ENCORE)) {
435
#endif
436
for (int32 i = 0; i < 0x400; ++i) MSZSetup->background1->deformationData[i] = MSZSetup->deformData[i & 0x1F];
437
#if MANIA_USE_PLUS
438
}
439
#endif
440
MSZSetup->usingRegularPalette = true;
441
442
RSDK.CopyPalette(4, 128, 0, 128, 128);
443
#if MANIA_USE_PLUS
444
RSDK.CopyPalette(4, 128, 1, 128, 128);
445
RSDK.CopyPalette(4, 128, 2, 128, 128);
446
RSDK.RotatePalette(2, 204, 207, false);
447
448
if ((SceneInfo->filter & FILTER_ENCORE))
449
self->state = MSZSetup_State_CheckTrainStart;
450
else
451
#endif
452
destroyEntity(self);
453
}
454
}
455
456
void MSZSetup_HandleRestart(void)
457
{
458
Zone_ReloadStoredEntities(WIDE_SCR_XCENTER << 16, 1440 << 16, true);
459
460
int32 id = 0;
461
TileLayer *background1 = RSDK.GetTileLayer(0);
462
for (int32 i = 0; i < background1->scrollInfoCount; ++i) background1->scrollInfo[i].scrollPos = globals->parallaxOffset[id++];
463
464
TileLayer *background2 = RSDK.GetTileLayer(1);
465
for (int32 i = 0; i < background2->scrollInfoCount; ++i) background2->scrollInfo[i].scrollPos = globals->parallaxOffset[id++];
466
467
foreach_all(ParallaxSprite, parallaxSprite) { parallaxSprite->scrollPos.x = globals->parallaxOffset[id++]; }
468
}
469
470
#if MANIA_USE_PLUS
471
void MSZSetup_State_CheckFadeTrigger_E(void)
472
{
473
RSDK_THIS(MSZSetup);
474
475
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
476
if (player1->position.x > 0x29800000) {
477
if (player1->position.y > 0x4200000 && player1->position.y < 0x6800000)
478
self->state = MSZSetup_State_SwitchPalettes;
479
}
480
}
481
482
void MSZSetup_State_CheckTrainStart(void)
483
{
484
RSDK_THIS(MSZSetup);
485
486
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
487
if (player1->position.x > 0x2B600000) {
488
foreach_all(Decoration, decoration)
489
{
490
if (decoration->animator.animationID == 2 || decoration->animator.animationID == 3)
491
decoration->animator.speed = 1;
492
}
493
494
Zone->cameraBoundsL[0] = 10624;
495
Zone->playerBoundsL[0] = 10624 << 16;
496
497
MSZSetup->chuggaChannel = RSDK.PlaySfx(MSZSetup->sfxLocoChugga, 1, 255);
498
RSDK.SetChannelAttributes(MSZSetup->chuggaChannel, 0.0, 0.0, 1.0);
499
500
MSZSetup_StoreBGParallax();
501
MSZSetup_ReloadBGParallax_Multiply(0x000);
502
Camera_ShakeScreen(0, 4, 4);
503
504
RSDK.CopyTileLayer(4, 640, 94, 5, 0, 0, 62, 16);
505
RSDK.CopyTileLayer(4, 655, 0, 5, 0, 0, 17, 70);
506
RSDK.CopyTileLayer(3, 655, 0, 5, 0, 0, 17, 70);
507
RSDK.CopyTileLayer(2, 655, 0, 5, 0, 0, 17, 70);
508
509
self->state = MSZSetup_State_TrainStarting;
510
}
511
}
512
513
void MSZSetup_State_TrainStarting(void)
514
{
515
RSDK_THIS(MSZSetup);
516
517
RSDK.SetChannelAttributes(MSZSetup->chuggaChannel, ++MSZSetup->chuggaVolume * (1 / 256.0f), 0.0, 1.0);
518
MSZSetup_ReloadBGParallax_Multiply(8 * MSZSetup->chuggaVolume);
519
520
if (MSZSetup->chuggaVolume >= 256)
521
self->state = MSZSetup_State_TrainSequence_MSZ1E;
522
523
RSDK.GetTileLayer(3)->scrollInfo[1].scrollSpeed = 0x600 * MSZSetup->chuggaVolume;
524
}
525
526
void MSZSetup_State_TrainSequence_MSZ1E(void)
527
{
528
RSDK_THIS(MSZSetup);
529
530
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
531
TileLayer *fgSupaLow = RSDK.GetTileLayer(3);
532
fgSupaLow->scrollInfo[1].scrollPos &= 0x00FFFFFF;
533
fgSupaLow->scrollInfo[1].scrollSpeed = 0x600 * MSZSetup->chuggaVolume;
534
535
if (player1->position.x > 0x360C0000) {
536
GiantPistol->inCutscene = true;
537
self->state = MSZSetup_State_Boss_MSZ1E;
538
}
539
}
540
541
void MSZSetup_State_Boss_MSZ1E(void)
542
{
543
RSDK_THIS(MSZSetup);
544
545
TileLayer *fgSupaLow = RSDK.GetTileLayer(3);
546
fgSupaLow->scrollInfo[1].scrollPos &= 0x00FFFFFF;
547
fgSupaLow->scrollInfo[1].scrollSpeed = 0x600 * MSZSetup->chuggaVolume;
548
549
if (!MSZSetup->parallaxMult) {
550
MSZSetup->chuggaVolume -= 4;
551
RSDK.SetChannelAttributes(MSZSetup->chuggaChannel, MSZSetup->chuggaVolume * (1 / 256.0f), 0.0, 1.0);
552
553
if (MSZSetup->chuggaVolume <= 0) {
554
fgSupaLow->scrollInfo[1].scrollSpeed = 0;
555
fgSupaLow->scrollInfo[1].scrollPos = 0;
556
MSZSetup->chuggaVolume = 0;
557
self->state = MSZSetup_State_AwaitActClearStart;
558
}
559
}
560
}
561
562
void MSZSetup_State_AwaitActClearStart(void)
563
{
564
RSDK_THIS(MSZSetup);
565
566
if (RSDK_GET_ENTITY(SLOT_ACTCLEAR, ActClear)->classID == ActClear->classID)
567
self->state = MSZSetup_State_AwaitActClearFinish;
568
}
569
570
void MSZSetup_State_AwaitActClearFinish(void)
571
{
572
RSDK_THIS(MSZSetup);
573
574
if (RSDK_GET_ENTITY(SLOT_ACTCLEAR, ActClear)->classID != ActClear->classID) {
575
self->timer = 0;
576
Zone->cameraBoundsR[0] = 17064;
577
Zone->playerBoundActiveR[0] = false;
578
579
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
580
player1->stateInput = StateMachine_None;
581
582
foreach_active(Player, player)
583
{
584
RSDK.SetSpriteAnimation(player->aniFrames, ANI_IDLE, &player->animator, true, 0);
585
player->up = false;
586
player->down = false;
587
player->left = false;
588
player->right = false;
589
player->jumpPress = false;
590
player->jumpHold = false;
591
player->state = Player_State_Ground;
592
}
593
594
self->state = MSZSetup_State_MoveToMSZ2Start;
595
}
596
}
597
598
void MSZSetup_State_MoveToMSZ2Start(void)
599
{
600
RSDK_THIS(MSZSetup);
601
602
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
603
player1->right = true;
604
605
if (player1->position.x < (Zone->cameraBoundsR[0] - ScreenInfo->center.x) << 16) {
606
foreach_active(Player, player)
607
{
608
if (player->groundVel > 0x30000)
609
player->groundVel = 0x30000;
610
}
611
}
612
else {
613
player1->right = false;
614
player1->left = true;
615
self->state = MSZSetup_State_AwaitPlayerStopped;
616
}
617
}
618
619
void MSZSetup_State_AwaitPlayerStopped(void)
620
{
621
RSDK_THIS(MSZSetup);
622
623
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
624
if (player1->groundVel <= 0) {
625
player1->groundVel = 0;
626
player1->left = false;
627
player1->direction = FLIP_NONE;
628
self->timer = 0;
629
self->state = MSZSetup_State_StoreMSZ1ScrollPos_E;
630
}
631
}
632
633
void MSZSetup_State_StoreMSZ1ScrollPos_E(void)
634
{
635
RSDK_THIS(MSZSetup);
636
637
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
638
player1->direction = FLIP_NONE;
639
640
if (++self->timer >= 90) {
641
int32 id = 0;
642
643
TileLayer *background1 = RSDK.GetTileLayer(0);
644
for (int32 i = 0; i < background1->scrollInfoCount; ++i) {
645
globals->parallaxOffset[id++] = background1->scrollInfo[i].tilePos;
646
}
647
648
TileLayer *background2 = RSDK.GetTileLayer(1);
649
for (int32 i = 0; i < background2->scrollInfoCount; ++i) {
650
globals->parallaxOffset[id++] = background2->scrollInfo[i].tilePos;
651
}
652
653
foreach_all(ParallaxSprite, sprite)
654
{
655
globals->parallaxOffset[id++] =
656
((sprite->scrollPos.x + sprite->parallaxFactor.x * ScreenInfo->position.x) & 0x7FFF0000) % sprite->loopPoint.x;
657
}
658
659
Zone_StoreEntities((ScreenInfo->center.x + 16640) << 16, 1440 << 16);
660
globals->atlEnabled = true;
661
RSDK.LoadScene();
662
663
destroyEntity(self);
664
}
665
}
666
#endif
667
668
void MSZSetup_State_StoreMSZ1ScrollPos_ST(void)
669
{
670
int32 id = 0;
671
672
TileLayer *background1 = RSDK.GetTileLayer(0);
673
for (int32 i = 0; i < background1->scrollInfoCount; ++i) {
674
globals->parallaxOffset[id++] = background1->scrollInfo[i].scrollPos;
675
}
676
677
TileLayer *background2 = RSDK.GetTileLayer(1);
678
for (int32 i = 0; i < background2->scrollInfoCount; ++i) {
679
globals->parallaxOffset[id++] = background2->scrollInfo[i].scrollPos;
680
}
681
682
foreach_all(ParallaxSprite, sprite) { globals->parallaxOffset[id++] = sprite->scrollPos.x; }
683
684
Zone_StoreEntities((Zone->cameraBoundsL[0] + ScreenInfo->center.x) << 16, 1440 << 16);
685
++SceneInfo->listPos;
686
globals->atlEnabled = true;
687
RSDK.LoadScene();
688
}
689
690
void MSZSetup_PlayerState_Pilot(void)
691
{
692
RSDK_THIS(Player);
693
694
self->position.x = 0;
695
self->position.y = 0;
696
self->active = ACTIVE_NEVER;
697
self->visible = false;
698
self->stateInput = StateMachine_None;
699
self->position.x = ScreenInfo->position.x << 16;
700
self->position.y = ScreenInfo->position.y << 16;
701
Player->respawnTimer = 0;
702
}
703
704
void MSZSetup_PlayerState_PostCrashJumpIn(void)
705
{
706
RSDK_THIS(Player);
707
708
self->active = ACTIVE_NORMAL;
709
self->visible = true;
710
self->stateInput = Player_Input_P2_AI;
711
Player->respawnTimer = 240;
712
713
Player_HandleSidekickRespawn();
714
}
715
716
#if GAME_INCLUDE_EDITOR
717
void MSZSetup_EditorDraw(void) {}
718
719
void MSZSetup_EditorLoad(void)
720
{
721
RSDK_ACTIVE_VAR(GenericTrigger, triggerID);
722
RSDK_ENUM_VAR("Award Achievement", MSZ_GENERICTRIGGER_ACHIEVEMENT);
723
724
RSDK_ACTIVE_VAR(Decoration, type);
725
RSDK_ENUM_VAR("Main", MSZ_DECORATION_MAIN);
726
RSDK_ENUM_VAR("Tanker Rail", MSZ_DECORATION_TANKERRAIL);
727
RSDK_ENUM_VAR("Tanker Wheel", MSZ_DECORATION_TANKERWHEEL);
728
RSDK_ENUM_VAR("Carriage Wheel", MSZ_DECORATION_CARRIAGEWHEEL);
729
RSDK_ENUM_VAR("Connector 1", MSZ_DECORATION_CONNECTOR1);
730
RSDK_ENUM_VAR("Connector 2", MSZ_DECORATION_CONNECTOR2);
731
732
RSDK_ACTIVE_VAR(ParallaxSprite, aniID);
733
RSDK_ENUM_VAR("Cactus 1", MSZ_PARALLAXSPRITE_CACTUS1);
734
RSDK_ENUM_VAR("Cactus 2", MSZ_PARALLAXSPRITE_CACTUS2);
735
RSDK_ENUM_VAR("Cactus 3", MSZ_PARALLAXSPRITE_CACTUS3);
736
RSDK_ENUM_VAR("Cactus 4", MSZ_PARALLAXSPRITE_CACTUS4);
737
RSDK_ENUM_VAR("Cactus 5", MSZ_PARALLAXSPRITE_CACTUS5);
738
RSDK_ENUM_VAR("Cactus 6", MSZ_PARALLAXSPRITE_CACTUS6);
739
RSDK_ENUM_VAR("Cactus 7", MSZ_PARALLAXSPRITE_CACTUS7);
740
RSDK_ENUM_VAR("OOZ Peek", MSZ_PARALLAXSPRITE_OOZPEEK);
741
}
742
#endif
743
744
void MSZSetup_Serialize(void) {}
745
746