Path: blob/master/SonicMania/Objects/GHZ/CorkscrewPath.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: CorkscrewPath Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectCorkscrewPath *CorkscrewPath;1011void CorkscrewPath_Update(void)12{13RSDK_THIS(CorkscrewPath);14foreach_active(Player, player)15{16int32 playerID = RSDK.GetEntitySlot(player);1718if (abs(self->position.x - player->position.x) >> 16 > self->xSize) {19self->activePlayers &= ~playerID;20if (player->animator.animationID != ANI_SPRING_CS)21player->direction &= ~FLIP_Y;22}23else {24int32 corkscrewPos = self->xSize + ((player->position.x - self->position.x) >> 16);25int32 frame = 24 * corkscrewPos / self->period;26int32 yOffset = self->amplitude * RSDK.Cos1024((corkscrewPos << 10) / self->period);2728if (!(playerID & self->activePlayers)) {29if (abs(yOffset + self->position.y - player->position.y) >= 0x100000) {30self->activePlayers &= ~playerID;31}32else if (abs(player->groundVel) > 0x40000 && player->velocity.y > -0x40000 && player->groundedStore) {33player->position.y = self->position.y + yOffset;34player->velocity.y = 0;35player->onGround = true;3637if (player->animator.animationID != ANI_JUMP) {38if (player->groundVel < 0) {39player->direction |= FLIP_Y;40RSDK.SetSpriteAnimation(player->aniFrames, ANI_SPRING_CS, &player->animator, true, CorkscrewPath->frameTable[frame]);41}42else {43player->direction &= ~FLIP_Y;44RSDK.SetSpriteAnimation(player->aniFrames, ANI_SPRING_CS, &player->animator, true, frame);45}46}47}48else {49self->activePlayers &= ~playerID;50}51}52else if (abs(player->groundVel) > 0x40000 && player->groundedStore && abs(yOffset + self->position.y - player->position.y) < 0x100000) {53self->activePlayers |= playerID;54player->position.y = yOffset + self->position.y;55player->velocity.y = 0;56player->onGround = true;5758if (player->animator.animationID != ANI_JUMP) {59if (player->groundVel < 0) {60player->direction |= FLIP_Y;61RSDK.SetSpriteAnimation(player->aniFrames, ANI_SPRING_CS, &player->animator, true, CorkscrewPath->frameTable[frame]);62}63else {64player->direction &= ~FLIP_Y;65RSDK.SetSpriteAnimation(player->aniFrames, ANI_SPRING_CS, &player->animator, true, frame);66}67}68}69}70}71}7273void CorkscrewPath_LateUpdate(void) {}7475void CorkscrewPath_StaticUpdate(void) {}7677void CorkscrewPath_Draw(void) {}7879void CorkscrewPath_Create(void *data)80{81RSDK_THIS(CorkscrewPath);8283if (!SceneInfo->inEditor) {84self->amplitude <<= 6;85self->period = abs(self->period);86self->xSize = self->period >> 1;87self->active = ACTIVE_BOUNDS;88self->updateRange.x = abs(self->period) << 15;89self->updateRange.y = self->amplitude << 3;90}91}9293void CorkscrewPath_StageLoad(void) {}9495#if GAME_INCLUDE_EDITOR96void CorkscrewPath_EditorDraw(void)97{98RSDK_THIS(CorkscrewPath);99RSDK.SetSpriteAnimation(CorkscrewPath->aniFrames, 0, &self->animator, true, 4);100RSDK.DrawSprite(&self->animator, NULL, false);101102// Bounds103104Vector2 size;105size.x = abs(self->period) << 15;106size.y = (self->amplitude << 6) * RSDK.Cos1024(0);107108DrawHelpers_DrawRectOutline(self->position.x, self->position.y, size.x << 1, size.y << 1, 0xFFFF00);109}110111void CorkscrewPath_EditorLoad(void) { CorkscrewPath->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE); }112#endif113114void CorkscrewPath_Serialize(void)115{116RSDK_EDITABLE_VAR(CorkscrewPath, VAR_ENUM, period);117RSDK_EDITABLE_VAR(CorkscrewPath, VAR_ENUM, amplitude);118RSDK_EDITABLE_VAR(CorkscrewPath, VAR_ENUM, angle);119}120121122