Path: blob/master/SonicMania/Objects/AIZ/AIZTornadoPath.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: AIZTornadoPath Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectAIZTornadoPath *AIZTornadoPath;1011void AIZTornadoPath_Update(void)12{13RSDK_THIS(AIZTornadoPath);14StateMachine_Run(self->state);15}1617void AIZTornadoPath_LateUpdate(void) {}1819void AIZTornadoPath_StaticUpdate(void) {}2021void AIZTornadoPath_Draw(void) {}2223void AIZTornadoPath_Create(void *data)24{25RSDK_THIS(AIZTornadoPath);26if (!SceneInfo->inEditor) {27switch (self->type) {28case AIZTORNADOPATH_START:29if (!StarPost->postIDs[0]) {30self->active = ACTIVE_NORMAL;31EntityCamera *camera = RSDK_GET_ENTITY(SLOT_CAMERA1, Camera);32if (camera) {33camera->state = StateMachine_None;34camera->position.x = self->position.x;35camera->position.y = self->position.y;36AIZTornadoPath->camera = camera;37}3839foreach_all(Player, player) { player->camera = NULL; }4041foreach_all(AIZTornado, tornado) { AIZTornadoPath->tornado = tornado; }42ScreenInfo->position.y = FROM_FIXED(self->position.y) - ScreenInfo->center.y;43self->speed = self->targetSpeed;44self->state = AIZTornadoPath_State_SetTornadoSpeed;45}46break;4748case AIZTORNADOPATH_DUD: self->active = ACTIVE_NEVER; break;4950case AIZTORNADOPATH_SETSPEED:51self->active = ACTIVE_NEVER;52self->timer = 1;53self->state = AIZTornadoPath_State_SetTornadoSpeed;54break;5556case AIZTORNADOPATH_SETCAMERA:57self->active = ACTIVE_NEVER;58self->state = AIZTornadoPath_State_SetPlayerCamera;59break;6061case AIZTORNADOPATH_DISABLEINTERACTIONS:62self->active = ACTIVE_NEVER;63self->state = AIZTornadoPath_State_DisablePlayerInteractions;64break;6566case AIZTORNADOPATH_EXITTORNADO:67self->active = ACTIVE_NEVER;68self->timer = 1;69self->state = AIZTornadoPath_State_ExitTornadoSequence;70break;7172case AIZTORNADOPATH_ENTERTORNADO:73self->state = AIZTornadoPath_State_PrepareCatchPlayer;74self->active = (StarPost->postIDs[0] > 0) ? ACTIVE_XBOUNDS : ACTIVE_NEVER;75self->speed = self->targetSpeed;76break;7778case AIZTORNADOPATH_TARGETNODE:79self->active = ACTIVE_NEVER;80self->timer = 1;81self->speed = self->targetSpeed;82self->state = AIZTornadoPath_State_SetTornadoSpeed;83break;8485default: break;86}87}88}8990void AIZTornadoPath_StageLoad(void)91{92AIZTornadoPath->moveVel.x = 0;93AIZTornadoPath->moveVel.y = 0;94}9596void AIZTornadoPath_HandleMoveSpeed(void)97{98RSDK_THIS(AIZTornadoPath);99bool32 usingCamPos = false;100EntityCamera *camera = AIZTornadoPath->camera;101EntityAIZTornado *tornado = AIZTornadoPath->tornado;102103int32 x = 0, y = 0;104if (camera && camera->position.x >= ScreenInfo->size.x << 16) {105x = camera->position.x;106y = camera->position.y;107usingCamPos = true;108}109else {110x = tornado->newPos.x;111y = tornado->newPos.y;112}113114EntityAIZTornadoPath *node = RSDK_GET_ENTITY(SceneInfo->entitySlot + 1, AIZTornadoPath);115int32 xDist = (x - node->position.x) >> 16;116int32 yDist = (y - node->position.y) >> 16;117self->angle = RSDK.ATan2(xDist, yDist);118int32 newPosX = x - self->speed * RSDK.Cos256(self->angle);119int32 newPosY = y - self->speed * RSDK.Sin256(self->angle);120if (usingCamPos) {121camera->position.x = newPosX;122camera->position.y = newPosY;123}124125int32 spd = self->speed >> 3;126if (xDist * xDist + yDist * yDist < spd) {127self->active = ACTIVE_NEVER;128node->active = ACTIVE_NORMAL;129if (node->easeToSpeed)130node->speed = self->speed;131else132node->speed = self->targetSpeed;133}134AIZTornadoPath->moveVel.x = newPosX - x;135AIZTornadoPath->moveVel.y = newPosY - y;136}137138void AIZTornadoPath_State_SetTornadoSpeed(void)139{140RSDK_THIS(AIZTornadoPath);141142if (self->speed >= self->targetSpeed) {143if (self->speed > self->targetSpeed) {144self->speed -= 16;145if (self->speed < self->targetSpeed)146self->speed = self->targetSpeed;147}148}149else {150self->speed += 16;151if (self->speed > self->targetSpeed)152self->speed = self->targetSpeed;153}154155if (self->timer > 0) {156self->timer--;157}158else {159AIZTornadoPath_HandleMoveSpeed();160}161}162163void AIZTornadoPath_State_SetPlayerCamera(void)164{165EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);166EntityCamera *camera = AIZTornadoPath->camera;167168if (camera) {169camera->state = Camera_State_FollowXY;170player->camera = camera;171AIZTornadoPath->camera = NULL;172}173}174175void AIZTornadoPath_State_DisablePlayerInteractions(void)176{177RSDK_THIS(AIZTornadoPath);178EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);179player->collisionPlane = 1;180player->interaction = false;181182foreach_active(Player, playerPtr) { playerPtr->drawGroup = Zone->playerDrawGroup[1]; }183184AIZTornadoPath_HandleMoveSpeed();185self->state = AIZTornadoPath_State_SetTornadoSpeed;186}187188void AIZTornadoPath_State_ExitTornadoSequence(void)189{190foreach_active(AIZTornado, tornado) { tornado->drawGroup = Zone->objectDrawGroup[0]; }191192if (!tornado->disableInteractions) {193EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);194EntityCamera *camera = AIZTornadoPath->camera;195196if (camera) {197camera->state = Camera_State_FollowXY;198player->camera = camera;199player->collisionPlane = 0;200player->interaction = true;201player->applyJumpCap = false;202player->drawGroup = Zone->playerDrawGroup[0];203AIZTornadoPath->camera = NULL;204}205player->groundVel = AIZTornadoPath->moveVel.x;206Player_Action_Jump(player);207player->right = true;208tornado->disableInteractions = true;209}210211AIZTornadoPath_State_SetTornadoSpeed();212}213214void AIZTornadoPath_State_PrepareCatchPlayer(void)215{216RSDK_THIS(AIZTornadoPath);217EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);218219if (player->position.x > self->position.x) {220player->stateInput = StateMachine_None;221player->left = false;222player->right = true;223if (player->pushing > 0) {224player->jumpPress = true;225player->jumpHold = true;226self->state = AIZTornadoPath_State_CatchPlayer;227AIZTornadoPath->moveVel.x = 0;228AIZTornadoPath->moveVel.y = 0;229}230}231}232233void AIZTornadoPath_State_CatchPlayer(void)234{235RSDK_THIS(AIZTornadoPath);236EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);237238++self->timer;239if (self->timer == 60) {240foreach_all(AIZTornado, tornado)241{242tornado->position.x = player->position.x - 0x1400000;243tornado->position.y = player->position.y + 0x400000;244tornado->offsetX = 0x40000;245tornado->state = AIZTornado_State_Move;246tornado->active = ACTIVE_NORMAL;247}248}249250if (self->timer == 90) {251self->timer = 0;252player->stateInput = Player_Input_P1;253int32 velX = 0;254foreach_all(AIZTornadoPath, node)255{256if (node->type == AIZTORNADOPATH_TARGETNODE) {257velX = node->position.x - player->position.x;258node->active = ACTIVE_NORMAL;259}260}261262player->position.x += velX;263if (player->camera) {264player->camera->position.x += velX;265player->camera->state = StateMachine_None;266AIZTornadoPath->camera = player->camera;267player->camera = NULL;268}269270foreach_active(AIZTornado, tornado)271{272tornado->position.x += velX;273tornado->offsetX = 0x80000;274}275}276}277278#if GAME_INCLUDE_EDITOR279void AIZTornadoPath_EditorDraw(void)280{281RSDK_THIS(AIZTornadoPath);282RSDK.SetSpriteAnimation(AIZTornadoPath->aniFrames, 0, &self->unusedAnimator, true, 7);283RSDK.DrawSprite(&self->unusedAnimator, NULL, false);284}285286void AIZTornadoPath_EditorLoad(void)287{288AIZTornadoPath->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE);289RSDK.SetSpriteAnimation(AIZTornadoPath->aniFrames, 0, &AIZTornadoPath->unusedAnimator, true, 7);290291RSDK_ACTIVE_VAR(AIZTornadoPath, type);292RSDK_ENUM_VAR("Start Node", AIZTORNADOPATH_START);293RSDK_ENUM_VAR("Blank Node", AIZTORNADOPATH_DUD);294RSDK_ENUM_VAR("Set Tornado Speed", AIZTORNADOPATH_SETSPEED);295RSDK_ENUM_VAR("Return Player Camera", AIZTORNADOPATH_SETCAMERA);296RSDK_ENUM_VAR("Disable Player Interactions", AIZTORNADOPATH_DISABLEINTERACTIONS);297RSDK_ENUM_VAR("Exit Tornado Sequence", AIZTORNADOPATH_EXITTORNADO);298RSDK_ENUM_VAR("Enter Tornado Sequence (Fly to Target Node)", AIZTORNADOPATH_ENTERTORNADO);299RSDK_ENUM_VAR("Set Tornado Speed (Target Node)", AIZTORNADOPATH_TARGETNODE);300}301#endif302303void AIZTornadoPath_Serialize(void)304{305RSDK_EDITABLE_VAR(AIZTornadoPath, VAR_ENUM, type);306RSDK_EDITABLE_VAR(AIZTornadoPath, VAR_ENUM, targetSpeed);307RSDK_EDITABLE_VAR(AIZTornadoPath, VAR_ENUM, timer);308RSDK_EDITABLE_VAR(AIZTornadoPath, VAR_BOOL, easeToSpeed);309}310311312