Path: blob/master/SonicMania/Objects/OOZ/GasPlatform.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: GasPlatform Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectGasPlatform *GasPlatform;1011void GasPlatform_Update(void)12{13RSDK_THIS(GasPlatform);1415if (self->state == Platform_State_Fixed) {16switch (self->type) {17case GASPLATFORM_INTERVAL:18if (!((Zone->timer + self->intervalOffset) % self->interval))19GasPlatform_PopPlatform();20break;2122case GASPLATFORM_CONTACT: {23int32 playerID = 0;24foreach_active(Player, player)25{26if ((1 << playerID) & self->stoodPlayers && !player->sidekick) {27if (abs(player->position.x - self->position.x) < 0x40000) {28player->position.x = self->position.x;29player->state = Player_State_Static;30player->velocity.x = 0;31player->groundVel = 0;3233GasPlatform_PopPlatform();34}35}3637++playerID;38}39break;40}41}42}4344Platform_Update();45}4647void GasPlatform_LateUpdate(void) {}4849void GasPlatform_StaticUpdate(void) {}5051void GasPlatform_Draw(void)52{53RSDK_THIS(GasPlatform);5455if (self->centerPos.y - self->drawPos.y > 0x180000)56RSDK.DrawSprite(&self->gasAnimator, NULL, false);5758RSDK.DrawSprite(&self->animator, &self->drawPos, false);59}6061void GasPlatform_Create(void *data)62{63RSDK_THIS(GasPlatform);6465if (!self->interval)66self->interval = 1;6768self->frameID = 2;69self->collision = PLATFORM_C_PLATFORM;70Platform_Create(NULL);71RSDK.SetSpriteAnimation(Platform->aniFrames, 2, &self->gasAnimator, true, 0);7273self->stateCollide = Platform_Collision_Solid;74self->state = Platform_State_Fixed;75}7677void GasPlatform_StageLoad(void)78{79GasPlatform->hitboxGas.top = -16;80GasPlatform->hitboxGas.left = -16;81GasPlatform->hitboxGas.right = 16;82GasPlatform->hitboxGas.bottom = 0;8384GasPlatform->range.x = 0x800000;85GasPlatform->range.y = 0x180000;8687GasPlatform->sfxGasPop = RSDK.GetSfx("OOZ/GasPop.wav");88GasPlatform->sfxSpring = RSDK.GetSfx("Global/Spring.wav");89}9091void GasPlatform_PopPlatform(void)92{93RSDK_THIS(GasPlatform);9495if (RSDK.CheckOnScreen(self, &GasPlatform->range))96RSDK.PlaySfx(GasPlatform->sfxGasPop, false, 255);9798self->active = ACTIVE_NORMAL;99self->velocity.y = -0x96800;100self->state = GasPlatform_State_Popped;101}102103void GasPlatform_State_Popped(void)104{105RSDK_THIS(GasPlatform);106107self->drawPos.y += self->velocity.y;108109if (self->drawPos.y >= self->centerPos.y) {110self->drawPos.y = self->centerPos.y;111if (self->velocity.y <= 0x10000) {112self->active = ACTIVE_BOUNDS;113self->state = Platform_State_Fixed;114return;115}116117self->velocity.y = -(self->velocity.y >> 2);118}119else {120self->velocity.y += 0x3800;121}122123if (self->centerPos.y - self->drawPos.y > 0x180000) {124RSDK.ProcessAnimation(&self->gasAnimator);125int32 storeX = self->position.x;126int32 storeY = self->position.y;127self->position.x = self->centerPos.x;128self->position.y = self->centerPos.y;129130foreach_active(Player, player)131{132if (Player_CheckCollisionTouch(player, self, &GasPlatform->hitboxGas))133Player_ElementHurt(player, self, SHIELD_FIRE);134}135136self->position.x = storeX;137self->position.y = storeY;138}139140if (self->type == GASPLATFORM_CONTACT) {141int32 playerID = 0;142foreach_active(Player, player)143{144int32 launchY = self->centerPos.y - 0x780000;145146if (self->position.y <= launchY) {147self->position.y = launchY;148if ((1 << playerID) & self->stoodPlayers) {149player->velocity.y = -0x100000;150player->state = Player_State_Air;151player->onGround = false;152RSDK.SetSpriteAnimation(player->aniFrames, ANI_SPRING_TWIRL, &player->animator, true, 0);153RSDK.PlaySfx(GasPlatform->sfxSpring, false, 255);154self->timer = 240;155self->state = GasPlatform_State_SpringCooldown;156}157}158else if ((1 << playerID) & self->stoodPlayers) {159if (abs(player->position.x - self->position.x) < 0x40000) {160player->position.x = self->position.x;161player->state = Player_State_Static;162player->velocity.x = 0;163player->groundVel = 0;164}165}166167++playerID;168}169}170}171172void GasPlatform_State_SpringCooldown(void)173{174RSDK_THIS(GasPlatform);175176RSDK.ProcessAnimation(&self->gasAnimator);177178int32 storeX = self->position.x;179int32 storeY = self->position.y;180181self->position.x = self->centerPos.x;182self->position.y = self->centerPos.y;183foreach_active(Player, player)184{185if (Player_CheckCollisionTouch(player, self, &GasPlatform->hitboxGas))186Player_ElementHurt(player, self, SHIELD_FIRE);187}188189self->position.x = storeX;190self->position.y = storeY;191192if (!--self->timer) {193self->velocity.y = 0;194self->state = GasPlatform_State_Popped;195}196}197198void GasPlatform_State_Shaking(void)199{200RSDK_THIS(GasPlatform);201202self->drawPos.x = (RSDK.Rand(-1, 1) << 16) + self->centerPos.x;203self->drawPos.y = (RSDK.Rand(-2, 2) << 16) + self->centerPos.y;204205if (self->timer <= 0) {206RSDK.PlaySfx(GasPlatform->sfxGasPop, false, 255);207self->active = ACTIVE_NORMAL;208self->velocity.y = -0x8C000;209self->state = GasPlatform_State_Popped;210}211else {212self->timer--;213}214}215216#if GAME_INCLUDE_EDITOR217void GasPlatform_EditorDraw(void)218{219RSDK_THIS(GasPlatform);220221self->drawPos = self->position;222223GasPlatform_Draw();224}225226void GasPlatform_EditorLoad(void)227{228RSDK_ACTIVE_VAR(GasPlatform, type);229RSDK_ENUM_VAR("Pop On Interval", GASPLATFORM_INTERVAL);230RSDK_ENUM_VAR("Pop On Contact", GASPLATFORM_CONTACT); // never used in mania afaik, it's used in S2 though231}232#endif233234void GasPlatform_Serialize(void)235{236RSDK_EDITABLE_VAR(GasPlatform, VAR_ENUM, type);237RSDK_EDITABLE_VAR(GasPlatform, VAR_ENUM, childCount);238RSDK_EDITABLE_VAR(GasPlatform, VAR_UINT16, interval);239RSDK_EDITABLE_VAR(GasPlatform, VAR_UINT16, intervalOffset);240}241242243