Path: blob/master/SonicMania/Objects/Common/ForceSpin.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: ForceSpin Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectForceSpin *ForceSpin;1011void ForceSpin_Update(void)12{13RSDK_THIS(ForceSpin);1415foreach_active(Player, player)16{17Vector2 pivotPos = player->position;18Vector2 pivotVel = player->velocity;1920Zone_RotateOnPivot(&pivotPos, &self->position, self->negAngle);21Zone_RotateOnPivot(&pivotVel, &self->velocity, self->negAngle);2223if (abs(pivotPos.x - self->position.x) < TO_FIXED(24) && abs(pivotPos.y - self->position.y) < self->size << 19) {24if (pivotPos.x >= self->position.x) {25if (self->direction) {26if (player->state == Player_State_TubeRoll || player->state == Player_State_TubeAirRoll) {27player->state = player->onGround ? Player_State_Roll : Player_State_Air;28player->nextGroundState = StateMachine_None;29player->nextAirState = StateMachine_None;30}31}32else {33ForceSpin_SetPlayerState(player);34}35}36else {37if (!self->direction) {38if (player->state == Player_State_TubeRoll || player->state == Player_State_TubeAirRoll) {39player->state = player->onGround ? Player_State_Roll : Player_State_Air;40player->nextGroundState = StateMachine_None;41player->nextAirState = StateMachine_None;42}43}44else {45ForceSpin_SetPlayerState(player);46}47}48}49}5051self->visible = DebugMode->debugActive;52}5354void ForceSpin_LateUpdate(void) {}5556void ForceSpin_StaticUpdate(void) {}5758void ForceSpin_Draw(void) { ForceSpin_DrawSprites(); }5960void ForceSpin_Create(void *data)61{62RSDK_THIS(ForceSpin);6364RSDK.SetSpriteAnimation(ForceSpin->aniFrames, 0, &self->animator, true, 0);65self->animator.frameID = 4;66self->drawFX |= FX_FLIP;6768if (!SceneInfo->inEditor) {69self->active = ACTIVE_BOUNDS;70self->updateRange.x = TO_FIXED(32) + abs(self->size * RSDK.Sin256(self->angle) << 11);71self->updateRange.y = TO_FIXED(32) + abs(self->size * RSDK.Cos256(self->angle) << 11);72self->visible = false;73self->drawGroup = Zone->objectDrawGroup[0];74self->negAngle = -self->angle & 0xFF;75}76}7778void ForceSpin_StageLoad(void) { ForceSpin->aniFrames = RSDK.LoadSpriteAnimation("Global/PlaneSwitch.bin", SCOPE_STAGE); }7980void ForceSpin_DrawSprites(void)81{82RSDK_THIS(ForceSpin);8384Vector2 drawPos;85drawPos.x = self->position.x;86drawPos.y = self->position.y - (self->size << 19);87Zone_RotateOnPivot(&drawPos, &self->position, self->angle);8889for (int32 i = 0; i < self->size; ++i) {90RSDK.DrawSprite(&self->animator, &drawPos, false);91drawPos.x += RSDK.Sin256(self->angle) << 12;92drawPos.y += RSDK.Cos256(self->angle) << 12;93}94}95void ForceSpin_SetPlayerState(EntityPlayer *player)96{97RSDK_THIS(ForceSpin);9899if (player->state != Player_State_TubeRoll && player->state != Player_State_TubeAirRoll) {100if (player->animator.animationID != ANI_JUMP) {101RSDK.PlaySfx(Player->sfxRoll, false, 0xFF);102RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);103if (!player->collisionMode && player->onGround)104player->position.y += player->jumpOffset;105player->pushing = 0;106}107108player->state = player->onGround ? Player_State_TubeRoll : Player_State_TubeAirRoll;109player->nextGroundState = StateMachine_None;110player->nextAirState = StateMachine_None;111112if (abs(player->groundVel) < 0x10000) {113if (self->direction & FLIP_X)114player->groundVel = -0x40000;115else116player->groundVel = 0x40000;117}118}119}120121#if GAME_INCLUDE_EDITOR122void ForceSpin_EditorDraw(void)123{124RSDK_THIS(ForceSpin);125126self->updateRange.x = TO_FIXED(32) + abs(self->size * RSDK.Sin256(self->angle) << 11);127self->updateRange.y = TO_FIXED(32) + abs(self->size * RSDK.Cos256(self->angle) << 11);128129ForceSpin_DrawSprites();130}131132void ForceSpin_EditorLoad(void)133{134ForceSpin->aniFrames = RSDK.LoadSpriteAnimation("Global/PlaneSwitch.bin", SCOPE_STAGE);135136RSDK_ACTIVE_VAR(ForceSpin, direction);137RSDK_ENUM_VAR("Enter From Right, Exit From Left", FLIP_NONE);138RSDK_ENUM_VAR("Enter From Left, Exit From Right", FLIP_X);139}140#endif141142void ForceSpin_Serialize(void)143{144RSDK_EDITABLE_VAR(ForceSpin, VAR_UINT8, direction);145RSDK_EDITABLE_VAR(ForceSpin, VAR_ENUM, size);146RSDK_EDITABLE_VAR(ForceSpin, VAR_INT32, angle);147}148149150