Path: blob/master/SonicMania/Objects/TMZ/GymBar.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: GymBar Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectGymBar *GymBar;1011void GymBar_Update(void) { GymBar_HandlePlayerInteractions(); }1213void GymBar_LateUpdate(void) {}1415void GymBar_StaticUpdate(void) {}1617void GymBar_Draw(void)18{19RSDK_THIS(GymBar);2021Vector2 drawPos = self->position;22if (self->type != GYMBAR_HORIZONTAL) {23drawPos.y = self->position.y - (self->size << 18);24self->animator.frameID = 0;25RSDK.DrawSprite(&self->animator, &drawPos, false);2627self->animator.frameID = 1;28for (int32 i = 0; i < self->size; ++i) {29RSDK.DrawSprite(&self->animator, &drawPos, false);30drawPos.y += 0x80000;31}32}33else {34drawPos.x = self->position.x - (self->size << 18);35self->animator.frameID = 0;36RSDK.DrawSprite(&self->animator, &drawPos, false);3738self->animator.frameID = 1;39for (int32 i = 0; i < self->size; ++i) {40RSDK.DrawSprite(&self->animator, &drawPos, false);41drawPos.x += 0x80000;42}43}4445self->animator.frameID = 2;46RSDK.DrawSprite(&self->animator, &drawPos, false);47}4849void GymBar_Create(void *data)50{51RSDK_THIS(GymBar);5253self->drawFX = FX_FLIP;54self->visible = true;55self->drawGroup = Zone->objectDrawGroup[0];56self->active = ACTIVE_BOUNDS;57self->updateRange.x = 0x400000;58self->updateRange.y = 0x400000;5960if (self->type == GYMBAR_HORIZONTAL) {61self->updateRange.x = (self->size << 18) + 0x400000;6263self->hitbox.left = -4 * self->size;64self->hitbox.top = 0;65self->hitbox.right = 4 * self->size - 8;66self->hitbox.bottom = 8;6768self->maxX = self->position.x - (self->size << 18) + 0x50000;69self->minX = (self->size << 18) + self->position.x - 0xC0000;70}71else {72self->updateRange.y = (self->size + 16) << 18;7374self->hitbox.left = 0;75self->hitbox.top = (8 - (self->size << 2));76self->hitbox.right = 0;77self->hitbox.bottom = (self->size << 2) - 16;78}7980RSDK.SetSpriteAnimation(GymBar->aniFrames, self->type, &self->animator, true, 0);81}8283void GymBar_StageLoad(void)84{85if (RSDK.CheckSceneFolder("TMZ1") || RSDK.CheckSceneFolder("TMZ2"))86GymBar->aniFrames = RSDK.LoadSpriteAnimation("TMZ1/GymBar.bin", SCOPE_STAGE);8788GymBar->sfxBumper = RSDK.GetSfx("Stage/Bumper3.wav");8990DEBUGMODE_ADD_OBJ(GymBar);91}9293void GymBar_DebugSpawn(void)94{95RSDK_THIS(GymBar);9697CREATE_ENTITY(GymBar, NULL, self->position.x, self->position.y);98}99100void GymBar_DebugDraw(void)101{102RSDK.SetSpriteAnimation(GymBar->aniFrames, 0, &DebugMode->animator, true, 0);103RSDK.DrawSprite(&DebugMode->animator, NULL, false);104}105106void GymBar_HandlePlayerInteractions(void)107{108RSDK_THIS(GymBar);109110foreach_active(Player, player)111{112int32 playerID = RSDK.GetEntitySlot(player);113if (player->animator.animationID != ANI_HURT && player->state != Player_State_FlyCarried) {114if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {115if (!self->playerTimers[playerID]) {116player->onGround = false;117if (self->type != GYMBAR_HORIZONTAL) {118if (abs(player->velocity.x) >= 0x40000) {119player->position.x = self->position.x;120player->direction = FLIP_NONE;121if (player->velocity.x <= 0)122RSDK.SetSpriteAnimation(player->aniFrames, ANI_POLE_SWING_H, &player->animator, false, 2);123else124RSDK.SetSpriteAnimation(player->aniFrames, ANI_POLE_SWING_H, &player->animator, false, 9);125player->animator.speed = 0xE0 + ((abs(player->velocity.x) - 0x40000) >> 12);126player->abilityValues[0] = 0;127player->abilityValues[1] = player->animator.frameID;128player->abilityValues[2] = player->velocity.x;129player->state = GymBar_PlayerState_SwingH;130}131}132else {133player->rotation = 0;134player->position.x = CLAMP(player->position.x, self->maxX, self->minX);135player->position.y = self->position.y;136137if (abs(player->velocity.y) < 0x40000 || self->noSwing) {138RSDK.SetSpriteAnimation(player->aniFrames, ANI_POLE_SWING_V, &player->animator, false, 0);139player->animator.speed = 0;140player->abilityPtrs[0] = self;141player->state = GymBar_PlayerState_Hang;142}143else {144if (player->velocity.y <= 0)145RSDK.SetSpriteAnimation(player->aniFrames, ANI_POLE_SWING_V, &player->animator, false, 2);146else147RSDK.SetSpriteAnimation(player->aniFrames, ANI_POLE_SWING_V, &player->animator, false, 9);148player->animator.speed = 0x100 + ((abs(player->velocity.y) - 0x40000) >> 12);149player->abilityValues[0] = 0;150player->abilityValues[1] = player->animator.frameID;151player->abilityValues[2] = player->velocity.y;152player->state = GymBar_PlayerState_SwingV;153}154}155156if (player->state == GymBar_PlayerState_Hang || player->state == GymBar_PlayerState_SwingH157|| player->state == GymBar_PlayerState_SwingV) {158self->playerTimers[playerID] = 16;159RSDK.PlaySfx(Player->sfxGrab, false, 0xFF);160player->nextAirState = StateMachine_None;161player->nextGroundState = StateMachine_None;162player->velocity.x = 0;163player->velocity.y = 0;164player->groundVel = 0;165player->applyJumpCap = false;166}167}168}169else {170if (self->playerTimers[playerID])171self->playerTimers[playerID]--;172}173}174}175}176177void GymBar_HandleSwingJump(void)178{179RSDK_THIS(Player);180181if (!self->down)182self->velocity.y = -0x50000;183184RSDK.SetSpriteAnimation(self->aniFrames, ANI_JUMP, &self->animator, false, 0);185186if (self->characterID == ID_TAILS)187self->animator.speed = 120;188else189self->animator.speed = ((abs(self->groundVel) * 0xF0) / 0x60000) + 0x30;190191if (self->animator.speed > 0xF0)192self->animator.speed = 0xF0;193194self->applyJumpCap = true;195self->jumpAbilityState = 1;196self->abilityPtrs[0] = NULL;197self->abilityValues[0] = 0;198self->abilityValues[1] = 0;199self->abilityValues[2] = 0;200201self->state = Player_State_Air;202}203204void GymBar_PlayerState_SwingV(void)205{206RSDK_THIS(Player);207208if (self->jumpPress)209GymBar_HandleSwingJump();210211int32 frame = self->abilityValues[2] <= 0 ? 4 : 11;212213if (self->animator.frameID == frame && self->abilityValues[1] != frame)214++self->abilityValues[0];215216self->abilityValues[1] = self->animator.frameID;217if (self->abilityValues[0] >= 2) {218if (self->abilityValues[2] <= 0)219RSDK.SetSpriteAnimation(self->aniFrames, ANI_SPRING_DIAGONAL, &self->animator, false, 0);220else221RSDK.SetSpriteAnimation(self->aniFrames, ANI_WALK, &self->animator, false, 0);222223self->velocity.y =224self->abilityValues[2] + (self->abilityValues[2] >> ((abs(self->abilityValues[2]) >> 18) + (abs(self->abilityValues[2]) >> 20)));225self->abilityPtrs[0] = NULL;226self->abilityValues[0] = 0;227self->abilityValues[1] = 0;228self->abilityValues[2] = 0;229230self->state = Player_State_Air;231}232}233234void GymBar_PlayerState_Hang(void)235{236RSDK_THIS(Player);237238EntityGymBar *gymbar = self->abilityPtrs[0];239if (self->left) {240if (self->position.x > gymbar->maxX)241self->position.x -= 0x10000;242243RSDK.SetSpriteAnimation(self->aniFrames, ANI_SHIMMY_MOVE, &self->animator, false, 0);244self->direction = FLIP_X;245}246else if (self->right) {247if (self->position.x < gymbar->minX)248self->position.x += 0x10000;249250RSDK.SetSpriteAnimation(self->aniFrames, ANI_SHIMMY_MOVE, &self->animator, false, 0);251self->direction = FLIP_NONE;252}253else {254RSDK.SetSpriteAnimation(self->aniFrames, ANI_SHIMMY_IDLE, &self->animator, false, 0);255}256257if (self->jumpPress)258GymBar_HandleSwingJump();259}260261void GymBar_PlayerState_SwingH(void)262{263RSDK_THIS(Player);264265if (self->jumpPress)266GymBar_HandleSwingJump();267268int32 frame = self->abilityValues[2] <= 0 ? 4 : 11;269270if (self->animator.frameID == frame && self->abilityValues[1] != frame)271++self->abilityValues[0];272273self->abilityValues[1] = self->animator.frameID;274if (self->abilityValues[0] >= 2) {275RSDK.SetSpriteAnimation(self->aniFrames, ANI_WALK, &self->animator, false, 0);276277self->velocity.x = self->abilityValues[2] + (self->abilityValues[2] >> (abs(self->abilityValues[2]) >> 18));278self->groundVel = self->velocity.x;279self->direction = abs(self->velocity.x >> 31);280281self->abilityPtrs[0] = NULL;282self->abilityValues[0] = 0;283self->abilityValues[1] = 0;284self->abilityValues[2] = 0;285286self->state = Player_State_Air;287}288}289290#if GAME_INCLUDE_EDITOR291void GymBar_EditorDraw(void)292{293RSDK_THIS(GymBar);294295if (self->type == GYMBAR_HORIZONTAL) {296self->updateRange.x = (self->size << 18) + 0x400000;297self->maxX = self->position.x - (self->size << 18) + 0x50000;298self->minX = (self->size << 18) + self->position.x - 0xC0000;299}300else {301self->updateRange.y = (self->size + 16) << 18;302}303304RSDK.SetSpriteAnimation(GymBar->aniFrames, self->type, &self->animator, true, 0);305306GymBar_Draw();307}308309void GymBar_EditorLoad(void)310{311GymBar->aniFrames = RSDK.LoadSpriteAnimation("TMZ1/GymBar.bin", SCOPE_STAGE);312313RSDK_ACTIVE_VAR(GymBar, type);314RSDK_ENUM_VAR("Horizontal", GYMBAR_HORIZONTAL);315RSDK_ENUM_VAR("Vertical", GYMBAR_VERTICAL);316}317#endif318319void GymBar_Serialize(void)320{321RSDK_EDITABLE_VAR(GymBar, VAR_ENUM, type);322RSDK_EDITABLE_VAR(GymBar, VAR_ENUM, size);323RSDK_EDITABLE_VAR(GymBar, VAR_BOOL, noSwing);324}325326327