Path: blob/master/SonicMania/Objects/PGZ/PSZ1Setup.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PSZ1Setup Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPSZ1Setup *PSZ1Setup;1011void PSZ1Setup_Update(void) {}1213void PSZ1Setup_LateUpdate(void) {}1415void PSZ1Setup_StaticUpdate(void)16{17PSZ1Setup->newspaperHAniFrame -= 8;18PSZ1Setup->newspaperHAniFrame &= 0x3F;1920PSZ1Setup->newspaperVAniFrame += 4;21if (PSZ1Setup->newspaperVAniFrame == 80)22PSZ1Setup->newspaperVAniFrame = 0;2324RSDK.DrawAniTiles(PSZ1Setup->aniTiles2, 985, 0, PSZ1Setup->newspaperVAniFrame, 48, 80);25RSDK.DrawAniTiles(PSZ1Setup->aniTiles3, 716, PSZ1Setup->newspaperHAniFrame, 0, 64, 48);2627if (!(Zone->timer & 1))28RSDK.RotatePalette(0, 236, 239, false);2930if (++PSZ1Setup->inkRollerAniDuration == 3) {31PSZ1Setup->inkRollerAniDuration = 0;3233++PSZ1Setup->inkRollerAniFrame;34PSZ1Setup->inkRollerAniFrame &= 0xF;3536RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 552, 16 * PSZ1Setup->inkRollerAniFrame, 0, 16, 128);37}3839if (--PSZ1Setup->buttonFrontAniDuration < 1) {40++PSZ1Setup->buttonFrontAniFrame;4142PSZ1Setup->buttonFrontAniFrame %= 7;43PSZ1Setup->buttonFrontAniDuration = PSZ1Setup->buttonSideAniDurationTable[PSZ1Setup->buttonFrontAniFrame];4445RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 216, 16 * PSZ1Setup->buttonFrontAniFrame, 128, 16, 16);46}4748if (--PSZ1Setup->buttonBackAniDuration < 1) {49++PSZ1Setup->buttonBackAniFrame;5051PSZ1Setup->buttonBackAniFrame %= 7;52PSZ1Setup->buttonBackAniDuration = PSZ1Setup->buttonSideAniDurationTable[PSZ1Setup->buttonBackAniFrame];5354RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 217, 16 * (PSZ1Setup->buttonBackAniFrame + 7), 128, 16, 16);55}5657if (--PSZ1Setup->buttonSideFrontAniDuration < 1) {58++PSZ1Setup->buttonSideFrontAniFrame;5960PSZ1Setup->buttonSideFrontAniFrame %= 14;61PSZ1Setup->buttonSideFrontAniDuration = PSZ1Setup->buttonSideBackAniDurationTable[PSZ1Setup->buttonSideFrontAniFrame];6263RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 218, 16 * PSZ1Setup->buttonSideFrontAniFrame, 144, 16, 32);64}6566if (--PSZ1Setup->buttonSideBackAniDuration < 1) {67++PSZ1Setup->buttonSideBackAniFrame;6869PSZ1Setup->buttonSideBackAniFrame %= 14;70PSZ1Setup->buttonSideBackAniDuration = PSZ1Setup->buttonSideBackAniDurationTable[PSZ1Setup->buttonSideBackAniFrame];7172RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 220, 16 * PSZ1Setup->buttonSideBackAniFrame, 176, 16, 48);73}7475if (--PSZ1Setup->buttonSideAniDuration < 1) {76++PSZ1Setup->buttonSideAniFrame;7778PSZ1Setup->buttonSideAniFrame %= 7;79PSZ1Setup->buttonSideAniDuration = PSZ1Setup->buttonSideAniDurationTable[PSZ1Setup->buttonSideAniFrame];8081RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 223, 16 * PSZ1Setup->buttonSideAniFrame, 224, 16, 32);82}8384if (!(Zone->timer & 1)) {85++PSZ1Setup->buttonBladeAniFrame;8687PSZ1Setup->buttonBladeAniFrame %= 3;88switch (PSZ1Setup->buttonBladeAniFrame) {89case 0: RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 227, 112, 224, 48, 32); break;9091case 1:92case 3: RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 227, 160, 224, 48, 32); break;9394case 2: RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 227, 208, 224, 48, 32); break;9596default: break;97}98}99100if (Zone->cameraBoundsB[0] == 2944) {101EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);102103if (player->position.y < 0xAA00000) {104if (player->position.y <= 0x900000) {105EntityCamera *camera = player->camera;106107camera->position.y += 0xA000000;108camera->center.y += 0xA00;109ScreenInfo[camera->screenID].position.y += 0xA00;110player->position.y += 0xA000000;111112TileLayer *background1 = RSDK.GetTileLayer(0);113TileLayer *background2 = RSDK.GetTileLayer(1);114background1->scrollPos -= 0xA00000;115background2->scrollPos -= 0x2800000;116117if (background1->scrollPos < 0)118background1->scrollPos += 0x4000000;119120if (background2->scrollPos < 0)121background2->scrollPos += 0x6000000;122123if (ScreenInfo->position.y >= 0x180)124ScreenInfo->position.y += 0xA00;125}126}127else {128EntityCamera *camera = player->camera;129130camera->position.y -= 0xA000000;131camera->center.y -= 0xA00;132ScreenInfo[camera->screenID].position.y -= 0xA00;133player->position.y -= 0xA000000;134135TileLayer *background1 = RSDK.GetTileLayer(0);136TileLayer *background2 = RSDK.GetTileLayer(1);137background1->scrollPos += 0xA00000;138background2->scrollPos += 0x2800000;139140if (background1->scrollPos >= 0x6E000000)141background1->scrollPos -= 0x4000000;142143if (background2->scrollPos >= 0x6E000000)144background2->scrollPos -= 0x6000000;145146if (ScreenInfo->position.y >= 0xA00)147ScreenInfo->position.y -= 0xA00;148}149150if (player->camera->position.y < 0x6100000) {151if (player->camera->position.y <= 0x2800000) {152if (PSZ1Setup->levelWrapType == PSZ1_WRAP_BOTTOM) {153PSZ1Setup->levelWrapType = PSZ1_WRAP_TOP;154PSZ1Setup_LevelWrap_Top();155}156}157}158else {159if (PSZ1Setup->levelWrapType == PSZ1_WRAP_TOP) {160PSZ1Setup->levelWrapType = PSZ1_WRAP_BOTTOM;161PSZ1Setup_LevelWrap_Bottom();162}163}164}165166if (PSZ1Setup->petalBehaviourActive) {167if (PSZ1Setup->petalTimer <= 0) {168foreach_active(Player, player)169{170Hitbox *playerHitbox = Player_GetHitbox(player);171172uint16 tile = RSDK.GetTile(Zone->fgLayer[0], player->position.x >> 20, (player->position.y + (playerHitbox->bottom << 16)) >> 20);173bool32 isLowLayer = true;174if (tile == (uint16)-1) {175tile = RSDK.GetTile(Zone->fgLayer[1], player->position.x >> 20, (player->position.y + (playerHitbox->bottom << 16)) >> 20);176isLowLayer = false;177}178179if (RSDK.GetTileFlags(tile, player->collisionPlane)) {180if (abs(player->groundVel) >= 0x60000 || player->state == Player_State_DropDash) {181RSDK_THIS(PSZ1Setup); // not sure what this is meant to be since this is a StaticUpdate event...182183EntityPetalPile *pile = CREATE_ENTITY(PetalPile, self, player->position.x, player->position.y + (playerHitbox->bottom << 16));184pile->leafPattern = PETALPILE_PATTERN_4;185pile->tileLayer = isLowLayer;186pile->pileSize.x = 0x40000;187pile->pileSize.y = 0x40000;188pile->noRemoveTiles = true;189pile->petalRadius = 0xB5555;190pile->petalDir = 2 * (player->direction != FLIP_NONE) - 1;191pile->petalVel = player->groundVel >> 1;192PSZ1Setup->petalTimer = 3;193}194}195}196}197else {198PSZ1Setup->petalTimer--;199}200}201}202203void PSZ1Setup_Draw(void) {}204205void PSZ1Setup_Create(void *data) {}206207void PSZ1Setup_StageLoad(void)208{209PSZ1Setup->aniTiles1 = RSDK.LoadSpriteSheet("PSZ1/AniTiles.gif", SCOPE_STAGE);210PSZ1Setup->aniTiles2 = RSDK.LoadSpriteSheet("PSZ1/AniTiles2.gif", SCOPE_STAGE);211PSZ1Setup->aniTiles3 = RSDK.LoadSpriteSheet("PSZ1/AniTiles3.gif", SCOPE_STAGE);212213PSZ1Setup->petalBehaviourActive = false;214PSZ1Setup->levelWrapType = PSZ1_WRAP_TOP;215216GenericTrigger->callbacks[GENERICTRIGGER_PSZ1_PETALSINACTIVE] = PSZ1Setup_Trigger_DeactivatePetalBehaviour;217GenericTrigger->callbacks[GENERICTRIGGER_PSZ1_PETALSACTIVE] = PSZ1Setup_Trigger_ActivatePetalBehaviour;218GenericTrigger->callbacks[GENERICTRIGGER_PSZ1_ACHIEVEMENT] = PSZ1Setup_Trigger_AwardAchievement;219220PSZ1Setup->buttonFrontAniDuration = 12;221PSZ1Setup->buttonFrontAniFrame = 0;222RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 216, 0, 128, 16, 16);223224PSZ1Setup->buttonBackAniDuration = 24;225PSZ1Setup->buttonBackAniFrame = 0;226RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 217, 112, 128, 16, 16);227228PSZ1Setup->buttonSideFrontAniDuration = 36;229PSZ1Setup->buttonSideFrontAniFrame = 0;230RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 218, 0, 144, 16, 32);231232PSZ1Setup->buttonSideBackAniDuration = 48;233PSZ1Setup->buttonSideBackAniFrame = 0;234RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 220, 0, 176, 16, 48);235236PSZ1Setup->buttonSideAniDuration = 64;237PSZ1Setup->buttonSideAniFrame = 0;238RSDK.DrawAniTiles(PSZ1Setup->aniTiles1, 223, 0, 224, 16, 32);239240if (isMainGameMode() && CutsceneRules_IsAct1())241Zone->stageFinishCallback = PSZ1Setup_StageFinish_EndAct1;242243#if MANIA_USE_PLUS244if (SceneInfo->filter & FILTER_ENCORE)245RSDK.LoadPalette(0, "EncorePSZ1.act", 0b0000000011111111);246247// Fun Fact: Pre-Plus didn't have animal types set for PGZ! It'd always be flickies due to that being the default value!248Animals->animalTypes[0] = ANIMAL_POCKY;249Animals->animalTypes[1] = ANIMAL_BECKY;250251BGSwitch->switchCallback[PSZ1_BG_INSIDE] = PSZ1Setup_BGSwitch_Inside;252BGSwitch->switchCallback[PSZ1_BG_OUTSIDE] = PSZ1Setup_BGSwitch_Outside;253254BGSwitch->layerIDs[0] = PSZ1_BG_INSIDE;255BGSwitch->layerIDs[1] = PSZ1_BG_INSIDE;256BGSwitch->layerIDs[2] = PSZ1_BG_INSIDE;257BGSwitch->layerIDs[3] = PSZ1_BG_INSIDE;258#endif259}260261#if MANIA_USE_PLUS262void PSZ1Setup_BGSwitch_Inside(void)263{264RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0; // Background 1265RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0; // Background 2266RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = 0; // Background 3267}268269void PSZ1Setup_BGSwitch_Outside(void)270{271RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0; // Background 1272RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT; // Background 2273RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT; // Background 3274}275#endif276277void PSZ1Setup_Trigger_DeactivatePetalBehaviour(void) { PSZ1Setup->petalBehaviourActive = true; }278279void PSZ1Setup_Trigger_ActivatePetalBehaviour(void) { PSZ1Setup->petalBehaviourActive = false; }280281void PSZ1Setup_Trigger_AwardAchievement(void)282{283RSDK_THIS(GenericTrigger);284285if (!PSZ1Setup->hasAchievement) {286int32 count = 0;287foreach_all(Crate, crate)288{289if (MathHelpers_PointInHitbox(self->position.x, self->position.y, crate->position.x, crate->position.y, self->direction, &self->hitbox)) {290if (crate->frameID == 1)291++count;292}293}294295if (!count) {296API_UnlockAchievement(&achievementList[ACH_PGZ]);297PSZ1Setup->hasAchievement = true;298}299}300}301302void PSZ1Setup_StageFinish_EndAct1(void)303{304++SceneInfo->listPos;305globals->enableIntro = true;306globals->suppressTitlecard = true;307globals->suppressAutoMusic = true;308309for (int32 p = 0; p < Player->playerCount; ++p) StarPost->postIDs[p] = 0;310311SaveGame_SavePlayerState();312Zone_StoreEntities(15876 << 16, 1316 << 16);313314RSDK.LoadScene();315}316317void PSZ1Setup_LevelWrap_Top(void)318{319for (int32 i = 1; i < ENTITY_COUNT; ++i) {320EntityPlatform *entity = RSDK_GET_ENTITY(i, Platform);321if (entity->classID != BoundsMarker->classID) {322if (entity->position.y >= 0x6800000) {323entity->position.y -= 0xA000000;324325if (entity->classID == PrintBlock->classID || entity->classID == Platform->classID || entity->classID == Crate->classID) {326EntityPlatform *platform = entity;327platform->drawPos.y -= 0xA000000;328platform->centerPos.y -= 0xA000000;329}330}331}332}333}334335void PSZ1Setup_LevelWrap_Bottom(void)336{337for (int32 i = 1; i < ENTITY_COUNT; ++i) {338EntityPlatform *entity = RSDK_GET_ENTITY(i, Platform);339if (entity->classID != BoundsMarker->classID) {340if (entity->position.y <= 0x1800000) {341entity->position.y += 0xA000000;342343if (entity->classID == PrintBlock->classID || entity->classID == Platform->classID || entity->classID == Crate->classID) {344EntityPlatform *platform = entity;345platform->drawPos.y += 0xA000000;346platform->centerPos.y += 0xA000000;347}348}349}350}351}352353#if GAME_INCLUDE_EDITOR354void PSZ1Setup_EditorDraw(void) {}355356void PSZ1Setup_EditorLoad(void)357{358RSDK_ACTIVE_VAR(BGSwitch, bgID);359RSDK_ENUM_VAR("Inside BG", PSZ1_BG_INSIDE);360RSDK_ENUM_VAR("Outside BG", PSZ1_BG_OUTSIDE);361362RSDK_ACTIVE_VAR(GenericTrigger, triggerID);363RSDK_ENUM_VAR("Stop Petal Behaviour", GENERICTRIGGER_PSZ1_PETALSINACTIVE);364RSDK_ENUM_VAR("Start Petal Behaviour", GENERICTRIGGER_PSZ1_PETALSACTIVE);365RSDK_ENUM_VAR("PSZ1 Achievement Area", GENERICTRIGGER_PSZ1_ACHIEVEMENT);366}367#endif368369void PSZ1Setup_Serialize(void) {}370371372