Path: blob/master/SonicMania/Objects/CPZ/RotatingStair.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: RotatingStair Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectRotatingStair *RotatingStair;1011void RotatingStair_Update(void) { Platform_Update(); }1213void RotatingStair_LateUpdate(void) {}1415void RotatingStair_StaticUpdate(void) {}1617void RotatingStair_Draw(void)18{19RSDK_THIS(RotatingStair);2021RSDK.DrawSprite(&self->animator, &self->drawPos, false);22}2324void RotatingStair_Create(void *data)25{26RSDK_THIS(RotatingStair);2728self->frameID = 2;29self->collision = PLATFORM_C_SOLID;30self->speed = 3;3132if (self->direction)33self->amplitude.x = -self->amplitude.x;3435if (self->mode & 1)36self->amplitude.x = -self->amplitude.x;3738int32 typeStore = self->mode;39self->mode = (RotatingStairModes)PLATFORM_LINEAR;40Platform_Create(NULL);41self->mode = typeStore;4243if (self->mode >= 4) {44self->duration = 120 * self->speed;45self->state = RotatingStair_State_Move_Intervals;46self->interval = self->duration + 512;47}48else {49self->state = RotatingStair_State_Move;50}51}5253void RotatingStair_StageLoad(void) { RotatingStair->unused = 0; }5455void RotatingStair_State_Move(void)56{57RSDK_THIS(RotatingStair);5859int32 timer = Zone->timer + self->oscOff;60int32 drawX = -self->drawPos.x;61int32 drawY = -self->drawPos.y;6263int32 dir = 0;64if (self->mode & 1)65dir = self->mode - (((3 * timer) >> 9) & 3) - 2;66else67dir = ((3 * timer) >> 9) + self->mode;6869switch (dir & 3) {70case FLIP_NONE: // right71self->drawPos.x = self->centerPos.x + self->amplitude.x * RSDK.Cos1024(timer * self->speed);72self->drawPos.y = self->centerPos.y + (self->amplitude.y << 10);73break;7475case FLIP_X: // up76self->drawPos.x = self->centerPos.x - (self->amplitude.x << 10);77self->drawPos.y = self->centerPos.y - self->amplitude.y * RSDK.Cos1024(timer * self->speed);78break;7980case FLIP_Y: // left81self->drawPos.x = self->centerPos.x - self->amplitude.x * RSDK.Cos1024(timer * self->speed);82self->drawPos.y = self->centerPos.y - (self->amplitude.y << 10);83break;8485case FLIP_XY: // down86self->drawPos.x = self->centerPos.x + (self->amplitude.x << 10);87self->drawPos.y = self->centerPos.y + self->amplitude.y * RSDK.Cos1024(timer * self->speed);88break;89}9091self->velocity.x = drawX + self->drawPos.x;92self->velocity.y = drawY + self->drawPos.y;93}9495void RotatingStair_State_Move_Intervals(void)96{97RSDK_THIS(RotatingStair);9899int32 drawX = -self->drawPos.x;100int32 drawY = -self->drawPos.y;101102int32 angle = 0;103if (self->speed * (Zone->timer + self->oscOff) % self->interval >= self->duration)104angle = self->speed * (Zone->timer + self->oscOff) % self->interval - self->duration;105106int32 dir = 0;107if (self->mode & 1)108dir = self->mode - ((self->speed * (Zone->timer + self->oscOff) / self->interval) & 3) - 2;109else110dir = self->speed * (Zone->timer + self->oscOff) / self->interval + self->mode;111112switch (dir & 3) {113case FLIP_NONE: // right114self->drawPos.x = self->centerPos.x + self->amplitude.x * RSDK.Cos1024(angle);115self->drawPos.y = self->centerPos.y + (self->amplitude.y << 10);116break;117118case FLIP_X: // up119self->drawPos.x = self->centerPos.x - (self->amplitude.x << 10);120self->drawPos.y = self->centerPos.y - self->amplitude.y * RSDK.Cos1024(angle + 0x200);121break;122123case FLIP_Y: // left124self->drawPos.x = self->centerPos.x - self->amplitude.x * RSDK.Cos1024(angle);125self->drawPos.y = self->centerPos.y - (self->amplitude.y << 10);126break;127128case FLIP_XY: // down129self->drawPos.x = self->centerPos.x + (self->amplitude.x << 10);130self->drawPos.y = self->centerPos.y + self->amplitude.y * RSDK.Cos1024(angle + 0x200);131break;132}133134self->velocity.x = drawX + self->drawPos.x;135self->velocity.y = drawY + self->drawPos.y;136}137138#if GAME_INCLUDE_EDITOR139void RotatingStair_EditorDraw(void)140{141RSDK_THIS(RotatingStair);142143self->frameID = 2;144self->collision = PLATFORM_C_SOLID;145self->speed = 3;146if (self->direction)147self->amplitude.x = -self->amplitude.x;148if (self->mode & 1)149self->amplitude.x = -self->amplitude.x;150151int32 typeStore = self->mode;152self->mode = (RotatingStairModes)PLATFORM_LINEAR;153Platform_Create(NULL);154self->mode = typeStore;155156// self->drawPos = self->position;157158Vector2 amplitude = self->amplitude;159160if (self->direction)161self->amplitude.x = -self->amplitude.x;162if (self->mode & 1)163self->amplitude.x = -self->amplitude.x;164165if (self->mode >= 4) {166self->duration = 120 * self->speed;167self->interval = self->duration + 512;168RotatingStair_State_Move_Intervals();169}170else {171RotatingStair_State_Move();172}173174RotatingStair_Draw();175176if (showGizmos()) {177RSDK_DRAWING_OVERLAY(true);178179for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {180Entity *child = RSDK_GET_ENTITY_GEN(s + i);181if (!child)182continue;183184DrawHelpers_DrawArrow(self->drawPos.x, self->drawPos.y, child->position.x, child->position.y, 0xFFFF00, INK_NONE, 0xFF);185}186187RSDK_DRAWING_OVERLAY(false);188}189190self->amplitude = amplitude;191}192193void RotatingStair_EditorLoad(void)194{195196RSDK_ACTIVE_VAR(RotatingStair, mode);197RSDK_ENUM_VAR("Start Left", ROTATINGSTAIR_LEFT);198RSDK_ENUM_VAR("Start Down", ROTATINGSTAIR_DOWN);199RSDK_ENUM_VAR("Start Right", ROTATINGSTAIR_RIGHT);200RSDK_ENUM_VAR("Start Up", ROTATINGSTAIR_UP);201RSDK_ENUM_VAR("Start Left (Use Intervals)", ROTATINGSTAIR_LEFT_INTERVAL);202RSDK_ENUM_VAR("Start Down (Use Intervals)", ROTATINGSTAIR_DOWN_INTERVAL);203RSDK_ENUM_VAR("Start Right (Use Intervals)", ROTATINGSTAIR_RIGHT_INTERVAL);204RSDK_ENUM_VAR("Start Up (Use Intervals)", ROTATINGSTAIR_UP_INTERVAL);205206RSDK_ACTIVE_VAR(RotatingStair, direction);207RSDK_ENUM_VAR("No Flip", FLIP_NONE);208RSDK_ENUM_VAR("Flipped", FLIP_X);209}210#endif211212void RotatingStair_Serialize(void)213{214RSDK_EDITABLE_VAR(RotatingStair, VAR_ENUM, mode);215RSDK_EDITABLE_VAR(RotatingStair, VAR_VECTOR2, amplitude);216RSDK_EDITABLE_VAR(RotatingStair, VAR_ENUM, childCount);217RSDK_EDITABLE_VAR(RotatingStair, VAR_UINT8, direction);218RSDK_EDITABLE_VAR(RotatingStair, VAR_UINT16, oscOff);219}220221222