Path: blob/master/SonicMania/Objects/OOZ/PushSpring.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PushSpring Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPushSpring *PushSpring;1011void PushSpring_Update(void)12{13RSDK_THIS(PushSpring);1415StateMachine_Run(self->state);1617self->beingPushed = false;18StateMachine_Run(self->stateCollide);19}2021void PushSpring_LateUpdate(void) {}2223void PushSpring_StaticUpdate(void) {}2425void PushSpring_Draw(void)26{27RSDK_THIS(PushSpring);2829if (self->pushOffset) {30StateMachine_Run(self->stateDraw);31}32else {33self->animator.frameID = 0;34RSDK.DrawSprite(&self->animator, NULL, false);35}36}3738void PushSpring_Create(void *data)39{40RSDK_THIS(PushSpring);4142self->drawFX = FX_FLIP;43if (!SceneInfo->inEditor) {44self->active = ACTIVE_BOUNDS;45self->visible = true;46self->drawGroup = Zone->objectDrawGroup[0];47self->updateRange.x = 0x800000;48self->updateRange.y = 0x800000;4950RSDK.SetSpriteAnimation(PushSpring->aniFrames, self->type, &self->animator, true, 0);5152if (self->type != PUSHSPRING_V) {53if (self->direction) {54self->stateDraw = PushSpring_Draw_Left;55self->stateCollide = PushSpring_Collide_Left;56}57else {58self->stateDraw = PushSpring_Draw_Right;59self->stateCollide = PushSpring_Collide_Right;60}6162self->groundVel = 0x4000;6364self->hitbox.left = -20;65self->hitbox.top = -16;66self->hitbox.right = 20;67self->hitbox.bottom = 16;6869self->state = PushSpring_State_WaitForPushed;70}71else {72if (self->direction) {73self->direction = FLIP_Y;74self->stateDraw = PushSpring_Draw_Bottom;75self->stateCollide = PushSpring_Collide_Bottom;76}77else {78self->stateDraw = PushSpring_Draw_Top;79self->stateCollide = PushSpring_Collide_Top;80}8182self->groundVel = 0x20000;8384self->hitbox.left = -16;85self->hitbox.top = -20;86self->hitbox.right = 16;87self->hitbox.bottom = 20;8889self->state = PushSpring_State_WaitForPushed;90}91}92}9394void PushSpring_StageLoad(void)95{96if (RSDK.CheckSceneFolder("OOZ1") || RSDK.CheckSceneFolder("OOZ2"))97PushSpring->aniFrames = RSDK.LoadSpriteAnimation("OOZ/PushSpring.bin", SCOPE_STAGE);9899PushSpring->sfxPush = RSDK.GetSfx("Stage/Push.wav");100PushSpring->sfxSpring = RSDK.GetSfx("Global/Spring.wav");101}102103void PushSpring_Collide_Top(void)104{105RSDK_THIS(PushSpring);106107self->hitbox.top = (self->pushOffset >> 16) - 22;108109foreach_active(Player, player)110{111if (Player_CheckCollisionBox(player, self, &self->hitbox) == C_TOP) {112player->position.y += 0x20000;113self->beingPushed |= true;114115if (self->pushOffset >= 0x120000) {116player->collisionMode = 0;117player->onGround = false;118player->state = Player_State_Air;119player->velocity.y = -0xA0000;120121int32 anim = player->animator.animationID;122if (anim == ANI_WALK || (anim > ANI_AIR_WALK && anim <= ANI_DASH))123player->animationReserve = player->animator.animationID;124else125player->animationReserve = ANI_WALK;126127RSDK.SetSpriteAnimation(player->aniFrames, ANI_SPRING_DIAGONAL, &player->animator, true, 0);128RSDK.PlaySfx(PushSpring->sfxSpring, false, 255);129self->state = PushSpring_State_PushRecoil;130}131}132}133}134135void PushSpring_Collide_Bottom(void)136{137RSDK_THIS(PushSpring);138139self->hitbox.top = (self->pushOffset >> 16) - 22;140141foreach_active(Player, player)142{143int32 yvel = player->velocity.y;144145if (Player_CheckCollisionBox(player, self, &self->hitbox) == C_BOTTOM) {146if (yvel < 0) {147player->velocity.y = yvel + 0x3800;148player->position.y -= 0x20000;149self->beingPushed |= true;150}151152if (self->pushOffset >= 0x120000) {153player->collisionMode = 0;154player->onGround = false;155player->state = Player_State_Air;156player->velocity.y = 0xA0000;157RSDK.PlaySfx(PushSpring->sfxSpring, false, 255);158self->state = PushSpring_State_PushRecoil;159}160}161}162}163164void PushSpring_Collide_Left(void)165{166RSDK_THIS(PushSpring);167168self->hitbox.right = 22 - (self->pushOffset >> 16);169170foreach_active(Player, player)171{172if (Player_CheckCollisionBox(player, self, &self->hitbox) == C_LEFT) {173if (player->direction == FLIP_NONE)174player->position.x += 0x20000;175176if (player->right)177self->beingPushed |= true;178179if (self->state == PushSpring_State_PushRecoil) {180if (self->pushOffset > 0x10000) {181player->groundVel = -12 * self->pushOffset / 18;182player->velocity.x = player->groundVel;183player->collisionMode = 0;184player->controlLock = 16;185player->pushing = false;186player->direction = self->direction;187player->state = Player_State_Ground;188RSDK.PlaySfx(PushSpring->sfxSpring, false, 255);189}190}191}192}193}194195void PushSpring_Collide_Right(void)196{197RSDK_THIS(PushSpring);198199self->hitbox.right = 22 - (self->pushOffset >> 16);200201foreach_active(Player, player)202{203if (Player_CheckCollisionBox(player, self, &self->hitbox) == C_RIGHT) {204if (player->direction == FLIP_X)205player->position.x -= 0x20000;206207if (player->left)208self->beingPushed |= true;209210if (self->state == PushSpring_State_PushRecoil) {211if (self->pushOffset > 0x10000) {212player->groundVel = 12 * self->pushOffset / 18;213player->velocity.x = player->groundVel;214player->collisionMode = 0;215player->controlLock = 16;216player->pushing = false;217player->direction = self->direction;218player->state = Player_State_Ground;219RSDK.PlaySfx(PushSpring->sfxSpring, false, 255);220}221}222}223}224}225226void PushSpring_Draw_Top(void)227{228RSDK_THIS(PushSpring);229230Vector2 drawPos = self->position;231drawPos.y += self->pushOffset;232self->animator.frameID = 1;233RSDK.DrawSprite(&self->animator, &drawPos, false);234235drawPos.y = self->position.y + 2 * self->pushOffset / 3;236self->animator.frameID = 2;237RSDK.DrawSprite(&self->animator, &drawPos, false);238239drawPos.y = self->position.y + self->pushOffset / 3;240self->animator.frameID = 3;241RSDK.DrawSprite(&self->animator, &drawPos, false);242243self->animator.frameID = 4;244RSDK.DrawSprite(&self->animator, NULL, false);245}246247void PushSpring_Draw_Bottom(void)248{249RSDK_THIS(PushSpring);250251Vector2 drawPos = self->position;252drawPos.y -= self->pushOffset;253self->animator.frameID = 1;254RSDK.DrawSprite(&self->animator, &drawPos, false);255256drawPos.y = self->position.y - 2 * self->pushOffset / 3;257self->animator.frameID = 2;258RSDK.DrawSprite(&self->animator, &drawPos, false);259260drawPos.y = self->position.y - self->pushOffset / 3;261self->animator.frameID = 3;262RSDK.DrawSprite(&self->animator, &drawPos, false);263264self->animator.frameID = 4;265RSDK.DrawSprite(&self->animator, 0, false);266}267268void PushSpring_Draw_Left(void)269{270RSDK_THIS(PushSpring);271272Vector2 drawPos = self->position;273drawPos.x += self->pushOffset;274self->animator.frameID = 1;275RSDK.DrawSprite(&self->animator, &drawPos, false);276277drawPos.x = self->position.x + 2 * self->pushOffset / 3;278self->animator.frameID = 2;279RSDK.DrawSprite(&self->animator, &drawPos, false);280281drawPos.x = self->position.x + self->pushOffset / 3;282self->animator.frameID = 3;283RSDK.DrawSprite(&self->animator, &drawPos, false);284285self->animator.frameID = 4;286RSDK.DrawSprite(&self->animator, NULL, false);287}288289void PushSpring_Draw_Right(void)290{291RSDK_THIS(PushSpring);292293Vector2 drawPos = self->position;294drawPos.x -= self->pushOffset;295self->animator.frameID = 1;296RSDK.DrawSprite(&self->animator, &drawPos, false);297298drawPos.x = self->position.x - 2 * self->pushOffset / 3;299self->animator.frameID = 2;300RSDK.DrawSprite(&self->animator, &drawPos, false);301302drawPos.x = self->position.x - self->pushOffset / 3;303self->animator.frameID = 3;304RSDK.DrawSprite(&self->animator, &drawPos, false);305306self->animator.frameID = 4;307RSDK.DrawSprite(&self->animator, NULL, false);308}309310void PushSpring_State_WaitForPushed(void)311{312RSDK_THIS(PushSpring);313314if (self->beingPushed) {315self->timer = 0;316self->state = PushSpring_State_BeingPushed;317}318}319320void PushSpring_State_BeingPushed(void)321{322RSDK_THIS(PushSpring);323324if (self->beingPushed) {325self->pushOffset += self->groundVel;326327if (self->pushOffset < 0x120000) {328if (!(self->timer % 10))329RSDK.PlaySfx(PushSpring->sfxPush, false, 0xFF);330}331else {332self->pushOffset = 0x120000;333}334335++self->timer;336}337else {338self->state = PushSpring_State_PushRecoil;339}340}341342void PushSpring_State_PushRecoil(void)343{344RSDK_THIS(PushSpring);345346if (self->beingPushed) {347self->timer = 0;348self->state = PushSpring_State_BeingPushed;349}350else {351self->pushOffset -= 0x20000;352353if (self->pushOffset <= 0) {354self->pushOffset = 0;355self->state = PushSpring_State_WaitForPushed;356}357}358}359360#if GAME_INCLUDE_EDITOR361void PushSpring_EditorDraw(void)362{363RSDK_THIS(PushSpring);364365int32 dir = self->direction;366367RSDK.SetSpriteAnimation(PushSpring->aniFrames, self->type, &self->animator, false, 0);368369if (self->type == PUSHSPRING_V)370self->direction *= FLIP_Y;371372RSDK.DrawSprite(&self->animator, NULL, false);373374self->direction = dir;375}376377void PushSpring_EditorLoad(void)378{379PushSpring->aniFrames = RSDK.LoadSpriteAnimation("OOZ/PushSpring.bin", SCOPE_STAGE);380381RSDK_ACTIVE_VAR(PushSpring, type);382RSDK_ENUM_VAR("Vertical", PUSHSPRING_V);383RSDK_ENUM_VAR("Horizontal", PUSHSPRING_H);384385RSDK_ACTIVE_VAR(PushSpring, direction);386RSDK_ENUM_VAR("No Flip", FLIP_NONE);387RSDK_ENUM_VAR("Flipped", FLIP_X);388}389#endif390391void PushSpring_Serialize(void)392{393RSDK_EDITABLE_VAR(PushSpring, VAR_UINT8, type);394RSDK_EDITABLE_VAR(PushSpring, VAR_UINT8, direction);395}396397398