Path: blob/master/SonicMania/Objects/MMZ/PlaneSeeSaw.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PlaneSeeSaw Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPlaneSeeSaw *PlaneSeeSaw;1011void PlaneSeeSaw_Update(void)12{13RSDK_THIS(PlaneSeeSaw);1415StateMachine_Run(self->state);16}1718void PlaneSeeSaw_LateUpdate(void) {}1920void PlaneSeeSaw_StaticUpdate(void) {}2122void PlaneSeeSaw_Draw(void)23{24RSDK_THIS(PlaneSeeSaw);2526Vector2 drawPos;27drawPos.x = self->position.x;28drawPos.y = self->position.y + self->scale.y * (self->seeSawPos >> 9);29self->direction = FLIP_X;30RSDK.DrawSprite(&self->swingAnimator, NULL, false);3132self->direction = FLIP_NONE;33RSDK.DrawSprite(&self->swingAnimator, NULL, false);34RSDK.DrawSprite(&self->weightAnimator, &drawPos, false);35RSDK.DrawSprite(&self->platformAnimator, NULL, false);36}3738void PlaneSeeSaw_Create(void *data)39{40RSDK_THIS(PlaneSeeSaw);41self->drawFX = FX_FLIP;4243if (!SceneInfo->inEditor) {44self->visible = true;45self->drawGroup = Zone->objectDrawGroup[0];46self->active = ACTIVE_BOUNDS;47self->updateRange.x = 0x800000;48self->updateRange.y = 0x800000;49self->scale.x = 0x200;50self->scale.y = 0x200;51self->state = PlaneSeeSaw_State_WaitForPlayer;52RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 0, &self->swingAnimator, true, 0);53RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 1, &self->platformAnimator, true, 0);54RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 2, &self->weightAnimator, true, 0);55}56}5758void PlaneSeeSaw_StageLoad(void)59{60PlaneSeeSaw->aniFrames = RSDK.LoadSpriteAnimation("MMZ/SeeSaw.bin", SCOPE_STAGE);6162PlaneSeeSaw->sfxSpring = RSDK.GetSfx("Global/Spring.wav");63PlaneSeeSaw->sfxFlipper = RSDK.GetSfx("Stage/Flipper.wav");64}6566void PlaneSeeSaw_State_WaitForPlayer(void)67{68RSDK_THIS(PlaneSeeSaw);6970Hitbox *hitbox = RSDK.GetHitbox(&self->platformAnimator, 0);71foreach_active(Player, player)72{73if (Player_CheckCollisionPlatform(player, self, hitbox)) {74#if MANIA_USE_PLUS75if (player->state == Player_State_MightyHammerDrop)76player->state = Player_State_Air;77#endif78self->state = PlaneSeeSaw_State_PlayerPushDown;79}80}81}8283void PlaneSeeSaw_State_PlayerPushDown(void)84{85RSDK_THIS(PlaneSeeSaw);8687Hitbox *hitboxOld = RSDK.GetHitbox(&self->platformAnimator, 0);88if (self->platformAnimator.frameID >= self->platformAnimator.frameCount - 1) {89self->velocity.y += 0x3800;90self->seeSawPos += self->velocity.y;91}92else {93++self->swingAnimator.frameID;94++self->platformAnimator.frameID;9596if (self->platformAnimator.frameID == self->platformAnimator.frameCount - 1) {97self->velocity.y = -0x60000;98RSDK.PlaySfx(PlaneSeeSaw->sfxFlipper, false, 255);99}100101self->seeSawPos = RSDK.GetHitbox(&self->swingAnimator, 0)->top << 16;102}103104Hitbox *hitboxNew = RSDK.GetHitbox(&self->platformAnimator, 0);105foreach_active(Player, player)106{107if (Player_CheckCollisionPlatform(player, self, hitboxOld))108player->position.y += (hitboxNew->bottom - hitboxOld->bottom) << 16;109}110111if (self->seeSawPos > -0x230000 && self->velocity.y > 0) {112self->velocity.y = 0;113self->seeSawPos = -0x230000;114self->state = PlaneSeeSaw_State_Launch;115RSDK.PlaySfx(PlaneSeeSaw->sfxSpring, false, 255);116}117}118119void PlaneSeeSaw_State_Launch(void)120{121RSDK_THIS(PlaneSeeSaw);122123Hitbox *hitboxOld = RSDK.GetHitbox(&self->platformAnimator, 0);124if (self->platformAnimator.frameID <= 0) {125self->state = PlaneSeeSaw_State_WaitForPlayer;126}127else {128--self->swingAnimator.frameID;129--self->platformAnimator.frameID;130131self->seeSawPos = RSDK.GetHitbox(&self->swingAnimator, 0)->top << 16;132}133134Hitbox *hitboxNew = RSDK.GetHitbox(&self->platformAnimator, 0);135foreach_active(Player, player)136{137if (Player_CheckCollisionPlatform(player, self, hitboxOld)) {138player->position.y += (hitboxNew->bottom - hitboxOld->bottom) << 16;139140if (self->platformAnimator.frameID < 4) {141if (self->scale.x == 0x100) {142player->position.x -= FarPlane->originPos.x;143player->position.y -= FarPlane->originPos.y;144player->position.x += FarPlane->position.x;145player->position.y += FarPlane->position.y;146147if (player->camera) {148player->camera->targetMoveVel.x = 0;149player->camera->targetMoveVel.y = 0;150}151152player->groundVel = 0;153player->velocity.x = 0;154player->drawGroup = Zone->playerDrawGroup[0];155player->state = PlaneSeeSaw_PlayerState_ToFG;156player->velocity.y = -0x60000;157}158else {159player->groundVel = 0;160player->velocity.x = 0;161player->scale.x = 0x200;162player->scale.y = 0x200;163player->state = PlaneSeeSaw_PlayerState_ToBG;164player->velocity.y = -0xA0000;165}166167player->abilityValues[0] = self->position.x;168player->nextAirState = StateMachine_None;169player->nextGroundState = StateMachine_None;170player->interaction = false;171player->tileCollisions = TILECOLLISION_NONE;172player->jumpAbilityState = 0;173player->drawFX |= FX_SCALE;174player->applyJumpCap = false;175player->onGround = false;176177EntityShield *shield = RSDK_GET_ENTITY(Player->playerCount + RSDK.GetEntitySlot(player), Shield);178if (shield && shield->classID)179shield->drawFX |= FX_SCALE;180181RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);182player->animator.speed = 0x80;183}184}185}186}187188void PlaneSeeSaw_PlayerState_ToBG(void)189{190EntityPlayer *self = RSDK_GET_ENTITY(SceneInfo->entitySlot, Player);191192self->left = false;193self->right = false;194195if ((self->abilityValues[0] ^ self->position.x) & 0xFFFF0000) {196self->position.x += self->position.x <= self->abilityValues[0] ? 0x8000 : -0x8000;197}198199ControllerInfo[self->controllerID].keyY.press = false;200Player_State_Air();201202self->tileCollisions = TILECOLLISION_NONE;203if (self->scale.x <= 0x100) {204self->interaction = true;205self->tileCollisions = TILECOLLISION_DOWN;206self->drawGroup = 2;207208self->position.x -= FarPlane->position.x;209self->position.y -= FarPlane->position.y;210self->position.x += FarPlane->originPos.x;211self->position.y += FarPlane->originPos.y;212Zone->deathBoundary[0] += 0x8000000;213214self->state = Player_State_Air;215if (self->camera) {216self->camera->targetMoveVel.x = FarPlane->position.x - FarPlane->originPos.x;217self->camera->targetMoveVel.y = FarPlane->position.y - FarPlane->originPos.y;218}219220self->scale.y = self->scale.x;221}222else {223self->scale.x -= 4;224self->scale.y = self->scale.x;225}226}227228void PlaneSeeSaw_PlayerState_ToFG(void)229{230// ???231EntityPlayer *self = RSDK_GET_ENTITY(SceneInfo->entitySlot, Player);232233self->left = false;234self->right = false;235if (((self->abilityValues[0] ^ self->position.x) & 0xFFFF0000)) {236self->position.x += self->position.x <= self->abilityValues[0] ? 0x8000 : -0x8000;237}238239ControllerInfo[self->controllerID].keyY.press = false;240Player_State_Air();241242self->tileCollisions = TILECOLLISION_NONE;243if (self->scale.x >= 0x200) {244self->interaction = true;245self->tileCollisions = TILECOLLISION_DOWN;246Zone->deathBoundary[0] -= 0x8000000;247248self->drawFX &= ~FX_SCALE;249self->state = Player_State_Air;250251EntityShield *shield = RSDK_GET_ENTITY(Player->playerCount + RSDK.GetEntitySlot(self), Shield);252if (shield && shield->classID)253shield->drawFX &= ~FX_SCALE;254255self->scale.y = self->scale.x;256}257else {258self->scale.x += 4;259self->scale.y = self->scale.x;260}261}262263#if GAME_INCLUDE_EDITOR264void PlaneSeeSaw_EditorDraw(void)265{266RSDK_THIS(PlaneSeeSaw);267268RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 0, &self->swingAnimator, false, 0);269RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 1, &self->platformAnimator, false, 0);270RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 2, &self->weightAnimator, false, 0);271272PlaneSeeSaw_Draw();273}274275void PlaneSeeSaw_EditorLoad(void) { PlaneSeeSaw->aniFrames = RSDK.LoadSpriteAnimation("MMZ/SeeSaw.bin", SCOPE_STAGE); }276#endif277278void PlaneSeeSaw_Serialize(void) {}279280281