Path: blob/master/SonicMania/Objects/ERZ/PhantomRider.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PhantomRider Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPhantomRider *PhantomRider;1011void PhantomRider_Update(void)12{13RSDK_THIS(PhantomRider);1415if (self->invincibilityTimer > 0)16self->invincibilityTimer--;1718StateMachine_Run(self->state);19}2021void PhantomRider_LateUpdate(void) {}2223void PhantomRider_StaticUpdate(void) {}2425void PhantomRider_Draw(void)26{27RSDK_THIS(PhantomRider);2829RSDK.SetActivePalette(4, 0, ScreenInfo[SceneInfo->currentScreenID].size.y);3031if (self->invincibilityTimer & 1)32RSDK.CopyPalette(6, 128, 4, 128, 128);3334if (self->stateDraw) {35StateMachine_Run(self->stateDraw);36}37else {38RSDK.DrawSprite(&self->mainAnimator, NULL, false);39}4041if (self->invincibilityTimer & 1)42RSDK.CopyPalette(5, 128, 4, 128, 128);4344RSDK.SetActivePalette(0, 0, ScreenInfo[SceneInfo->currentScreenID].size.y);45}4647void PhantomRider_Create(void *data)48{49RSDK_THIS(PhantomRider);5051if (!SceneInfo->inEditor) {52self->visible = true;53self->drawGroup = Zone->objectDrawGroup[0];54self->updateRange.x = 0x800000;55self->updateRange.y = 0x800000;56self->type = VOID_TO_INT(data);5758if (data) {59if (VOID_TO_INT(data) == PHANTOMRIDER_JIMMY) {60self->active = ACTIVE_NORMAL;61self->state = PhantomRider_State_Jimmy;62}63}64else {65self->active = ACTIVE_BOUNDS;66self->drawFX = FX_FLIP;6768RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 0, &self->mainAnimator, true, 0);69RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 4, &self->jimmyAnimator, true, 0);70RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 5, &self->wheelAnimator, true, 0);71RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 6, &self->thrustAnimator, true, 0);7273self->direction = FLIP_X;74self->collisionPlane = 1;75self->collisionLayers = Zone->collisionLayers;76self->startPos = self->position;77self->tileCollisions = TILECOLLISION_DOWN;7879self->hitbox.left = -24;80self->hitbox.top = 0;81self->hitbox.right = 24;82self->hitbox.bottom = 20;8384self->outerBox.left = -12;85self->outerBox.top = 0;86self->outerBox.right = 12;87self->outerBox.bottom = 30;8889self->innerBox.left = -11;90self->innerBox.top = 0;91self->innerBox.right = 11;92self->innerBox.bottom = 30;9394self->stateDraw = PhantomRider_Draw_Rider;95self->state = PhantomRider_State_HandleBegin;96}97}98}99100void PhantomRider_StageLoad(void)101{102PhantomRider->aniFrames = RSDK.LoadSpriteAnimation("Phantom/PhantomRider.bin", SCOPE_STAGE);103104PhantomRider->sfxRiderLaunch = RSDK.GetSfx("LRZ/RiderLaunch.wav");105}106107void PhantomRider_ProcessAutoScroll(void)108{109if (Zone->autoScrollSpeed > 0x80000) {110Zone->autoScrollSpeed -= 0x2000;111112if (Zone->autoScrollSpeed < 0x80000)113Zone->autoScrollSpeed = 0x80000;114}115116if (Zone->autoScrollSpeed < 0x80000) {117Zone->autoScrollSpeed += 0x2000;118119if (Zone->autoScrollSpeed > 0x80000)120Zone->autoScrollSpeed = 0x80000;121}122123foreach_active(Player, player)124{125if (player->groundVel < Zone->autoScrollSpeed - 0x20000)126player->groundVel = Zone->autoScrollSpeed - 0x20000;127128player->direction = FLIP_NONE;129player->topSpeed = Zone->autoScrollSpeed + 0x20000;130131if (player->groundVel > player->topSpeed)132player->groundVel = player->topSpeed;133}134}135136void PhantomRider_Hit(void)137{138RSDK_THIS(PhantomRider);139140self->invincibilityTimer = 48;141RSDK.PlaySfx(PhantomEgg->sfxHit, false, 255);142}143144void PhantomRider_Draw_Rider(void)145{146RSDK_THIS(PhantomRider);147148RSDK.DrawSprite(&self->jimmyAnimator, NULL, false);149RSDK.DrawSprite(&self->mainAnimator, NULL, false);150RSDK.DrawSprite(&self->wheelAnimator, NULL, false);151RSDK.DrawSprite(&self->thrustAnimator, NULL, false);152}153154void PhantomRider_State_HandleBegin(void)155{156RSDK_THIS(PhantomRider);157158EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);159160if (player1->position.x > self->position.x) {161EntityPhantomRider *child = CREATE_ENTITY(PhantomRider, INT_TO_VOID(PHANTOMRIDER_JIMMY), player1->position.x, player1->position.y);162163EntityCamera *camera = RSDK_GET_ENTITY(SLOT_CAMERA1, Camera);164camera->target = (Entity *)child;165camera->state = Camera_State_FollowXY;166167player1->camera = NULL;168Zone->autoScrollSpeed = player1->velocity.x;169170self->groundVel = 0;171self->velocity.x = 0;172self->child = child;173self->active = ACTIVE_NORMAL;174self->state = PhantomRider_State_EnterRider;175176foreach_active(PopOut, popOut)177{178popOut->active = ACTIVE_NORMAL;179popOut->drawGroup = 2;180}181foreach_active(Button, button) { button->active = ACTIVE_NORMAL; }182RSDK.PlaySfx(PhantomRider->sfxRiderLaunch, false, 255);183}184}185186void PhantomRider_State_EnterRider(void)187{188RSDK_THIS(PhantomRider);189190RSDK.ProcessAnimation(&self->mainAnimator);191RSDK.ProcessAnimation(&self->jimmyAnimator);192RSDK.ProcessAnimation(&self->wheelAnimator);193RSDK.ProcessAnimation(&self->thrustAnimator);194195PhantomRider_ProcessAutoScroll();196197if (++self->timer > 48) {198if (self->groundVel < 0xC0000)199self->groundVel += 0x40000;200}201202if (self->position.x > self->child->position.x + 0x200000) {203self->timer = 0;204205RSDK.PlaySfx(PhantomRider->sfxRiderLaunch, false, 0xFF);206self->state = PhantomRider_State_InitialRace;207}208209if (!self->onGround) {210self->velocity.y += 0x3800;211212if (self->velocity.y > 0xC0000)213self->velocity.y = 0xC0000;214}215216self->prevOnGround = self->onGround;217RSDK.ProcessObjectMovement(self, &self->outerBox, &self->innerBox);218}219220void PhantomRider_State_InitialRace(void)221{222RSDK_THIS(PhantomRider);223224RSDK.ProcessAnimation(&self->mainAnimator);225RSDK.ProcessAnimation(&self->jimmyAnimator);226RSDK.ProcessAnimation(&self->wheelAnimator);227RSDK.ProcessAnimation(&self->thrustAnimator);228229PhantomRider_ProcessAutoScroll();230231if (self->groundVel > Zone->autoScrollSpeed - 0x10000) {232self->groundVel -= 0x2000;233234if (self->groundVel < Zone->autoScrollSpeed - 0x4000)235self->groundVel = Zone->autoScrollSpeed - 0x4000;236}237238if (!self->onGround) {239self->velocity.y += 0x3800;240241if (self->velocity.y > 0xC0000)242self->velocity.y = 0xC0000;243}244245self->prevOnGround = self->onGround;246RSDK.ProcessObjectMovement(self, &self->outerBox, &self->innerBox);247248EntityPlatformNode *marker = RSDK_GET_ENTITY(SceneInfo->entitySlot + 1, PlatformNode);249if (self->position.x > marker->position.x)250self->state = PhantomRider_State_RacePlayer;251}252253void PhantomRider_State_RacePlayer(void)254{255RSDK_THIS(PhantomRider);256257RSDK.ProcessAnimation(&self->mainAnimator);258RSDK.ProcessAnimation(&self->jimmyAnimator);259RSDK.ProcessAnimation(&self->wheelAnimator);260RSDK.ProcessAnimation(&self->thrustAnimator);261262PhantomRider_ProcessAutoScroll();263264if (!self->onGround) {265self->velocity.y += 0x3800;266267if (self->velocity.y > 0xC0000)268self->velocity.y = 0xC0000;269}270271self->prevOnGround = self->onGround;272RSDK.ProcessObjectMovement(self, &self->outerBox, &self->innerBox);273274if (++self->timer == 560) {275self->timer = 0;276Zone->autoScrollSpeed = 0;277278PhantomEgg_SetupWarpFX();279self->state = PhantomRider_State_ExitRider;280281foreach_active(PopOut, popOut) { popOut->shouldAppear = false; }282foreach_active(Player, player) { Player_UpdatePhysicsState(player); }283}284285foreach_active(Spikes, spikes)286{287if (RSDK.CheckObjectCollisionTouchBox(self, &self->hitbox, spikes, &spikes->hitbox) == C_TOP) {288EntityPopOut *popOut = RSDK_GET_ENTITY(RSDK.GetEntitySlot(spikes) - 1, PopOut);289popOut->shouldAppear = false;290291foreach_active(Button, button)292{293if (button->tag == popOut->tag)294button->activated = false;295}296297PhantomRider_Hit();298}299}300}301302void PhantomRider_State_ExitRider(void)303{304RSDK_THIS(PhantomRider);305306if (++self->timer == 60) {307self->position.x = self->startPos.x;308self->position.y = self->startPos.y;309self->timer = 0;310self->active = ACTIVE_BOUNDS;311destroyEntity(self->child);312313EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);314Camera_SetTargetEntity(0, player1);315player1->camera = RSDK_GET_ENTITY(SLOT_CAMERA1, Camera);316317foreach_active(PopOut, popOut) { popOut->active = ACTIVE_BOUNDS; }318319foreach_active(Button, button)320{321button->active = ACTIVE_BOUNDS;322button->activated = false;323}324325self->state = PhantomRider_State_HandleBegin;326}327}328329void PhantomRider_State_Jimmy(void)330{331RSDK_THIS(PhantomRider);332333self->position.x += Zone->autoScrollSpeed;334335if (self->position.y < 0x8A80000)336self->position.y += 0x20000;337338EntityCamera *camera = RSDK_GET_ENTITY(SLOT_CAMERA1, Camera);339340if (camera->offset.y > 0)341camera->offset.y -= (camera->offset.y >> 4);342343foreach_active(Player, player)344{345int32 x = self->position.x - (ScreenInfo->center.x << 16) + 0x100000;346if (player->position.x < x)347player->position.x = x;348349int32 y = ((ScreenInfo->center.x - 16) << 16) + self->position.x;350if (player->position.x > y)351player->position.x = y;352}353}354355#if GAME_INCLUDE_EDITOR356void PhantomRider_EditorDraw(void)357{358RSDK_THIS(PhantomRider);359360self->drawFX = FX_FLIP;361self->direction = FLIP_X;362RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 0, &self->mainAnimator, true, 0);363RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 4, &self->jimmyAnimator, true, 0);364RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 5, &self->wheelAnimator, true, 0);365RSDK.SetSpriteAnimation(PhantomRider->aniFrames, 6, &self->thrustAnimator, true, 0);366367PhantomRider_Draw_Rider();368}369370void PhantomRider_EditorLoad(void) { PhantomRider->aniFrames = RSDK.LoadSpriteAnimation("Phantom/PhantomRider.bin", SCOPE_STAGE); }371#endif372373void PhantomRider_Serialize(void) {}374375376