Path: blob/master/SonicMania/Objects/LRZ/LRZ1Intro.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: LRZ1Intro Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectLRZ1Intro *LRZ1Intro;1112void LRZ1Intro_Update(void)13{14RSDK_THIS(LRZ1Intro);1516StateMachine_Run(self->state);17}1819void LRZ1Intro_LateUpdate(void) {}2021void LRZ1Intro_StaticUpdate(void) {}2223void LRZ1Intro_Draw(void)24{25RSDK_THIS(LRZ1Intro);2627RSDK.SetActivePalette(6, 0, ScreenInfo->size.y);2829RSDK.DrawSprite(&self->animator, NULL, false);3031RSDK.SetActivePalette(0, 0, ScreenInfo->size.y);32}3334void LRZ1Intro_Create(void *data)35{36RSDK_THIS(LRZ1Intro);3738if (!SceneInfo->inEditor) {39self->active = ACTIVE_NORMAL;40self->visible = true;41self->drawGroup = Zone->objectDrawGroup[0];42self->updateRange.x = 0x1000000;43self->updateRange.y = 0x1000000;44RSDK.SetSpriteAnimation(LRZ1Intro->aniFrames, 0, &self->animator, true, 0);45self->state = LRZ1Intro_State_SetupActors;46}47}4849void LRZ1Intro_StageLoad(void)50{51LRZ1Intro->aniFrames = RSDK.LoadSpriteAnimation("LRZ1/IntroSub.bin", SCOPE_STAGE);5253LRZ1Intro->sfxSubLand = RSDK.GetSfx("LRZ/SubLand.wav");54LRZ1Intro->sfxWalkerLegs2 = RSDK.GetSfx("LRZ/WalkerLegs2.wav");55LRZ1Intro->sfxLava = RSDK.GetSfx("Stage/Lava.wav");56}5758void LRZ1Intro_HandlePlayerCollisions(void)59{60RSDK_THIS(LRZ1Intro);6162Hitbox *hitboxTopDeck = RSDK.GetHitbox(&self->animator, 0);63Hitbox *hitboxBottomDeck = RSDK.GetHitbox(&self->animator, 1);6465foreach_active(Player, player)66{67if (Player_CheckCollisionPlatform(player, self, hitboxTopDeck))68player->position.y += 0x20000;6970if (Player_CheckCollisionPlatform(player, self, hitboxBottomDeck))71player->position.y += 0x20000;72}73}7475void LRZ1Intro_HandlePlayerMovement(void)76{77RSDK_THIS(LRZ1Intro);7879foreach_active(Player, player)80{81player->velocity.x = 0;82player->velocity.y = 0;8384player->position.x = self->position.x + self->playerOffset[player->playerID].x;85player->position.y = self->position.y + self->playerOffset[player->playerID].y;86}87}8889void LRZ1Intro_HandleLavaContact(void)90{91RSDK_THIS(LRZ1Intro);9293if (!(Zone->timer & 3)) {94int32 x = self->position.x + 0xE00000;95int32 y = self->spawnPosY + RSDK.Rand(0x400000, 0x580000);96CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_BOSS), x, y)->drawGroup = Zone->objectDrawGroup[1];97}9899if (self->velocity.y <= 0x10000) {100if (!(Zone->timer % 6)) {101EntityLavaGeyser *geyser = CREATE_ENTITY(LavaGeyser, NULL, self->position.x, self->spawnPosY + 0x4C0000);102geyser->visible = true;103geyser->active = ACTIVE_NORMAL;104geyser->velocity.y = 0x40000;105106RSDK.SetSpriteAnimation(LavaGeyser->aniFrames, 1, &geyser->plumeAnimator, true, 0);107RSDK.SetSpriteAnimation(LavaGeyser->aniFrames, 0, &geyser->flowAnimator, true, 0);108RSDK.SetSpriteAnimation(LavaGeyser->aniFrames, 1, &geyser->plumeLoopAnimator, true, 16);109110geyser->state = LavaGeyser_State_Erupting;111}112}113}114115void LRZ1Intro_HandleExplosions(void)116{117RSDK_THIS(LRZ1Intro);118119if (!(Zone->timer & 3)) {120int32 x = self->position.x + RSDK.Rand(-0xE00000, 0xE00000);121int32 y = self->spawnPosY + RSDK.Rand(0x400000, 0x580000);122CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_BOSSPUFF), x, y);123}124}125126void LRZ1Intro_State_SetupActors(void)127{128RSDK_THIS(LRZ1Intro);129130EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);131132Hitbox *playerHitbox = Player_GetHitbox(player1);133player1->state = Player_State_Static;134RSDK.SetSpriteAnimation(player1->aniFrames, ANI_BALANCE_2, &player1->animator, false, 0);135136self->playerOffset[0].x = 0x600000;137self->playerOffset[0].y = -0x10000 * playerHitbox->bottom;138139for (int32 p = 1; p < Player->playerCount; ++p) {140EntityPlayer *playerPtr = RSDK_GET_ENTITY(p, Player);141142if (playerPtr->classID == Player->classID) {143Hitbox *hitbox = Player_GetHitbox(playerPtr);144self->playerOffset[p].x = 0x400000;145self->playerOffset[p].y = -0x10000 * hitbox->bottom;146playerPtr->state = Player_State_Static;147RSDK.SetSpriteAnimation(playerPtr->aniFrames, ANI_BALANCE_2, &playerPtr->animator, false, 0);148}149}150151foreach_all(Player, player)152{153player->position.x = self->position.x;154player->position.y = self->position.y;155156if (player->camera) {157player->camera->position.x = self->position.x;158player->camera->position.y = self->position.y;159}160}161162Zone->playerBoundActiveL[0] = false;163self->state = LRZ1Intro_State_IntroDelay;164}165166void LRZ1Intro_State_IntroDelay(void)167{168RSDK_THIS(LRZ1Intro);169170if (++self->timer == 32) {171self->timer = 0;172self->velocity.x = 0x100000;173self->state = LRZ1Intro_State_EnterSub;174175RSDK.PlaySfx(LRZ1Intro->sfxSubLand, false, 255);176177Zone->cameraBoundsL[0] = 2732;178Zone->cameraBoundsL[1] = 2732;179Zone->cameraBoundsL[2] = 2732;180Zone->cameraBoundsL[3] = 2732;181}182183LRZ1Intro_HandlePlayerMovement();184}185186void LRZ1Intro_State_EnterSub(void)187{188RSDK_THIS(LRZ1Intro);189190if (self->velocity.y < 0x100000)191self->velocity.y += 0x3800;192193self->position.x += self->velocity.x;194self->position.y += self->velocity.y;195196EntityCamera *camera = RSDK_GET_ENTITY(SLOT_CAMERA1, Camera);197if (self->velocity.y > 0x60000)198camera->lookPos.y += 3;199200if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, 0x800000, true)) {201Zone->playerBoundActiveL[0] = true;202self->spawnPosY = self->position.y + 0x380000;203self->state = LRZ1Intro_State_RidingSub;204205Camera_ShakeScreen(0, 0, 6);206camera->lookPos.y &= 0xFFFE;207208RSDK.PlaySfx(LRZ1Intro->sfxWalkerLegs2, false, 255);209}210211LRZ1Intro_HandlePlayerMovement();212}213214void LRZ1Intro_State_RidingSub(void)215{216RSDK_THIS(LRZ1Intro);217218self->velocity.x -= 0x1000;219if (self->velocity.x < 0)220self->velocity.x = 0;221222self->velocity.y = (200 * self->velocity.y) >> 8;223224self->position.x += self->velocity.x;225self->position.y += self->velocity.y;226227if (!(Zone->timer & 0xF))228RSDK.PlaySfx(LRZ1Intro->sfxLava, false, 255);229230if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_LWALL, 0, 0x1000000, 0x600000, true)) {231Camera_ShakeScreen(0, 0, 6);232self->state = LRZ1Intro_State_CrashedSub;233RSDK.PlaySfx(LRZ1Intro->sfxWalkerLegs2, false, 255);234}235236LRZ1Intro_HandleLavaContact();237LRZ1Intro_HandlePlayerMovement();238}239240void LRZ1Intro_State_CrashedSub(void)241{242RSDK_THIS(LRZ1Intro);243244if (++self->timer == 24) {245foreach_active(Player, player) { player->state = Player_State_Ground; }246self->timer = 0;247self->originY = self->position.y;248self->state = LRZ1Intro_State_SubSinking;249}250}251252void LRZ1Intro_State_SubSinking(void)253{254RSDK_THIS(LRZ1Intro);255256self->originY += 0x4000;257self->position.y = (RSDK.Sin256(self->timer) << 10) + self->originY;258259LRZ1Intro_HandleExplosions();260LRZ1Intro_HandlePlayerCollisions();261262self->timer += 2;263if (self->timer == 1024 || !RSDK.CheckOnScreen(self, NULL))264destroyEntity(self);265}266267#if GAME_INCLUDE_EDITOR268void LRZ1Intro_EditorDraw(void) {}269270void LRZ1Intro_EditorLoad(void) {}271#endif272273void LRZ1Intro_Serialize(void) {}274#endif275276277