Path: blob/master/SonicMania/Objects/PGZ/DoorTrigger.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: DoorTrigger Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectDoorTrigger *DoorTrigger;1011void DoorTrigger_Update(void)12{13RSDK_THIS(DoorTrigger);1415RSDK.ProcessAnimation(&self->baseAnimator);1617if (self->bulbAnimator.frameID) {18if (!--self->id) {19self->id = RSDK.Rand(15, 121);2021int32 anim = 0;22switch (self->orientation) {23case DOORTRIGGER_ORIENATION_L:24case DOORTRIGGER_ORIENATION_R: anim = 3; break;2526case DOORTRIGGER_ORIENATION_U:27case DOORTRIGGER_ORIENATION_D: anim = 4; break;2829default: break;30}3132int32 x = self->position.x + (RSDK.Rand(-4, 5) << 16);33int32 y = self->position.y + (RSDK.Rand(-4, 5) << 16);34EntityDebris *shard = CREATE_ENTITY(Debris, NULL, x, y);3536shard->state = Debris_State_Move;37shard->drawFX = FX_FLIP;38shard->direction = self->direction;39shard->drawGroup = Zone->objectDrawGroup[1] - 1;40RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, anim, &shard->animator, true, 0);41}42}43else {44foreach_active(Player, player)45{46if (!player->sidekick && Player_CheckAttackingNoInvTimer(player, self)) {47if (Player_CheckCollisionTouch(player, self, &DoorTrigger->hitboxBulb[self->baseAnimator.frameID])) {48self->bulbAnimator.frameID = 1;49if (player->characterID == ID_KNUCKLES && player->animator.animationID == ANI_GLIDE) {50player->velocity.x = -player->velocity.x >> 1;51RSDK.SetSpriteAnimation(player->aniFrames, ANI_GLIDE_DROP, &player->animator, false, 0);52player->state = Player_State_KnuxGlideDrop;53}54else {55int32 x = 0, y = 0;56if (self->baseAnimator.frameID) {57x = player->position.x - self->position.x;5859if (self->direction)60y = (player->position.y - self->position.y) - 0xE0000;61else62y = (player->position.y - self->position.y) + 0xE0000;63}64else {65if (self->direction)66x = (player->position.x - self->position.x) - 0xE0000;67else68x = (player->position.x - self->position.x) + 0xE0000;6970y = player->position.y - self->position.y;71}7273int32 angle = RSDK.ATan2(x, y);74#if MANIA_USE_PLUS75if (player->characterID == ID_MIGHTY && player->animator.animationID == ANI_HAMMERDROP) {76player->velocity.y -= 0x10000;77}78else {79#endif80player->velocity.x = 0x300 * RSDK.Cos256(angle);81player->groundVel = 0x300 * RSDK.Cos256(angle);82player->velocity.y = 0x300 * RSDK.Sin256(angle);83#if MANIA_USE_PLUS84}85#endif8687player->applyJumpCap = false;88player->onGround = false;89}9091RSDK.PlaySfx(DoorTrigger->sfxShatter, false, 255);9293int32 spawnX = self->position.x;94int32 spawnY = self->position.y;95switch (self->orientation) {96case DOORTRIGGER_ORIENATION_L: spawnX -= 0x100000; break;97case DOORTRIGGER_ORIENATION_R: spawnX += 0x100000; break;98case DOORTRIGGER_ORIENATION_U: spawnY -= 0x100000; break;99case DOORTRIGGER_ORIENATION_D: spawnY += 0x100000; break;100default: break;101}102103for (int32 i = 0; i < 8; ++i) {104EntityDebris *shard =105CREATE_ENTITY(Debris, NULL, spawnX + RSDK.Rand(-0xA0000, 0xA0000), spawnY + RSDK.Rand(-0xA0000, 0xA0000));106shard->state = Debris_State_Fall;107shard->gravityStrength = 0x4000;108shard->velocity.x = RSDK.Rand(0, 0x20000);109if (shard->position.x < self->position.x)110shard->velocity.x = -shard->velocity.x;111shard->velocity.y = RSDK.Rand(-0x40000, -0x10000);112shard->drawFX = FX_FLIP;113shard->direction = i & 3;114shard->drawGroup = Zone->objectDrawGroup[1];115RSDK.SetSpriteAnimation(ItemBox->aniFrames, 6, &shard->animator, true, RSDK.Rand(0, 4));116}117118CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_ENEMY), spawnX, spawnY)->drawGroup = Zone->objectDrawGroup[1];119}120}121else {122Player_CheckCollisionBox(player, self, &DoorTrigger->hitboxBulb[self->baseAnimator.frameID]);123}124}125}126}127128void DoorTrigger_LateUpdate(void) {}129130void DoorTrigger_StaticUpdate(void) {}131132void DoorTrigger_Draw(void)133{134RSDK_THIS(DoorTrigger);135136RSDK.DrawSprite(&self->baseAnimator, NULL, false);137RSDK.DrawSprite(&self->bulbAnimator, NULL, false);138139if (!self->bulbAnimator.frameID && !(Zone->timer & 1)) {140self->inkEffect = INK_ADD;141self->bulbAnimator.frameID = 2;142self->alpha = 0xB8 + ((56 * RSDK.Sin256(Zone->timer)) >> 8);143RSDK.DrawSprite(&self->bulbAnimator, NULL, false);144145self->bulbAnimator.frameID = 3;146RSDK.DrawSprite(&self->bulbAnimator, NULL, false);147148self->bulbAnimator.frameID = 0;149self->inkEffect = INK_NONE;150}151}152153void DoorTrigger_Create(void *data)154{155RSDK_THIS(DoorTrigger);156157self->drawFX = FX_FLIP;158159if (!SceneInfo->inEditor) {160self->active = ACTIVE_BOUNDS;161self->visible = true;162self->drawGroup = Zone->objectDrawGroup[1];163self->updateRange.y = 0x800000;164self->updateRange.x = 0x800000;165RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, 0, &self->baseAnimator, true, 0);166167self->direction = self->orientation & 1;168if (self->orientation < DOORTRIGGER_ORIENATION_U) {169RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, 1, &self->bulbAnimator, true, 0);170}171else {172self->baseAnimator.frameID = 1;173self->direction *= FLIP_Y;174RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, 2, &self->bulbAnimator, true, 0);175}176}177}178179void DoorTrigger_StageLoad(void)180{181if (RSDK.CheckSceneFolder("PSZ1"))182DoorTrigger->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/DoorTrigger.bin", SCOPE_STAGE);183184// Active185DoorTrigger->hitboxBulb[0].top = -10;186DoorTrigger->hitboxBulb[0].left = -26;187DoorTrigger->hitboxBulb[0].bottom = 10;188DoorTrigger->hitboxBulb[0].right = 0;189190// Busted191DoorTrigger->hitboxBulb[1].top = -26;192DoorTrigger->hitboxBulb[1].left = -10;193DoorTrigger->hitboxBulb[1].bottom = 0;194DoorTrigger->hitboxBulb[1].right = 10;195196DoorTrigger->sfxShatter = RSDK.GetSfx("Stage/WindowShatter.wav");197}198199#if GAME_INCLUDE_EDITOR200void DoorTrigger_EditorDraw(void)201{202RSDK_THIS(DoorTrigger);203204self->active = ACTIVE_BOUNDS;205self->visible = true;206self->drawGroup = Zone->objectDrawGroup[1];207self->updateRange.y = 0x800000;208self->updateRange.x = 0x800000;209RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, 0, &self->baseAnimator, true, 0);210211self->direction = self->orientation & 1;212if (self->orientation < DOORTRIGGER_ORIENATION_U) {213RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, 1, &self->bulbAnimator, true, 0);214}215else {216self->baseAnimator.frameID = 1;217self->direction *= FLIP_Y;218RSDK.SetSpriteAnimation(DoorTrigger->aniFrames, 2, &self->bulbAnimator, true, 0);219}220221DoorTrigger_Draw();222}223224void DoorTrigger_EditorLoad(void)225{226DoorTrigger->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/DoorTrigger.bin", SCOPE_STAGE);227228RSDK_ACTIVE_VAR(DoorTrigger, orientation);229RSDK_ENUM_VAR("Left", DOORTRIGGER_ORIENATION_L);230RSDK_ENUM_VAR("Right", DOORTRIGGER_ORIENATION_R);231RSDK_ENUM_VAR("Up", DOORTRIGGER_ORIENATION_U);232RSDK_ENUM_VAR("Down", DOORTRIGGER_ORIENATION_D);233}234#endif235236void DoorTrigger_Serialize(void)237{238RSDK_EDITABLE_VAR(DoorTrigger, VAR_UINT8, orientation);239RSDK_EDITABLE_VAR(DoorTrigger, VAR_UINT8, id);240}241242243