Path: blob/master/SonicMania/Objects/MMZ/EggPistonsMKII.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: EggPistonsMKII Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectEggPistonsMKII *EggPistonsMKII;1011void EggPistonsMKII_Update(void)12{13RSDK_THIS(EggPistonsMKII);1415StateMachine_Run(self->state);16}1718void EggPistonsMKII_LateUpdate(void) {}1920void EggPistonsMKII_StaticUpdate(void) {}2122void EggPistonsMKII_Draw(void)23{24RSDK_THIS(EggPistonsMKII);2526if (self->type == EGGPISTON_ALARM) {27RSDK.FillScreen(0x880000, EggPistonsMKII->alarmTimer, EggPistonsMKII->alarmTimer, EggPistonsMKII->alarmTimer);28}29else {30RSDK.DrawSprite(&self->altAnimator, NULL, false);31RSDK.DrawSprite(&self->mainAnimator, NULL, false);32}33}3435void EggPistonsMKII_Create(void *data)36{37RSDK_THIS(EggPistonsMKII);3839self->drawFX = FX_FLIP;40if (!SceneInfo->inEditor) {41if (globals->gameMode < MODE_TIMEATTACK) {42self->active = ACTIVE_BOUNDS;4344if (data)45self->type = VOID_TO_INT(data);4647switch (self->type) {48case EGGPISTON_PISTON:49RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 0, &self->mainAnimator, true, 0);5051self->updateRange.x = 0xA00000;52self->updateRange.y = 0xEC0000;5354self->hitbox.left = -32;55self->hitbox.top = -96;56self->hitbox.right = 32;57self->hitbox.bottom = 60;5859self->state = EggPistonsMKII_StatePiston_Idle;60self->visible = true;61self->drawGroup = Zone->fgDrawGroup[1] - 1;62self->pistonID = self->position.y;6364EggPistonsMKII->pistons[EggPistonsMKII->pistonCount++] = self;65break;6667case EGGPISTON_CONTROL:68RSDK.SetSpriteAnimation(EggPistonsMKII->eggmanFrames, 0, &self->mainAnimator, true, 0);6970self->updateRange.x = 0x800000;71self->updateRange.y = 0x800000;7273self->hitbox.left = -33;74self->hitbox.top = -37;75self->hitbox.right = 33;76self->hitbox.bottom = 6;7778self->state = EggPistonsMKII_State_SetupArena;79self->visible = false;80self->drawGroup = Zone->objectDrawGroup[0];8182EggPistonsMKII->controller = self;83break;8485case EGGPISTON_EMITTER:86RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 1, &self->mainAnimator, true, 0);8788self->updateRange.x = 0x800000;89self->updateRange.y = 0x800000;9091self->hitbox.left = -8;92self->hitbox.top = -8;93self->hitbox.right = 8;94self->hitbox.bottom = 8;9596self->state = EggPistonsMKII_StatePiston_Idle;97self->visible = true;98self->drawGroup = Zone->objectDrawGroup[0] + 1;99break;100101case EGGPISTON_BARRIER:102RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 5, &self->mainAnimator, true, 0);103104self->hitbox.left = -32;105self->hitbox.top = -32;106self->hitbox.right = 32;107self->hitbox.bottom = 32;108109self->state = EggPistonsMKII_StateOrbGenerator_Idle;110self->updateRange.x = 0x800000;111self->updateRange.y = 0x800000;112self->visible = true;113self->drawGroup = Zone->objectDrawGroup[0];114break;115116case EGGPISTON_PLASMABALL:117RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 2, &self->mainAnimator, true, 0);118119self->hitbox.left = -12;120self->hitbox.top = -12;121self->hitbox.right = 12;122self->hitbox.bottom = 12;123124self->state = EggPistonsMKII_StateOrb_MoveToTargetPos;125self->updateRange.x = 0x800000;126self->updateRange.y = 0x800000;127self->visible = true;128self->drawGroup = Zone->objectDrawGroup[0];129break;130131case EGGPISTON_ALARM:132self->updateRange.x = 0x800000;133self->updateRange.y = 0x800000;134135self->state = EggPistonsMKII_StateAlarm_Active;136self->visible = true;137self->drawGroup = Zone->objectDrawGroup[1];138break;139140default: break;141}142}143else {144destroyEntity(self);145}146}147}148149void EggPistonsMKII_StageLoad(void)150{151EggPistonsMKII->aniFrames = RSDK.LoadSpriteAnimation("MMZ/EggPistonsMKII.bin", SCOPE_STAGE);152EggPistonsMKII->eggmanFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanMMZ1.bin", SCOPE_STAGE);153154EggPistonsMKII->pistonCount = 0;155EggPistonsMKII->invincibilityTimer = 0;156EggPistonsMKII->isPhase2 = false;157158EggPistonsMKII->sfxHit = RSDK.GetSfx("Stage/BossHit.wav");159EggPistonsMKII->sfxWall = RSDK.GetSfx("Stage/Wall.wav");160EggPistonsMKII->sfxElectrify = RSDK.GetSfx("Stage/Electrify.wav");161EggPistonsMKII->sfxExplosion = RSDK.GetSfx("Stage/Explosion2.wav");162EggPistonsMKII->sfxAlarm = RSDK.GetSfx("MMZ/Alarm.wav");163164RSDK.StopSfx(EggPistonsMKII->sfxAlarm);165}166167void EggPistonsMKII_CheckPlayerCollisions_Piston(void)168{169RSDK_THIS(EggPistonsMKII);170171EntityEggPistonsMKII *parent = self->parent;172173foreach_active(Player, player)174{175int32 side = Player_CheckCollisionBox(player, self, &self->hitbox);176if (side == C_TOP) {177player->position.y += self->velocity.y;178player->position.y &= 0xFFFF0000;179}180else if (side == C_BOTTOM && player->onGround)181player->deathType = PLAYER_DEATH_DIE_USESFX;182}183184self->position.y += self->velocity.y;185if (parent) {186parent->position.x = self->position.x;187parent->position.y = self->position.y;188parent->position.y += self->direction ? 0xE0000 : -0xA0000;189}190}191192void EggPistonsMKII_CheckPlayerCollisions_EggPiston(void)193{194RSDK_THIS(EggPistonsMKII);195196foreach_active(Player, player)197{198if (!EggPistonsMKII->invincibilityTimer && Player_CheckBadnikTouch(player, self, &self->hitbox)199&& EggPistonsMKII_CheckPlayerAttacking(player)) {200EggPistonsMKII_Hit();201}202}203}204205void EggPistonsMKII_CheckPlayerCollisions_Ball(void)206{207RSDK_THIS(EggPistonsMKII);208209foreach_active(Player, player)210{211if (Player_CheckCollisionTouch(player, self, &self->hitbox))212Player_ElementHurt(player, self, SHIELD_LIGHTNING);213}214}215216void EggPistonsMKII_CheckPlayerCollisions_Solid(void)217{218RSDK_THIS(EggPistonsMKII);219220foreach_active(Player, player)221{222if (Player_CheckCollisionBox(player, self, &self->hitbox) == C_BOTTOM) {223if (player->onGround)224player->deathType = PLAYER_DEATH_DIE_USESFX;225}226}227}228229void EggPistonsMKII_Hit(void)230{231RSDK_THIS(EggPistonsMKII);232233EggPistonsMKII->invincibilityTimer = 120;234if (EggPistonsMKII->health > 0)235EggPistonsMKII->health--;236237if (EggPistonsMKII->health) {238RSDK.SetSpriteAnimation(EggPistonsMKII->eggmanFrames, 1, &self->mainAnimator, true, 0);239RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 4, &self->altAnimator, true, 0);240RSDK.PlaySfx(EggPistonsMKII->sfxHit, false, 255);241}242else {243RSDK.SetSpriteAnimation(EggPistonsMKII->eggmanFrames, 2, &self->mainAnimator, true, 0);244SceneInfo->timeEnabled = false;245Player_GiveScore(RSDK_GET_ENTITY(SLOT_PLAYER1, Player), 1000);246self->mainAnimator.frameID = 1;247RSDK.PlaySfx(EggPistonsMKII->sfxExplosion, false, 255);248self->state = EggPistonsMKII_State_Finish;249}250}251252void EggPistonsMKII_Explode(void)253{254RSDK_THIS(EggPistonsMKII);255256int32 interval = 4 * (EggPistonsMKII->health != 0) + 3;257258if (!(Zone->timer % interval)) {259RSDK.PlaySfx(EggPistonsMKII->sfxExplosion, false, 255);260261if (Zone->timer & 4) {262int32 x = self->position.x + (RSDK.Rand(-24, 24) << 16);263int32 y = self->position.y + (RSDK.Rand(-48, 48) << 16);264CREATE_ENTITY(Explosion, INT_TO_VOID((RSDK.Rand(0, 256) > 192) + EXPLOSION_BOSS), x, y)->drawGroup = Zone->objectDrawGroup[1];265}266}267}268269EntityEggPistonsMKII *EggPistonsMKII_GetNextPiston(void)270{271RSDK_THIS(EggPistonsMKII);272273int32 pistonID = RSDK.Rand(0, 5);274EntityEggPistonsMKII *piston = EggPistonsMKII->pistons[pistonID];275276if (piston->state != EggPistonsMKII_StatePiston_Idle)277pistonID = EggPistonsMKII->pistonID - 1; // force another try278279while (pistonID == EggPistonsMKII->pistonID - 1 || pistonID == EggPistonsMKII->pistonID + 1) {280pistonID = RSDK.Rand(0, 5);281piston = EggPistonsMKII->pistons[pistonID];282283if (piston->state != EggPistonsMKII_StatePiston_Idle)284pistonID = EggPistonsMKII->pistonID - 1; // force another try285}286287EggPistonsMKII->pistonID = pistonID;288289self->visible = true;290piston->timer = 15;291piston->state = EggPistonsMKII_StatePiston_Shaking;292return piston;293}294295void EggPistonsMKII_SpawnElecBall(void)296{297EntityEggPistonsMKII *spawner = RSDK_GET_ENTITY(SceneInfo->entitySlot + 6, EggPistonsMKII);298spawner->state = EggPistonsMKII_StateOrbGenerator_Warning;299spawner->timer = 330;300int32 offset = 0;301302for (int32 i = 0; i < 4; ++i) {303EntityEggPistonsMKII *child = CREATE_ENTITY(EggPistonsMKII, INT_TO_VOID(EGGPISTON_PLASMABALL), spawner->position.x, spawner->position.y);304child->pistonID = offset + spawner->position.x + ((RSDK.Rand(0, 48) - 48) << 16);305child->inkEffect = INK_ADD;306child->velocity.x = (child->pistonID - child->position.x) >> 4;307child->alpha = 0;308offset -= 0x570000;309}310}311312bool32 EggPistonsMKII_CheckPlayerAttacking(EntityPlayer *player)313{314RSDK_THIS(EggPistonsMKII);315316if (Player_CheckAttacking(player, NULL)) {317if (player->position.x >= self->position.x) {318player->velocity.x = 0x30000;319player->groundVel = 0x30000;320}321else {322player->velocity.x = -0x30000;323player->groundVel = -0x30000;324}325326if (player->characterID == ID_KNUCKLES && player->animator.animationID == ANI_GLIDE) {327RSDK.SetSpriteAnimation(Player->knuxFrames, ANI_GLIDE_DROP, &player->animator, true, 0);328player->state = Player_State_KnuxGlideDrop;329}330331return true;332}333334return false;335}336337void EggPistonsMKII_State_SetupArena(void)338{339RSDK_THIS(EggPistonsMKII);340341for (int32 i = 0; i < 6; ++i) {342EntityCollapsingPlatform *platform = RSDK_GET_ENTITY(SceneInfo->entitySlot + 8 + i, CollapsingPlatform);343if (platform->classID == CollapsingPlatform->classID)344platform->active = ACTIVE_NEVER;345}346347if (++self->timer >= 2) {348self->timer = 0;349350Zone->playerBoundActiveR[0] = true;351Zone->playerBoundActiveB[0] = true;352Zone->cameraBoundsR[0] = (self->position.x >> 16) + ScreenInfo->center.x;353Zone->cameraBoundsB[0] = (self->position.y >> 16) + 71;354Zone->cameraBoundsT[0] = Zone->cameraBoundsB[0] - ScreenInfo->size.y;355356self->active = ACTIVE_NORMAL;357self->state = EggPistonsMKII_State_EnterBoss;358}359}360361void EggPistonsMKII_State_EnterBoss(void)362{363RSDK_THIS(EggPistonsMKII);364365EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);366367Zone->playerBoundActiveL[0] = true;368Zone->cameraBoundsL[0] = ScreenInfo->position.x;369370int32 pos = MANIA_USE_PLUS ? (self->position.x - 0xC00000) : self->position.x;371if (player1->position.x > pos) {372#if MANIA_USE_PLUS373if (player1->onGround)374player1->state = Player_State_Ground;375player1->stateInput = StateMachine_None;376player1->jumpPress = false;377player1->jumpHold = false;378player1->left = false;379player1->right = true;380player1->up = false;381player1->down = false;382383if (player1->groundVel > 0x30000)384player1->groundVel = 0x30000;385386if (player1->position.x > (self->position.x - 0x80000)) {387#endif388Zone->playerBoundActiveL[0] = true;389Zone->cameraBoundsL[0] = (self->position.x >> 16) - ScreenInfo->center.x;390Music_TransitionTrack(TRACK_MINIBOSS, 0.0125);391EggPistonsMKII->health = 8;392393self->timer = 142;394for (int32 i = 0; i < 2; ++i) {395EntityEggPistonsMKII *barrier = RSDK_GET_ENTITY(SceneInfo->entitySlot + 14 + i, EggPistonsMKII);396barrier->velocity.y = -0x20000;397barrier->timer = 64;398barrier->state = EggPistonsMKII_StateBarrier_Solid;399}400401player1->right = false;402player1->left = true;403self->state = EggPistonsMKII_State_PistonReveal;404#if MANIA_USE_PLUS405}406#endif407}408}409410void EggPistonsMKII_State_PistonReveal(void)411{412RSDK_THIS(EggPistonsMKII);413414EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);415416if (!player1->stateInput && player1->groundVel <= 0) {417player1->groundVel = 0;418player1->velocity.x = 0;419player1->left = false;420player1->direction = FLIP_NONE;421}422423if (--self->timer <= 0) {424player1->stateInput = Player_Input_P1;425426for (int32 i = 0; i < 6; ++i) {427EntityCollapsingPlatform *platform = RSDK_GET_ENTITY(SceneInfo->entitySlot + 8 + i, CollapsingPlatform);428if (platform->classID == CollapsingPlatform->classID) {429platform->active = ACTIVE_NORMAL;430platform->collapseDelay = 8;431platform->stoodPos.x = self->position.x;432}433}434435for (int32 i = 0; i < 2; ++i) {436EntityEggPistonsMKII *piston = RSDK_GET_ENTITY(SceneInfo->entitySlot + 14 + i, EggPistonsMKII);437piston->velocity.y = 0x80000;438piston->timer = 8;439piston->state = EggPistonsMKII_StateBarrier_Solid;440}441442self->position.y -= 0x800000;443self->timer = 120;444self->state = EggPistonsMKII_State_ClassicMode;445}446}447448void EggPistonsMKII_State_ClassicMode(void)449{450RSDK_THIS(EggPistonsMKII);451452if (--self->timer <= 0) {453if (self->pistonID) {454if (EggPistonsMKII->health > 4) {455EggPistonsMKII_SpawnElecBall();456RSDK.PlaySfx(EggPistonsMKII->sfxElectrify, false, 255);457self->timer = 345;458}459else {460self->timer = 120;461self->state = EggPistonsMKII_State_StartPinchMode;462}463}464else {465EggPistonsMKII_GetNextPiston();466EggPistonsMKII_GetNextPiston()->parent = self;467468RSDK.SetSpriteAnimation(EggPistonsMKII->eggmanFrames, 0, &self->mainAnimator, true, 0);469RSDK.SetSpriteAnimation(-1, 0, &self->altAnimator, true, 0);470471self->timer = 165;472RSDK.PlaySfx(EggPistonsMKII->sfxWall, false, 255);473}474self->pistonID ^= 1;475}476477if (EggPistonsMKII->invincibilityTimer)478EggPistonsMKII->invincibilityTimer--;479480self->direction = RSDK_GET_ENTITY(SLOT_PLAYER1, Player)->position.x <= self->position.x;481482RSDK.ProcessAnimation(&self->mainAnimator);483RSDK.ProcessAnimation(&self->altAnimator);484485if (self->visible)486EggPistonsMKII_CheckPlayerCollisions_EggPiston();487}488489void EggPistonsMKII_State_StartPinchMode(void)490{491RSDK_THIS(EggPistonsMKII);492493if (--self->timer <= 0) {494CREATE_ENTITY(EggPistonsMKII, INT_TO_VOID(EGGPISTON_ALARM), self->position.x, self->position.y);495496EntityEggPistonsMKII *orbSpawner = RSDK_GET_ENTITY(SceneInfo->entitySlot + 6, EggPistonsMKII);497RSDK.PlaySfx(EggPistonsMKII->sfxExplosion, false, 255);498CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_ENEMY), orbSpawner->position.x, orbSpawner->position.y)->drawGroup = Zone->objectDrawGroup[1];499500EggPistonsMKII->isPhase2 = true;501destroyEntity(orbSpawner);502503self->timer = 120;504self->pistonID = 1;505RSDK.PlaySfx(EggPistonsMKII->sfxAlarm, true, 255);506self->state = EggPistonsMKII_State_PinchMode;507}508}509510void EggPistonsMKII_State_PinchMode(void)511{512RSDK_THIS(EggPistonsMKII);513514if (--self->timer <= 0) {515EntityEggPistonsMKII *piston = EggPistonsMKII_GetNextPiston();516if (!self->pistonID) {517piston->parent = self;518RSDK.SetSpriteAnimation(EggPistonsMKII->eggmanFrames, 0, &self->mainAnimator, true, 0);519RSDK.SetSpriteAnimation(-1, 0, &self->altAnimator, true, 0);520}521522self->pistonID = (self->pistonID + 1) & 3;523524RSDK.PlaySfx(EggPistonsMKII->sfxWall, false, 255);525self->timer = 64;526}527528if (EggPistonsMKII->invincibilityTimer)529EggPistonsMKII->invincibilityTimer--;530531self->direction = RSDK_GET_ENTITY(SLOT_PLAYER1, Player)->position.x <= self->position.x;532RSDK.ProcessAnimation(&self->mainAnimator);533RSDK.ProcessAnimation(&self->altAnimator);534535if (self->visible)536EggPistonsMKII_CheckPlayerCollisions_EggPiston();537538if (!EggPistonsMKII->health)539self->state = EggPistonsMKII_State_Destroyed;540}541542void EggPistonsMKII_State_Destroyed(void)543{544RSDK_THIS(EggPistonsMKII);545546int32 id = 0;547for (int32 i = 0; i < 5; ++i) {548EntityEggPistonsMKII *piston = EggPistonsMKII->pistons[i];549550if (piston->state == EggPistonsMKII_StatePiston_Idle)551++id;552}553554if (++id >= 5) {555EggPistonsMKII->isPhase2 = false;556Music_TransitionTrack(TRACK_STAGE, 0.0125);557RSDK.StopSfx(EggPistonsMKII->sfxAlarm);558self->state = EggPistonsMKII_State_Finish;559}560}561562void EggPistonsMKII_State_Finish(void) {}563564void EggPistonsMKII_StatePiston_Idle(void) { EggPistonsMKII_CheckPlayerCollisions_Piston(); }565566void EggPistonsMKII_StatePiston_Shaking(void)567{568RSDK_THIS(EggPistonsMKII);569570self->position.y = (RSDK.Rand(-2, 3) << 16) + self->pistonID;571EggPistonsMKII_CheckPlayerCollisions_Piston();572573if (!--self->timer) {574self->position.y = self->pistonID;575self->velocity.y = self->direction == FLIP_NONE ? -0x8000 : 0x8000;576577self->timer = 32;578self->state = EggPistonsMKII_StatePiston_BeginCrushing;579}580581if (!EggPistonsMKII->health) {582self->position.y = self->pistonID;583self->state = EggPistonsMKII_StatePiston_Explode;584585EggPistonsMKII_Explode();586}587}588589void EggPistonsMKII_StatePiston_BeginCrushing(void)590{591RSDK_THIS(EggPistonsMKII);592593EggPistonsMKII_CheckPlayerCollisions_Piston();594if (!--self->timer) {595self->timer = 48;596self->velocity.y = self->direction == FLIP_NONE ? -0x30000 : 0x30000;597self->state = EggPistonsMKII_StatePiston_CrushExtend;598}599600if (!EggPistonsMKII->health) {601self->velocity.y = self->direction == FLIP_NONE ? 0x10000 : -0x10000;602self->timer >>= 1;603self->state = EggPistonsMKII_StatePiston_Explode;604605EggPistonsMKII_Explode();606}607}608609void EggPistonsMKII_StatePiston_CrushExtend(void)610{611RSDK_THIS(EggPistonsMKII);612613EggPistonsMKII_CheckPlayerCollisions_Piston();614615if (!--self->timer) {616self->timer = 80;617self->velocity.y = self->direction == FLIP_NONE ? 0x20000 : -0x20000;618self->state = EggPistonsMKII_StatePiston_Retract;619}620621if (!EggPistonsMKII->health) {622self->state = EggPistonsMKII_StatePiston_Explode;623self->velocity.y = self->direction == FLIP_NONE ? 0x10000 : -0x10000;624self->timer >>= 1;625626EggPistonsMKII_Explode();627}628}629630void EggPistonsMKII_StatePiston_Retract(void)631{632RSDK_THIS(EggPistonsMKII);633634EggPistonsMKII_CheckPlayerCollisions_Piston();635636if (!--self->timer) {637self->velocity.y = 0;638self->parent = NULL;639self->state = EggPistonsMKII_StatePiston_Idle;640}641642if (!EggPistonsMKII->health || (!EggPistonsMKII->isPhase2 && EggPistonsMKII->health == 4)) {643self->state = EggPistonsMKII_StatePiston_Explode;644self->velocity.y = self->direction == FLIP_NONE ? 0x10000 : -0x10000;645646EggPistonsMKII_Explode();647}648}649650void EggPistonsMKII_StatePiston_Explode(void)651{652RSDK_THIS(EggPistonsMKII);653654if ((self->direction || self->position.y < self->pistonID) && (self->direction != FLIP_Y || self->position.y > self->pistonID)) {655EggPistonsMKII_CheckPlayerCollisions_Piston();656657if (!EggPistonsMKII->health || (!EggPistonsMKII->isPhase2 && EggPistonsMKII->health == 4)) {658EggPistonsMKII_Explode();659}660}661else {662self->position.y = self->pistonID;663self->velocity.y = 0;664self->parent = NULL;665self->state = EggPistonsMKII_StatePiston_Idle;666}667}668669void EggPistonsMKII_StateOrbGenerator_Idle(void) {}670671void EggPistonsMKII_StateOrbGenerator_Warning(void)672{673RSDK_THIS(EggPistonsMKII);674675RSDK.ProcessAnimation(&self->mainAnimator);676677if ((self->timer & 7) == 4)678RSDK.PlaySfx(EggPistonsMKII->sfxElectrify, false, 255);679680if (!--self->timer) {681self->mainAnimator.frameID = 0;682self->state = EggPistonsMKII_StateOrbGenerator_Idle;683}684}685686void EggPistonsMKII_StateOrb_MoveToTargetPos(void)687{688RSDK_THIS(EggPistonsMKII);689690if (self->alpha < 0xC0)691self->alpha += 0x10;692693self->position.x += self->velocity.x;694695if (self->position.x <= self->pistonID) {696self->timer = 180;697self->state = EggPistonsMKII_StateOrb_Charging;698}699700RSDK.ProcessAnimation(&self->mainAnimator);701}702703void EggPistonsMKII_StateOrb_Charging(void)704{705RSDK_THIS(EggPistonsMKII);706707if (!--self->timer) {708self->alpha = 0x80;709self->velocity.x = (RSDK_GET_ENTITY(SLOT_PLAYER1, Player)->position.x - self->position.x) >> 7;710self->velocity.y = 0x14000;711self->timer = 133;712713RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 3, &self->altAnimator, true, 0);714self->state = EggPistonsMKII_StateOrb_Attacking;715self->mainAnimator.speed *= 2;716}717718RSDK.ProcessAnimation(&self->mainAnimator);719}720721void EggPistonsMKII_StateOrb_Attacking(void)722{723RSDK_THIS(EggPistonsMKII);724725self->velocity.x = (RSDK_GET_ENTITY(SLOT_PLAYER1, Player)->position.x - self->position.x) >> 7;726self->position.x += self->velocity.x;727self->position.y += self->velocity.y;728729if (!--self->timer)730destroyEntity(self);731732RSDK.ProcessAnimation(&self->mainAnimator);733734EggPistonsMKII_CheckPlayerCollisions_Ball();735}736737void EggPistonsMKII_StateAlarm_Active(void)738{739RSDK_THIS(EggPistonsMKII);740741EggPistonsMKII->alarmTimer = (abs(RSDK.Sin256(2 * EggPistonsMKII->alarmAngle)) >> 1) + 32;742++EggPistonsMKII->alarmAngle;743744if (!EggPistonsMKII->health && !EggPistonsMKII->isPhase2 && EggPistonsMKII->alarmTimer == 32)745self->state = EggPistonsMKII_StateAlarm_Destroyed;746}747748void EggPistonsMKII_StateAlarm_Destroyed(void)749{750RSDK_THIS(EggPistonsMKII);751752if (!--EggPistonsMKII->alarmTimer) {753for (int32 i = 0; i < 2; ++i) {754int32 slot = RSDK.GetEntitySlot(EggPistonsMKII->controller);755EntityEggPistonsMKII *barrier = RSDK_GET_ENTITY(slot + 14 + i, EggPistonsMKII);756757for (int32 d = 0; d < 4; ++d) {758EntityDebris *debris = CREATE_ENTITY(Debris, Debris_State_FallAndFlicker, barrier->position.x, barrier->position.y);759RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 5, &debris->animator, true, i + 1);760debris->gravityStrength = 0x3800;761debris->velocity.x = ((i & 1) << 17 >> (i >> 1)) - 0x10000;762debris->velocity.y = 0x18000 * ((i >> 1) - 2);763debris->drawGroup = Zone->objectDrawGroup[1];764debris->updateRange.x = 0x400000;765debris->updateRange.y = 0x400000;766}767768destroyEntity(barrier);769}770771Zone->cameraBoundsR[0] += WIDE_SCR_XSIZE;772Zone->playerBoundActiveR[0] = false;773774destroyEntity(self);775}776}777778void EggPistonsMKII_StateBarrier_Solid(void)779{780RSDK_THIS(EggPistonsMKII);781782self->position.y += self->velocity.y;783if (--self->timer <= 0) {784self->state = EggPistonsMKII_StateBarrier_Explode;785786if (self->velocity.y == 0x80000) {787RSDK_GET_ENTITY(SLOT_CAMERA1, Camera)->shakePos.y = 4;788self->velocity.y = 0;789}790else if (self->velocity.y == 0x20000) {791self->velocity.y = -0x20000;792self->timer = 32;793self->state = EggPistonsMKII_StateBarrier_Solid;794}795}796797EggPistonsMKII_CheckPlayerCollisions_Solid();798}799800void EggPistonsMKII_StateBarrier_Explode(void)801{802EggPistonsMKII_CheckPlayerCollisions_Solid();803804if (!EggPistonsMKII->health)805EggPistonsMKII_Explode();806}807808#if GAME_INCLUDE_EDITOR809void EggPistonsMKII_EditorDraw(void)810{811RSDK_THIS(EggPistonsMKII);812813self->updateRange.x = 0x800000;814self->updateRange.y = 0x800000;815816switch (self->type) {817case EGGPISTON_PISTON: RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 0, &self->mainAnimator, true, 0); break;818case EGGPISTON_CONTROL: RSDK.SetSpriteAnimation(EggPistonsMKII->eggmanFrames, 0, &self->mainAnimator, true, 0); break;819case EGGPISTON_EMITTER: RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 1, &self->mainAnimator, true, 0); break;820case EGGPISTON_BARRIER: RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 5, &self->mainAnimator, true, 0); break;821case EGGPISTON_PLASMABALL: RSDK.SetSpriteAnimation(EggPistonsMKII->aniFrames, 2, &self->mainAnimator, true, 0); break;822case EGGPISTON_ALARM: RSDK.SetSpriteAnimation(-1, 0, &self->mainAnimator, true, 0); break;823default: break;824}825826RSDK.DrawSprite(&self->mainAnimator, NULL, false);827828if (self->type == EGGPISTON_CONTROL && showGizmos()) {829RSDK_DRAWING_OVERLAY(true);830831DrawHelpers_DrawArenaBounds(-WIDE_SCR_XCENTER, -SCREEN_YSIZE, WIDE_SCR_XCENTER, 71, 1 | 2 | 4 | 8, 0x00C0F0);832833RSDK_DRAWING_OVERLAY(false);834}835}836837void EggPistonsMKII_EditorLoad(void)838{839EggPistonsMKII->aniFrames = RSDK.LoadSpriteAnimation("MMZ/EggPistonsMKII.bin", SCOPE_STAGE);840EggPistonsMKII->eggmanFrames = RSDK.LoadSpriteAnimation("Eggman/EggmanMMZ1.bin", SCOPE_STAGE);841842RSDK_ACTIVE_VAR(EggPistonsMKII, type);843RSDK_ENUM_VAR("Piston", EGGPISTON_PISTON);844RSDK_ENUM_VAR("Control", EGGPISTON_CONTROL);845RSDK_ENUM_VAR("Emitter", EGGPISTON_EMITTER);846RSDK_ENUM_VAR("Barrier", EGGPISTON_BARRIER);847}848#endif849850void EggPistonsMKII_Serialize(void)851{852RSDK_EDITABLE_VAR(EggPistonsMKII, VAR_UINT8, direction);853RSDK_EDITABLE_VAR(EggPistonsMKII, VAR_UINT8, type);854}855856857