Path: blob/master/SonicMania/Objects/TMZ/FlasherMKII.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: FlasherMKII Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectFlasherMKII *FlasherMKII;1011void FlasherMKII_Update(void)12{13RSDK_THIS(FlasherMKII);1415RSDK.ProcessAnimation(&self->animator);1617StateMachine_Run(self->state);18}1920void FlasherMKII_LateUpdate(void) {}2122void FlasherMKII_StaticUpdate(void) {}2324void FlasherMKII_Draw(void)25{26RSDK_THIS(FlasherMKII);2728RSDK.DrawSprite(&self->animator, NULL, false);29}3031void FlasherMKII_Create(void *data)32{33RSDK_THIS(FlasherMKII);3435self->drawFX |= FX_FLIP;36if (!SceneInfo->inEditor) {37self->active = ACTIVE_BOUNDS;38self->updateRange.x = 0x800000;39self->updateRange.y = 0x800000;40self->visible = true;41self->drawGroup = Zone->objectDrawGroup[0];42self->startPos = self->position;4344switch (self->orientation) {45case FLASHERMKII_ORIENTATION_UP:46self->type = 0;47self->direction = FLIP_NONE;48break;4950case FLASHERMKII_ORIENTATION_DOWN:51self->type = 0;52self->direction = FLIP_Y;53break;5455case FLASHERMKII_ORIENTATION_RIGHT:56self->direction = FLIP_NONE;57self->type = 4;58break;5960case FLASHERMKII_ORIENTATION_LEFT:61self->direction = FLIP_X;62self->type = 4;63break;6465default: break;66}6768RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type, &self->animator, true, 0);69self->state = FlasherMKII_State_Idle;70}71}7273void FlasherMKII_StageLoad(void)74{75if (RSDK.CheckSceneFolder("TMZ1") || RSDK.CheckSceneFolder("TMZ2"))76FlasherMKII->aniFrames = RSDK.LoadSpriteAnimation("TMZ1/FlasherMKII.bin", SCOPE_STAGE);7778DEBUGMODE_ADD_OBJ(FlasherMKII);7980FlasherMKII->sfxFlop = RSDK.GetSfx("TMZ1/FlasherFlop.wav");81FlasherMKII->sfxZap = RSDK.GetSfx("TMZ1/FlasherZap.wav");82}8384void FlasherMKII_DebugSpawn(void)85{86RSDK_THIS(FlasherMKII);8788CREATE_ENTITY(FlasherMKII, NULL, self->position.x, self->position.y);89}9091void FlasherMKII_DebugDraw(void)92{93RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, 0, &DebugMode->animator, true, 0);94RSDK.DrawSprite(&DebugMode->animator, NULL, false);95}9697void FlasherMKII_CheckOffScreen(void)98{99RSDK_THIS(FlasherMKII);100101if (!RSDK.CheckOnScreen(self, NULL) && !RSDK.CheckPosOnScreen(&self->startPos, &self->updateRange))102FlasherMKII_Create(NULL);103}104105void FlasherMKII_HandlePlayerCollisions(void)106{107RSDK_THIS(FlasherMKII);108109foreach_active(Player, player)110{111Hitbox *hitbox = RSDK.GetHitbox(&self->animator, 0);112113if (Player_CheckBadnikTouch(player, self, hitbox)) {114if ((self->animator.animationID & 3) == 3) {115if (player->shield == SHIELD_LIGHTNING || player->invincibleTimer || player->blinkTimer) {116if (Player_CheckBadnikBreak(player, self, true))117RSDK.StopSfx(FlasherMKII->sfxZap);118}119else {120Player_Hurt(player, self);121}122}123else {124Player_CheckBadnikBreak(player, self, true);125}126}127}128}129130void FlasherMKII_HandleHarmPlayerCollisions(void)131{132RSDK_THIS(FlasherMKII);133134foreach_active(Player, player)135{136if (player->shield == SHIELD_LIGHTNING || player->invincibleTimer || player->blinkTimer) {137Hitbox *hitbox = RSDK.GetHitbox(&self->animator, 0);138if (Player_CheckBadnikTouch(player, self, hitbox) && Player_CheckBadnikBreak(player, self, true))139RSDK.StopSfx(FlasherMKII->sfxZap);140}141else {142Hitbox *hitbox = RSDK.GetHitbox(&self->animator, 1);143if (Player_CheckCollisionTouch(player, self, hitbox))144Player_Hurt(player, self);145}146}147}148149void FlasherMKII_State_Idle(void)150{151RSDK_THIS(FlasherMKII);152153self->active = ACTIVE_NORMAL;154if (self->timer > 0)155self->timer--;156157EntityPlayer *player = Player_GetNearestPlayer();158if (player) {159int32 rx = (self->position.x - player->position.x) >> 16;160int32 ry = (self->position.y - player->position.y) >> 16;161162if (!self->timer && rx * rx + ry * ry < 0x1000) {163RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 2, &self->animator, false, 0);164RSDK.PlaySfx(FlasherMKII->sfxZap, false, 255);165self->state = FlasherMKII_State_WeakFlash;166}167else {168switch (self->orientation) {169case FLASHERMKII_ORIENTATION_UP:170if (player->position.x >= self->position.x) {171if ((uint32)(rx + 0xFF) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0x600000, 0xC0000, 2)) {172RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);173self->direction = FLIP_X;174self->velocity.x = 0x220000;175self->state = FlasherMKII_State_Moving;176break;177}178}179else if ((uint32)(rx - 65) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, -0x600000, 0xC0000, 2)) {180RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);181self->direction = FLIP_NONE;182self->velocity.x = -0x220000;183self->state = FlasherMKII_State_Moving;184break;185}186break;187188case FLASHERMKII_ORIENTATION_DOWN:189if (player->position.x >= self->position.x) {190if ((uint32)(rx + 0xFF) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_ROOF, 0, 0x600000, -0xC0000, 2)) {191RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);192self->velocity.x = 0x220000;193self->direction = FLIP_XY;194self->state = FlasherMKII_State_Moving;195break;196}197}198else if ((uint32)(rx - 65) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_ROOF, 0, -0x600000, -0xC0000, 2)) {199RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);200self->direction = FLIP_Y;201self->velocity.x = -0x220000;202self->state = FlasherMKII_State_Moving;203break;204}205break;206207case FLASHERMKII_ORIENTATION_RIGHT:208if (player->position.y >= self->position.y) {209if ((uint32)(ry + 0xFF) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_RWALL, 0, -0xC0000, 0x600000, 2)) {210RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);211self->direction = FLIP_Y;212self->velocity.y = 0x220000;213self->state = FlasherMKII_State_Moving;214break;215}216}217else if ((uint32)(ry - 65) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_RWALL, 0, -0xC0000, -0x600000, 2)) {218RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);219self->direction = FLIP_NONE;220self->velocity.y = -0x220000;221self->state = FlasherMKII_State_Moving;222break;223}224break;225226case FLASHERMKII_ORIENTATION_LEFT:227if (player->position.y >= self->position.y) {228if ((uint32)(ry + 0xFF) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_LWALL, 0, 0xC0000, 0x600000, 2)) {229RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);230self->velocity.y = 0x220000;231self->direction = FLIP_XY;232self->state = FlasherMKII_State_Moving;233break;234}235}236else if ((uint32)(ry - 65) <= 0xBE && RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_LWALL, 0, 0xC0000, -0x600000, 2)) {237RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 1, &self->animator, false, 0);238self->direction = FLIP_X;239self->velocity.y = -0x220000;240self->state = FlasherMKII_State_Moving;241break;242}243break;244245default: break;246}247}248}249250FlasherMKII_HandlePlayerCollisions();251FlasherMKII_CheckOffScreen();252}253254void FlasherMKII_State_Moving(void)255{256RSDK_THIS(FlasherMKII);257258if ((self->animator.frameID == 5 || self->animator.frameID == 12) && self->animator.timer == 1) {259self->position.x += self->velocity.x;260self->position.y += self->velocity.y;261262if (self->onScreen == 1)263RSDK.PlaySfx(FlasherMKII->sfxFlop, false, 255);264}265266if (self->animator.frameID == self->animator.frameCount - 1) {267RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type, &self->animator, false, 0);268self->state = FlasherMKII_State_Idle;269}270271FlasherMKII_HandlePlayerCollisions();272FlasherMKII_CheckOffScreen();273}274275void FlasherMKII_State_WeakFlash(void)276{277RSDK_THIS(FlasherMKII);278279if (++self->timer == 60) {280self->timer = 0;281RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 3, &self->animator, false, 0);282self->state = FlasherMKII_State_StrongFlash;283}284285FlasherMKII_HandlePlayerCollisions();286FlasherMKII_CheckOffScreen();287}288289void FlasherMKII_State_StrongFlash(void)290{291RSDK_THIS(FlasherMKII);292293if (++self->timer == 120) {294self->timer = 0;295RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type + 2, &self->animator, false, 0);296self->state = FlasherMKII_State_FinishedFlashing;297}298299FlasherMKII_HandleHarmPlayerCollisions();300FlasherMKII_CheckOffScreen();301}302303void FlasherMKII_State_FinishedFlashing(void)304{305RSDK_THIS(FlasherMKII);306307if (++self->timer == 30) {308RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type, &self->animator, false, 0);309self->state = FlasherMKII_State_Idle;310}311312FlasherMKII_HandlePlayerCollisions();313FlasherMKII_CheckOffScreen();314}315316#if GAME_INCLUDE_EDITOR317void FlasherMKII_EditorDraw(void)318{319RSDK_THIS(FlasherMKII);320321self->startPos = self->position;322323switch (self->orientation) {324case FLASHERMKII_ORIENTATION_UP:325self->type = 0;326self->direction = FLIP_NONE;327break;328329case FLASHERMKII_ORIENTATION_DOWN:330self->type = 0;331self->direction = FLIP_Y;332break;333334case FLASHERMKII_ORIENTATION_RIGHT:335self->direction = FLIP_NONE;336self->type = 4;337break;338339case FLASHERMKII_ORIENTATION_LEFT:340self->direction = FLIP_X;341self->type = 4;342break;343344default: break;345}346347RSDK.SetSpriteAnimation(FlasherMKII->aniFrames, self->type, &self->animator, true, 0);348349FlasherMKII_Draw();350}351352void FlasherMKII_EditorLoad(void)353{354FlasherMKII->aniFrames = RSDK.LoadSpriteAnimation("TMZ1/FlasherMKII.bin", SCOPE_STAGE);355356RSDK_ACTIVE_VAR(FlasherMKII, orientation);357RSDK_ENUM_VAR("Up", FLASHERMKII_ORIENTATION_UP);358RSDK_ENUM_VAR("Down", FLASHERMKII_ORIENTATION_DOWN);359RSDK_ENUM_VAR("Right", FLASHERMKII_ORIENTATION_RIGHT);360RSDK_ENUM_VAR("Left", FLASHERMKII_ORIENTATION_LEFT);361}362#endif363364void FlasherMKII_Serialize(void) { RSDK_EDITABLE_VAR(FlasherMKII, VAR_UINT8, orientation); }365366367