Path: blob/master/SonicMania/Objects/SPZ/DirectorChair.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: DirectorChair Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectDirectorChair *DirectorChair;1011void DirectorChair_Update(void) { Platform_Update(); }1213void DirectorChair_LateUpdate(void) {}1415void DirectorChair_StaticUpdate(void) {}1617void DirectorChair_Draw(void)18{19RSDK_THIS(DirectorChair);2021Vector2 drawPos;22int32 sin = RSDK.Sin512(self->rotation);2324drawPos = self->centerPos;25self->animator.frameID = 2;26RSDK.DrawSprite(&self->animator, &self->drawPos, false);2728self->animator.frameID = 1;29RSDK.DrawSprite(&self->animator, &self->drawPos, false);3031self->animator.frameID = 0;32RSDK.DrawSprite(&self->animator, &self->drawPos, false);33RSDK.DrawSprite(&self->animator, &self->centerPos, false);3435drawPos.x += -0x10000 - (RSDK.Cos512(self->rotation) << 11);36RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);3738self->direction = FLIP_X;39self->rotation = 0x100 - self->rotation;40drawPos.y += sin << 12;41RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);4243self->direction = FLIP_NONE;44self->rotation = 0x100 - self->rotation;4546for (int32 i = 0; i < self->size; ++i) {47RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);4849self->direction = FLIP_X;50self->rotation = 0x100 - self->rotation;51drawPos.y += sin << 12;52RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);5354self->direction = FLIP_NONE;55self->rotation = 0x100 - self->rotation;56}57}5859void DirectorChair_Create(void *data)60{61RSDK_THIS(DirectorChair);6263RSDK.SetSpriteAnimation(DirectorChair->aniFrames, 0, &self->scissorAnimator, true, 0);64RSDK.SetSpriteAnimation(DirectorChair->aniFrames, 1, &self->animator, true, 0);6566if (!SceneInfo->inEditor) {67self->centerPos = self->position;68self->drawPos = self->position;69self->active = ACTIVE_BOUNDS;70self->visible = true;71self->drawFX = FX_ROTATE | FX_FLIP;72self->updateRange.x = 0x800000;73self->updateRange.y = ((RSDK.Sin512(96) + 0x8000) << 8) + (RSDK.Sin512(96) << 12) * (self->size + 1);74self->drawGroup = Zone->objectDrawGroup[0];75self->minRetract = (self->size >> 2) - 16;76self->rotation = self->type == DIRECTORCHAIR_CLOSED ? self->minRetract : -96;77self->angle = self->rotation << 8;78self->state = DirectorChair_State_Idle;79self->stateCollide = DirectorChair_Collide_Chair;80self->speed <<= 7;81self->initExtendVel = MAX(32 - 2 * self->size, 1);82}83}8485void DirectorChair_StageLoad(void)86{87if (RSDK.CheckSceneFolder("SPZ1"))88DirectorChair->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/DirectorChair.bin", SCOPE_STAGE);8990DirectorChair->hitboxChair.top = -18;91DirectorChair->hitboxChair.left = -18;92DirectorChair->hitboxChair.right = 18;93DirectorChair->hitboxChair.bottom = -4;9495DirectorChair->hitboxL.top = -35;96DirectorChair->hitboxL.left = -24;97DirectorChair->hitboxL.right = -16;98DirectorChair->hitboxL.bottom = -3;99100DirectorChair->hitboxR.top = -35;101DirectorChair->hitboxR.left = 16;102DirectorChair->hitboxR.right = 24;103DirectorChair->hitboxR.bottom = -3;104105DirectorChair->extendCount = 0;106DirectorChair->retractCount = 0;107108DirectorChair->sfxUnravel = RSDK.GetSfx("Stage/Unravel.wav");109DirectorChair->sfxExtend = RSDK.GetSfx("Stage/Extend.wav");110DirectorChair->sfxRetract = RSDK.GetSfx("Stage/Retract.wav");111}112113void DirectorChair_Collide_Chair(void)114{115RSDK_THIS(DirectorChair);116117int32 playerID = 0;118self->stoodPlayers = 0;119120foreach_active(Player, player)121{122bool32 prevOnGround = player->onGround;123if (Player_CheckCollisionPlatform(player, self, &DirectorChair->hitboxChair)) {124#if MANIA_USE_PLUS125if (self->state == DirectorChair_State_Idle && player->state == Player_State_MightyHammerDrop)126player->state = Player_State_Air;127#endif128self->timer = 0;129if (!prevOnGround) {130self->stoodPlayers |= 1 << playerID;131self->stood = true;132player->position.x += self->collisionOffset.x;133player->position.y += self->collisionOffset.y;134player->position.y &= 0xFFFF0000;135}136}137138if (Player_CheckCollisionBox(player, self, &DirectorChair->hitboxL) == C_TOP) {139self->timer = 0;140if (!prevOnGround) {141self->stoodPlayers |= 1 << playerID;142player->position.x += self->collisionOffset.x;143player->position.y += self->collisionOffset.y;144player->position.y &= 0xFFFF0000;145}146}147148if (Player_CheckCollisionBox(player, self, &DirectorChair->hitboxR) == C_TOP) {149self->timer = 0;150if (!prevOnGround) {151self->stoodPlayers |= 1 << playerID;152player->position.x += self->collisionOffset.x;153player->position.y += self->collisionOffset.y;154player->position.y &= 0xFFFF0000;155}156}157158// Extend Hitbox159Hitbox hitbox;160hitbox.right = (RSDK.Cos512(self->rotation) >> 5) + 8;161hitbox.bottom = (self->centerPos.y - self->drawPos.y) >> 16;162hitbox.left = -hitbox.right;163hitbox.top = 0;164Player_CheckCollisionBox(player, self, &hitbox);165166++playerID;167}168}169170void DirectorChair_State_Idle(void)171{172RSDK_THIS(DirectorChair);173174int32 sin = RSDK.Sin512(self->rotation);175self->drawPos.x = self->centerPos.x;176self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);177178if (self->stood) {179self->active = ACTIVE_NORMAL;180self->extendVel = 512;181if (self->type == DIRECTORCHAIR_CLOSED) {182RSDK.PlaySfx(DirectorChair->sfxUnravel, false, 0xFF);183self->state = DirectorChair_State_StartExtend;184}185else {186++DirectorChair->retractCount;187RSDK.PlaySfx(DirectorChair->sfxRetract, false, 0xFF);188self->state = DirectorChair_State_Retract;189}190}191}192193void DirectorChair_State_StartExtend(void)194{195RSDK_THIS(DirectorChair);196197self->angle += self->extendVel;198self->extendVel -= self->initExtendVel;199self->rotation = self->angle >> 8;200201if (self->rotation >= 0) {202self->rotation = 0;203self->angle = 0;204self->extendVel = -self->initExtendVel;205++DirectorChair->extendCount;206RSDK.PlaySfx(DirectorChair->sfxExtend, false, 0xFF);207self->state = DirectorChair_State_Extend;208}209210int32 sin = RSDK.Sin512(self->rotation);211self->drawPos.x = self->centerPos.x;212self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);213}214215void DirectorChair_State_Extend(void)216{217RSDK_THIS(DirectorChair);218219self->angle -= self->extendVel;220if (self->extendVel != self->speed) {221if (self->extendVel >= self->speed) {222self->speed -= 32;223if (self->extendVel < self->speed)224self->extendVel = self->speed;225}226else {227self->extendVel += 0x20;228if (self->extendVel > self->speed)229self->extendVel = self->speed;230}231}232233self->rotation = self->angle >> 8;234if (self->rotation <= -96) {235self->rotation = -96;236237if (!--DirectorChair->extendCount)238RSDK.StopSfx(DirectorChair->sfxExtend);239240if (self->type == DIRECTORCHAIR_CLOSED) {241self->state = DirectorChair_State_StartRetract;242}243else {244self->active = ACTIVE_BOUNDS;245self->state = DirectorChair_State_Idle;246}247}248249int32 sin = RSDK.Sin512(self->rotation);250self->drawPos.x = self->centerPos.x;251self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);252}253254void DirectorChair_State_StartRetract(void)255{256RSDK_THIS(DirectorChair);257258if (++self->timer >= 60) {259self->timer = 0;260self->extendVel = 0;261262if (self->type == DIRECTORCHAIR_CLOSED) {263++DirectorChair->retractCount;264RSDK.PlaySfx(DirectorChair->sfxRetract, false, 0xFF);265self->state = DirectorChair_State_Retract;266}267else {268++DirectorChair->extendCount;269RSDK.PlaySfx(DirectorChair->sfxExtend, false, 0xFF);270self->state = DirectorChair_State_Extend;271}272}273274int32 sin = RSDK.Sin512(self->rotation);275self->drawPos.x = self->centerPos.x;276self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);277}278279void DirectorChair_State_Retract(void)280{281RSDK_THIS(DirectorChair);282283self->angle += self->extendVel;284285if (self->extendVel != self->speed) {286if (self->extendVel >= self->speed) {287self->extendVel -= 32;288if (self->extendVel < self->speed)289self->extendVel = self->speed;290}291else {292self->extendVel += 0x20;293if (self->extendVel > self->speed)294self->extendVel = self->speed;295}296}297298self->rotation = self->angle >> 8;299if (self->rotation >= self->minRetract) {300if (!--DirectorChair->retractCount)301RSDK.StopSfx(DirectorChair->sfxRetract);302303self->rotation = self->minRetract;304if (self->type == DIRECTORCHAIR_CLOSED) {305self->active = ACTIVE_BOUNDS;306self->state = DirectorChair_State_Idle;307}308else {309self->state = DirectorChair_State_StartRetract;310}311}312313int32 sin = RSDK.Sin512(self->rotation);314self->drawPos.x = self->centerPos.x;315self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);316}317318#if GAME_INCLUDE_EDITOR319void DirectorChair_EditorDraw(void)320{321RSDK_THIS(DirectorChair);322323self->centerPos = self->position;324self->drawPos = self->position;325self->active = ACTIVE_BOUNDS;326self->visible = true;327self->drawFX = FX_ROTATE | FX_FLIP;328self->updateRange.x = 0x800000;329self->updateRange.y = ((RSDK.Sin512(96) + 0x8000) << 8) + (RSDK.Sin512(96) << 12) * (self->size + 1);330self->drawGroup = Zone->objectDrawGroup[0];331self->minRetract = (self->size >> 2) - 16;332self->rotation = self->type == DIRECTORCHAIR_CLOSED ? self->minRetract : -96;333self->angle = self->rotation << 8;334self->initExtendVel = MAX(32 - 2 * self->size, 1);335336int32 sin = RSDK.Sin512(self->rotation);337self->drawPos.x = self->centerPos.x;338self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);339340DirectorChair_Draw();341342if (showGizmos()) {343RSDK_DRAWING_OVERLAY(true);344345self->rotation = self->type != DIRECTORCHAIR_CLOSED ? self->minRetract : -96;346self->angle = self->rotation << 8;347self->initExtendVel = MAX(32 - 2 * self->size, 1);348349self->drawPos.x = self->centerPos.x;350self->drawPos.y = self->centerPos.y + (RSDK.Sin512(self->rotation) << 8) + (RSDK.Sin512(self->rotation) << 12) * (self->size + 1);351352self->inkEffect = INK_BLEND;353DirectorChair_Draw();354self->inkEffect = INK_NONE;355356RSDK_DRAWING_OVERLAY(false);357}358}359360void DirectorChair_EditorLoad(void)361{362DirectorChair->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/DirectorChair.bin", SCOPE_STAGE);363364RSDK_ACTIVE_VAR(DirectorChair, type);365RSDK_ENUM_VAR("Closed", DIRECTORCHAIR_CLOSED);366RSDK_ENUM_VAR("Stretched Out", DIRECTORCHAIR_STRETCHED);367}368#endif369370void DirectorChair_Serialize(void)371{372RSDK_EDITABLE_VAR(DirectorChair, VAR_ENUM, type);373RSDK_EDITABLE_VAR(DirectorChair, VAR_ENUM, speed);374RSDK_EDITABLE_VAR(DirectorChair, VAR_ENUM, size);375}376377378