Path: blob/master/SonicMania/Objects/ERZ/PhantomRuby.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PhantomRuby Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPhantomRuby *PhantomRuby;1011void PhantomRuby_Update(void)12{13RSDK_THIS(PhantomRuby);1415StateMachine_Run(self->state);1617// flash18if (self->rubyAnimator.animationID == 1 && self->rubyAnimator.frameID == self->rubyAnimator.frameCount - 1)19RSDK.SetSpriteAnimation(PhantomRuby->aniFrames, 0, &self->rubyAnimator, true, 0);2021// flash add22if (self->flashAnimator.animationID == 2 && self->flashAnimator.frameID == self->flashAnimator.frameCount - 1)23RSDK.SetSpriteAnimation(-1, 0xFFFF, &self->flashAnimator, true, 0);2425RSDK.ProcessAnimation(&self->rubyAnimator);26RSDK.ProcessAnimation(&self->flashAnimator);27}2829void PhantomRuby_LateUpdate(void) {}3031void PhantomRuby_StaticUpdate(void) {}3233void PhantomRuby_Draw(void)34{35RSDK_THIS(PhantomRuby);3637RSDK.DrawSprite(&self->rubyAnimator, NULL, false);3839if (self->flashAnimator.animationID != -1) {40self->inkEffect = INK_ADD;41self->alpha = 0xFF;42RSDK.DrawSprite(&self->flashAnimator, NULL, false);4344self->inkEffect = INK_NONE;45}46}4748void PhantomRuby_Create(void *data)49{50RSDK_THIS(PhantomRuby);5152self->active = ACTIVE_BOUNDS;53if (!SceneInfo->inEditor)54self->drawGroup = Zone->objectDrawGroup[1];5556self->startPos = self->position;57self->visible = true;58self->drawFX = FX_FLIP;59self->updateRange.x = TO_FIXED(128);60self->updateRange.y = TO_FIXED(128);61self->state = PhantomRuby_State_FinishedFlash;6263RSDK.SetSpriteAnimation(PhantomRuby->aniFrames, 0, &self->rubyAnimator, true, 0);64}6566void PhantomRuby_StageLoad(void)67{68PhantomRuby->aniFrames = RSDK.LoadSpriteAnimation("Global/PhantomRuby.bin", SCOPE_STAGE);6970PhantomRuby->sfxL[RUBYSFX_ATTACK1 - 1] = RSDK.GetSfx("Ruby/Attack1_L.wav");71PhantomRuby->sfxR[RUBYSFX_ATTACK1 - 1] = RSDK.GetSfx("Ruby/Attack1_R.wav");72PhantomRuby->sfxL[RUBYSFX_ATTACK2 - 1] = RSDK.GetSfx("Ruby/Attack2_L.wav");73PhantomRuby->sfxR[RUBYSFX_ATTACK2 - 1] = RSDK.GetSfx("Ruby/Attack2_R.wav");74PhantomRuby->sfxL[RUBYSFX_ATTACK3 - 1] = RSDK.GetSfx("Ruby/Attack3_L.wav");75PhantomRuby->sfxR[RUBYSFX_ATTACK3 - 1] = RSDK.GetSfx("Ruby/Attack3_R.wav");76PhantomRuby->sfxL[RUBYSFX_ATTACK4 - 1] = RSDK.GetSfx("Ruby/Attack4_L.wav");77PhantomRuby->sfxR[RUBYSFX_ATTACK4 - 1] = RSDK.GetSfx("Ruby/Attack4_R.wav");78PhantomRuby->sfxL[RUBYSFX_ATTACK5 - 1] = RSDK.GetSfx("Ruby/Attack5_L.wav");79PhantomRuby->sfxR[RUBYSFX_ATTACK5 - 1] = RSDK.GetSfx("Ruby/Attack5_R.wav");80PhantomRuby->sfxL[RUBYSFX_ATTACK6 - 1] = RSDK.GetSfx("Ruby/Attack6_L.wav");81PhantomRuby->sfxR[RUBYSFX_ATTACK6 - 1] = RSDK.GetSfx("Ruby/Attack6_R.wav");82PhantomRuby->sfxL[RUBYSFX_REDCUBE - 1] = RSDK.GetSfx("Ruby/RedCube_L.wav");83PhantomRuby->sfxR[RUBYSFX_REDCUBE - 1] = RSDK.GetSfx("Ruby/RedCube_R.wav");84}8586void PhantomRuby_PlaySfx(uint8 sfxID)87{88if (sfxID) {89int32 channel = RSDK.PlaySfx(PhantomRuby->sfxL[sfxID - 1], false, 0x00);90RSDK.SetChannelAttributes(channel, 1.0, -1.0, 1.0);9192channel = RSDK.PlaySfx(PhantomRuby->sfxR[sfxID - 1], false, 0x00);93RSDK.SetChannelAttributes(channel, 1.0, 1.0, 1.0);94}95}9697void PhantomRuby_SetupFlash(EntityPhantomRuby *ruby)98{99ruby->flashFinished = false;100ruby->hasFlashed = false;101ruby->timer = 0;102103RSDK.SetSpriteAnimation(PhantomRuby->aniFrames, 1, &ruby->rubyAnimator, true, 0);104RSDK.SetSpriteAnimation(PhantomRuby->aniFrames, 2, &ruby->flashAnimator, true, 0);105106ruby->state = PhantomRuby_State_PlaySfx;107}108109void PhantomRuby_State_FinishedFlash(void)110{111RSDK_THIS(PhantomRuby);112113if (self->flashFinished)114self->flashFinished = false;115}116117void PhantomRuby_State_PlaySfx(void)118{119RSDK_THIS(PhantomRuby);120121if (self->timer == 38) {122PhantomRuby_PlaySfx(self->sfx);123124self->flashFinished = true;125self->hasFlashed = true;126self->timer = 0;127self->state = PhantomRuby_State_FinishedFlash;128}129else {130self->timer++;131}132}133134void PhantomRuby_State_Oscillate(void)135{136RSDK_THIS(PhantomRuby);137138self->position.y = BadnikHelpers_Oscillate(self->startPos.y, 2, 10);139}140141void PhantomRuby_State_MoveGravity(void)142{143RSDK_THIS(PhantomRuby);144145self->position.x += self->velocity.x;146self->position.y += self->velocity.y;147self->velocity.y += 0x3800;148149if (self->position.y > (Zone->cameraBoundsB[0] + 64) << 16)150self->state = StateMachine_None;151}152153void PhantomRuby_State_MoveRotateGravity(void)154{155RSDK_THIS(PhantomRuby);156157self->position.x += self->velocity.x;158self->position.y += self->velocity.y;159self->velocity.y += 0x3800;160161self->rotation = (self->rotation + 5) & 0x1FF;162}163164void PhantomRuby_State_MoveRotateGravity_CheckGround(void)165{166RSDK_THIS(PhantomRuby);167168PhantomRuby_State_MoveRotateGravity();169170if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, TO_FIXED(8), true)) {171self->velocity.x >>= 1;172if (-(self->velocity.y >> 1) > -TO_FIXED(1))173self->velocity.y = 0;174else175self->velocity.y = -(self->velocity.y >> 1);176}177}178179#if MANIA_USE_PLUS180void PhantomRuby_State_MoveToPos(void)181{182RSDK_THIS(PhantomRuby);183184int32 rx = (self->startPos.x - self->position.x) >> 16;185int32 ry = (self->startPos.y - self->position.y) >> 16;186int32 angle = RSDK.ATan2(rx, ry);187188self->velocity.x += RSDK.Cos256(angle) << 3;189self->velocity.y += RSDK.Sin256(angle) << 3;190191int32 r = rx * rx + ry * ry;192if (r >= 0x10) {193if (r < 0x900) {194self->velocity.x = (self->startPos.x - self->position.x) >> 4;195self->velocity.y = (self->startPos.y - self->position.y) >> 4;196}197198self->position.x += self->velocity.x;199self->position.y += self->velocity.y;200}201else {202self->position.x = self->startPos.x;203self->position.y = self->startPos.y;204self->state = PhantomRuby_State_Oscillate;205}206}207#endif208209void PhantomRuby_State_RotateToOrigin(void)210{211RSDK_THIS(PhantomRuby);212213self->rotation += 6;214215if (self->rotation > 0x200) {216self->rotation = 0;217self->drawFX = FX_NONE;218self->state = StateMachine_None;219}220}221222#if GAME_INCLUDE_EDITOR223void PhantomRuby_EditorDraw(void)224{225RSDK_THIS(PhantomRuby);226PhantomRuby_SetupFlash(self);227228PhantomRuby_Draw();229}230231void PhantomRuby_EditorLoad(void)232{233PhantomRuby->aniFrames = RSDK.LoadSpriteAnimation("Global/PhantomRuby.bin", SCOPE_STAGE);234235RSDK_ACTIVE_VAR(PhantomRuby, sfx);236RSDK_ENUM_VAR("None", RUBYSFX_NONE);237RSDK_ENUM_VAR("Attack 1", RUBYSFX_ATTACK1);238RSDK_ENUM_VAR("Attack 2", RUBYSFX_ATTACK2);239RSDK_ENUM_VAR("Attack 3", RUBYSFX_ATTACK3);240RSDK_ENUM_VAR("Attack 4", RUBYSFX_ATTACK4);241RSDK_ENUM_VAR("Attack 5", RUBYSFX_ATTACK5);242RSDK_ENUM_VAR("Attack 6", RUBYSFX_ATTACK6);243RSDK_ENUM_VAR("Red Cube", RUBYSFX_REDCUBE);244}245#endif246247void PhantomRuby_Serialize(void) { RSDK_EDITABLE_VAR(PhantomRuby, VAR_UINT8, sfx); }248249250