Path: blob/master/SonicMania/Objects/OOZ/PullSwitch.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PullSwitch Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPullSwitch *PullSwitch;1011void PullSwitch_Update(void)12{13RSDK_THIS(PullSwitch);1415if (!self->activated) {16if (self->pullPos > 0) {17self->position.y -= 0x20000;18self->pullPos -= 0x20000;19}20}21else if (self->pullPos < 0x300000) {22self->position.y += 0x20000;23self->pullPos += 0x20000;24}25else {26if (OOZSetup->smogTimer > 16 || Smog->forceEnabled)27RSDK.PlaySfx(PullSwitch->sfxSmogClear, false, 0xFF);2829OOZSetup->smogTimer = 0;30Smog->forceEnabled = false;31}3233self->activated = false;34foreach_active(Player, player)35{36int32 playerID = RSDK.GetEntitySlot(player);37Hitbox *playerHitbox = Player_GetHitbox(player);3839if (self->playerTimers[playerID]) {40self->playerTimers[playerID]--;41}42else if (((1 << playerID) & self->activePlayers)) {43player->position.x = self->position.x;44player->position.y = self->position.y - (playerHitbox->top << 16) + 0x1A0000;45self->activated = true;4647if (player->state == Player_State_Static) {48if (player->jumpPress) {49self->activePlayers &= ~(1 << playerID);50self->playerTimers[playerID] = 60;51player->velocity.y = -0x40000;52player->onGround = false;53player->groundedStore = false;54player->jumpAbilityState = 1;55RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);56player->animator.speed = 48;57player->state = Player_State_Air;58}59}60else {61self->activePlayers &= ~(1 << playerID);62self->playerTimers[playerID] = 60;63}64}65else {66if (Player_CheckCollisionTouch(player, self, &PullSwitch->hitbox) && player->velocity.y >= 0) {67self->activePlayers |= 1 << playerID;68player->state = Player_State_Static;69player->nextGroundState = StateMachine_None;70player->nextAirState = StateMachine_None;71RSDK.SetSpriteAnimation(player->aniFrames, ANI_HANG, &player->animator, false, 0);7273player->velocity.x = 0;74player->velocity.y = 0;75player->groundVel = 0;76player->controlLock = 0;77player->position.x = self->position.x;78player->position.y = self->position.y - (playerHitbox->top << 16) + 0x1A0000;79self->activated = true;80}81}82}83}8485void PullSwitch_LateUpdate(void) {}8687void PullSwitch_StaticUpdate(void) {}8889void PullSwitch_Draw(void)90{91RSDK_THIS(PullSwitch);9293SpriteFrame *frame = RSDK.GetFrame(PullSwitch->aniFrames, 0, 1);9495frame->height = (self->position.y - self->handlePos.y) >> 16;96frame->sprY = self->sprY + self->sprHeight - frame->height;97RSDK.DrawSprite(&self->chainAnimator, &self->handlePos, false);98RSDK.DrawSprite(&self->handleAnimator, NULL, false);99RSDK.DrawSprite(&self->dispenserAnimator, &self->handlePos, false);100}101102void PullSwitch_Create(void *data)103{104RSDK_THIS(PullSwitch);105106self->drawFX = FX_FLIP;107if (!SceneInfo->inEditor) {108self->active = ACTIVE_BOUNDS;109self->visible = true;110self->drawFX = FX_FLIP;111self->drawGroup = Zone->objectDrawGroup[0];112self->handlePos = self->position;113self->updateRange.x = 0x800000;114self->updateRange.y = 0x800000;115116RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->handleAnimator, true, 2);117RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->dispenserAnimator, true, 0);118RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->chainAnimator, true, 1);119120SpriteFrame *frame = RSDK.GetFrame(PullSwitch->aniFrames, 0, 1);121self->sprY = frame->sprY;122self->sprHeight = frame->height;123}124}125126void PullSwitch_StageLoad(void)127{128if (RSDK.CheckSceneFolder("OOZ1") || RSDK.CheckSceneFolder("OOZ2"))129PullSwitch->aniFrames = RSDK.LoadSpriteAnimation("OOZ/PullSwitch.bin", SCOPE_STAGE);130131PullSwitch->hitbox.left = -16;132PullSwitch->hitbox.top = 20;133PullSwitch->hitbox.right = 16;134PullSwitch->hitbox.bottom = 28;135136PullSwitch->sfxButton = RSDK.GetSfx("Stage/Button.wav");137PullSwitch->sfxSmogClear = RSDK.GetSfx("OOZ/SmogClear.wav");138}139140#if GAME_INCLUDE_EDITOR141void PullSwitch_EditorDraw(void)142{143RSDK_THIS(PullSwitch);144145self->handlePos = self->position;146147RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->handleAnimator, false, 2);148RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->dispenserAnimator, false, 0);149RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->chainAnimator, false, 1);150151RSDK.DrawSprite(&self->chainAnimator, &self->handlePos, false);152RSDK.DrawSprite(&self->dispenserAnimator, &self->handlePos, false);153154self->handlePos.y += 0x300000;155RSDK.DrawSprite(&self->handleAnimator, &self->handlePos, false);156}157158void PullSwitch_EditorLoad(void) { PullSwitch->aniFrames = RSDK.LoadSpriteAnimation("OOZ/PullSwitch.bin", SCOPE_STAGE); }159#endif160161void PullSwitch_Serialize(void) {}162163164