Path: blob/master/SonicMania/Objects/MSZ/EggLoco.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: EggLoco Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectEggLoco *EggLoco;1011void EggLoco_Update(void)12{13RSDK_THIS(EggLoco);1415RSDK.ProcessAnimation(&self->eggmanAnimator);16RSDK.ProcessAnimation(&self->lanternAnimator);17RSDK.ProcessAnimation(&self->smallWheelAnimator);1819self->couplingAngle = (self->couplingAngle + 16) & 0x1FF;2021StateMachine_Run(self->state);2223if (!(Zone->timer & 0x3F)) {24RSDK.PlaySfx(EggLoco->sfxSmoke, false, 255);25CREATE_ENTITY(LocoSmoke, NULL, self->position.x + 0x450000, self->position.y - 0x480000);26}27}2829void EggLoco_LateUpdate(void) {}3031void EggLoco_StaticUpdate(void) {}3233void EggLoco_Draw(void)34{35RSDK_THIS(EggLoco);3637Vector2 drawPos;38drawPos.x = self->position.x;39drawPos.y = self->position.y - 2 * self->tootPullPos;40RSDK.DrawSprite(&self->eggmanTootAnimator, 0, false);41RSDK.DrawSprite(&self->whistleAnimator, &drawPos, false);4243drawPos.x = self->position.x - 0x2D0000;44drawPos.y = self->position.y - 0x3F0000;45self->drawFX = FX_ROTATE;46self->rotation = -(self->tootPullPos >> 15);47self->whistleCableAnimator.frameID = 0;48RSDK.DrawSprite(&self->whistleCableAnimator, &drawPos, false);4950drawPos.x = self->position.x - 0x5F0000;51drawPos.y = self->tootPullPos + self->position.y - 0x3F0000;52self->drawFX = FX_NONE;53self->whistleCableAnimator.frameID = 1;54RSDK.DrawSprite(&self->whistleCableAnimator, &drawPos, false);5556self->whistleCableAnimator.frameID = 2;57RSDK.DrawSprite(&self->whistleCableAnimator, &drawPos, false);58RSDK.DrawSprite(&self->eggmanTootAnimator, NULL, false);59RSDK.DrawSprite(&self->eggmanAnimator, NULL, false);60RSDK.DrawSprite(&self->locomotiveAnimator, NULL, false);6162drawPos.x = self->position.x - 0x680000;63drawPos.y = self->position.y + 0x380000;64self->rotation = self->couplingAngle;65self->drawFX = FX_ROTATE;66RSDK.DrawSprite(&self->bigWheelAnimator, &drawPos, false);6768self->drawFX = FX_NONE;69RSDK.DrawSprite(&self->bigWheelEdgeAnimator, &drawPos, false);7071drawPos.x += 0x4A0000;72self->drawFX = FX_ROTATE;73self->rotation = self->couplingAngle + 0x100;74RSDK.DrawSprite(&self->bigWheelAnimator, &drawPos, false);7576self->drawFX = FX_NONE;77RSDK.DrawSprite(&self->bigWheelEdgeAnimator, &drawPos, false);7879drawPos.x = self->position.x + 0x160000;80drawPos.y = self->position.y + 0x4B0000;81RSDK.DrawSprite(&self->smallWheelAnimator, &drawPos, false);8283drawPos.x += 0x3E0000;84RSDK.DrawSprite(&self->smallWheelAnimator, &drawPos, false);8586drawPos.x = (2304 * RSDK.Cos512(self->couplingAngle) + self->position.x - 0x680000) + 0x4C0000;87drawPos.y = ((9 * RSDK.Sin512(self->couplingAngle)) << 8) + self->position.y + 0x380000;88self->couplingAnimator.frameID = 1;89self->drawFX = FX_ROTATE;90self->rotation = RSDK.Sin512(-self->couplingAngle) / 18 - 4;91RSDK.DrawSprite(&self->couplingAnimator, &drawPos, false);9293self->drawFX = FX_NONE;94drawPos.x -= 0x4C0000;95self->couplingAnimator.frameID = 0;96RSDK.DrawSprite(&self->couplingAnimator, &drawPos, false);9798self->pistonRodAnimator.frameID = 0;99drawPos.x = self->position.x + ((RSDK.Cos512(self->couplingAngle) + 256) << 11);100drawPos.y = self->position.y;101RSDK.DrawSprite(&self->pistonRodAnimator, &drawPos, false);102103self->pistonRodAnimator.frameID = 2;104RSDK.DrawSprite(&self->pistonRodAnimator, &drawPos, false);105106self->pistonRodAnimator.frameID = 1;107RSDK.DrawSprite(&self->pistonRodAnimator, NULL, false);108RSDK.DrawSprite(&self->guardAnimator, NULL, false);109RSDK.DrawSprite(&self->lanternAnimator, NULL, false);110}111112void EggLoco_Create(void *data)113{114RSDK_THIS(EggLoco);115116if (!SceneInfo->inEditor) {117self->visible = true;118self->drawGroup = Zone->objectDrawGroup[0];119self->active = ACTIVE_BOUNDS;120self->updateRange.x = 0xA00000;121self->updateRange.y = 0x600000;122self->state = EggLoco_State_TootDelay;123self->timer = 60;124125RSDK.SetSpriteAnimation(EggLoco->aniFrames, 0, &self->locomotiveAnimator, true, 0);126RSDK.SetSpriteAnimation(EggLoco->aniFrames, 6, &self->whistleAnimator, true, 0);127RSDK.SetSpriteAnimation(EggLoco->aniFrames, 1, &self->bigWheelAnimator, true, 0);128RSDK.SetSpriteAnimation(EggLoco->aniFrames, 1, &self->bigWheelEdgeAnimator, true, 1);129RSDK.SetSpriteAnimation(EggLoco->aniFrames, 2, &self->smallWheelAnimator, true, 0);130RSDK.SetSpriteAnimation(EggLoco->aniFrames, 3, &self->couplingAnimator, true, 0);131RSDK.SetSpriteAnimation(EggLoco->aniFrames, 5, &self->guardAnimator, true, 0);132RSDK.SetSpriteAnimation(EggLoco->aniFrames, 7, &self->lanternAnimator, true, 0);133RSDK.SetSpriteAnimation(EggLoco->aniFrames, 4, &self->pistonRodAnimator, true, 0);134RSDK.SetSpriteAnimation(EggLoco->aniFrames, 10, &self->eggmanAnimator, true, 0);135RSDK.SetSpriteAnimation(EggLoco->aniFrames, 12, &self->eggmanTootAnimator, true, 0);136RSDK.SetSpriteAnimation(EggLoco->aniFrames, 13, &self->whistleCableAnimator, true, 0);137}138}139140void EggLoco_StageLoad(void)141{142EggLoco->aniFrames = RSDK.LoadSpriteAnimation("MSZ/Train.bin", SCOPE_STAGE);143144EggLoco->sfxSmoke = RSDK.GetSfx("MSZ/LocoSmoke.wav");145EggLoco->sfxWhistle = RSDK.GetSfx("MSZ/LocoWhistle.wav");146Soundboard_LoadSfx("MSZ/LocoChugga.wav", true, EggLoco_SfxCheck_LocoChugga, EggLoco_SfxUpdate_LocoChugga);147}148149bool32 EggLoco_SfxCheck_LocoChugga(void)150{151int32 count = 0;152int32 screenX = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;153int32 screenY = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;154155foreach_all(EggLoco, eggLoco)156{157if ((MathHelpers_Distance(eggLoco->position.x, eggLoco->position.y, screenX, screenY) >> 16) <= 840)158count++;159}160161return count > 0;162}163164void EggLoco_SfxUpdate_LocoChugga(int32 sfx)165{166int32 screenX = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;167int32 screenY = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;168169foreach_all(EggLoco, eggLoco)170{171int32 distX = abs(screenX - eggLoco->position.x) >> 16;172int32 distY = abs(screenY - eggLoco->position.y) >> 16;173int32 vol = MIN(MathHelpers_SquareRoot(distX * distX + distY * distY), 840);174175RSDK.SetChannelAttributes(Soundboard->sfxChannel[sfx], 1.0 - (vol / 840.0), 0.0, 1.0);176foreach_break;177}178}179180void EggLoco_State_TootDelay(void)181{182RSDK_THIS(EggLoco);183184if (self->timer <= 0) {185RSDK.SetSpriteAnimation(EggLoco->aniFrames, 11, &self->eggmanAnimator, true, 0);186RSDK.SetSpriteAnimation(EggLoco->aniFrames, 12, &self->eggmanTootAnimator, true, 0);187self->state = EggLoco_State_Whistle;188}189else {190self->timer--;191}192}193194void EggLoco_State_Whistle(void)195{196RSDK_THIS(EggLoco);197198if (++self->timer == 4) {199RSDK.PlaySfx(EggLoco->sfxWhistle, false, 255);200self->timer = 0;201self->state = EggLoco_State_Tooting;202}203}204205void EggLoco_State_Tooting(void)206{207RSDK_THIS(EggLoco);208209RSDK.ProcessAnimation(&self->eggmanTootAnimator);210211// How much eggman's pulled the "toot" down212self->tootPullPos = (RSDK.GetFrameID(&self->eggmanTootAnimator) - 'a') << 16;213214if (self->tootPullPos >= 0x10000 && !(Zone->timer & 3)) {215EntityDust *dust = CREATE_ENTITY(Dust, NULL, self->position.x - 0x240000, self->position.y - 0x4E0000);216dust->state = Dust_State_DustPuff_Friction;217dust->velocity.x = 0x20000;218dust->velocity.y = -0x18000;219dust->drawGroup = Zone->objectDrawGroup[0];220}221222if (self->eggmanAnimator.animationID == 11 && self->eggmanAnimator.frameID == self->eggmanAnimator.frameCount - 1)223RSDK.SetSpriteAnimation(EggLoco->aniFrames, 10, &self->eggmanAnimator, true, 0);224225if (self->eggmanTootAnimator.frameID == self->eggmanTootAnimator.frameCount - 1) {226self->timer = RSDK.Rand(60, 180);227self->state = EggLoco_State_TootDelay;228}229}230231#if GAME_INCLUDE_EDITOR232void EggLoco_EditorDraw(void)233{234RSDK_THIS(EggLoco);235236self->updateRange.x = 0xA00000;237self->updateRange.y = 0x600000;238239RSDK.SetSpriteAnimation(EggLoco->aniFrames, 0, &self->locomotiveAnimator, true, 0);240RSDK.SetSpriteAnimation(EggLoco->aniFrames, 6, &self->whistleAnimator, true, 0);241RSDK.SetSpriteAnimation(EggLoco->aniFrames, 1, &self->bigWheelAnimator, true, 0);242RSDK.SetSpriteAnimation(EggLoco->aniFrames, 1, &self->bigWheelEdgeAnimator, true, 1);243RSDK.SetSpriteAnimation(EggLoco->aniFrames, 2, &self->smallWheelAnimator, true, 0);244RSDK.SetSpriteAnimation(EggLoco->aniFrames, 3, &self->couplingAnimator, true, 0);245RSDK.SetSpriteAnimation(EggLoco->aniFrames, 5, &self->guardAnimator, true, 0);246RSDK.SetSpriteAnimation(EggLoco->aniFrames, 7, &self->lanternAnimator, true, 0);247RSDK.SetSpriteAnimation(EggLoco->aniFrames, 4, &self->pistonRodAnimator, true, 0);248RSDK.SetSpriteAnimation(EggLoco->aniFrames, 10, &self->eggmanAnimator, true, 0);249RSDK.SetSpriteAnimation(EggLoco->aniFrames, 12, &self->eggmanTootAnimator, true, 0);250RSDK.SetSpriteAnimation(EggLoco->aniFrames, 13, &self->whistleCableAnimator, true, 0);251252EggLoco_Draw();253}254255void EggLoco_EditorLoad(void) { EggLoco->aniFrames = RSDK.LoadSpriteAnimation("MSZ/Train.bin", SCOPE_STAGE); }256#endif257258void EggLoco_Serialize(void) {}259260261