Path: blob/master/SonicMania/Objects/MSZ/LightBulb.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: LightBulb Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectLightBulb *LightBulb;1011void LightBulb_Update(void)12{13RSDK_THIS(LightBulb);1415StateMachine_Run(self->state);16}1718void LightBulb_LateUpdate(void) {}1920void LightBulb_StaticUpdate(void) {}2122void LightBulb_Draw(void)23{24RSDK_THIS(LightBulb);2526self->alpha = 0x200;27self->inkEffect = INK_SUB;28self->animator.frameID = 0;29RSDK.DrawSprite(&self->animator, NULL, false);3031self->inkEffect = INK_ADD;32self->alpha = (RSDK.Sin256(4 * Zone->timer) >> 2) + 192;33self->animator.frameID = 2;34RSDK.DrawSprite(&self->animator, NULL, false);3536self->alpha = 0x200;37self->animator.frameID = 1;38RSDK.DrawSprite(&self->animator, NULL, false);39}4041void LightBulb_Create(void *data)42{43RSDK_THIS(LightBulb);4445self->drawGroup = (self->priority != LIGHTBULB_PRIO_HIGH) ? Zone->objectDrawGroup[0] : Zone->objectDrawGroup[1];46self->visible = true;47self->alpha = 0x100;48self->active = ACTIVE_BOUNDS;49self->updateRange.x = 0x400000;50self->updateRange.y = 0x400000;51self->state = LightBulb_State_CheckPlayerCollisions;52RSDK.SetSpriteAnimation(LightBulb->aniFrames, 0, &self->animator, true, 0);53}5455void LightBulb_StageLoad(void)56{57LightBulb->aniFrames = RSDK.LoadSpriteAnimation("MSZ/LightBulb.bin", SCOPE_STAGE);5859LightBulb->hitboxLightBulb.left = -12;60LightBulb->hitboxLightBulb.top = -12;61LightBulb->hitboxLightBulb.right = 12;62LightBulb->hitboxLightBulb.bottom = 12;6364LightBulb->sfxBulbPop = RSDK.GetSfx("Stage/BulbPop.wav");65DEBUGMODE_ADD_OBJ(LightBulb);66}6768void LightBulb_DebugSpawn(void)69{70RSDK_THIS(DebugMode);7172CREATE_ENTITY(LightBulb, NULL, self->position.x, self->position.y);73}7475void LightBulb_DebugDraw(void)76{77RSDK.SetSpriteAnimation(LightBulb->aniFrames, 0, &DebugMode->animator, true, 0);78RSDK.DrawSprite(&DebugMode->animator, NULL, false);79}8081void LightBulb_State_CheckPlayerCollisions(void)82{83RSDK_THIS(LightBulb);8485foreach_active(Player, player)86{87if (player->animator.animationID != ANI_HURT && Player_CheckCollisionTouch(player, self, &LightBulb->hitboxLightBulb)) {88RSDK.PlaySfx(LightBulb->sfxBulbPop, false, 255);8990#if MANIA_USE_PLUS91if (player->state != Player_State_MightyHammerDrop) {92#endif93if (player->state == Player_State_FlyCarried)94RSDK_GET_ENTITY(SLOT_PLAYER2, Player)->flyCarryTimer = 30;9596int32 anim = player->animator.animationID;97if (anim != ANI_FLY && anim != ANI_FLY_LIFT_TIRED) {98if (player->state != Player_State_TailsFlight) {99if (player->state != Player_State_DropDash)100player->state = Player_State_Air;101102if (anim != ANI_JUMP && anim != ANI_JOG && anim != ANI_RUN && anim != ANI_DASH)103player->animator.animationID = ANI_WALK;104}105}106107if (player->animator.animationID != ANI_FLY)108player->applyJumpCap = false;109110if (player->velocity.y > -0x80000)111player->velocity.y = -0x80000;112113player->onGround = false;114player->tileCollisions = TILECOLLISION_DOWN;115#if MANIA_USE_PLUS116}117#endif118CREATE_ENTITY(ScoreBonus, NULL, self->position.x, self->position.y)->animator.frameID = 16;119Player_GiveScore(player, 10);120CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_BOSSPUFF), self->position.x, self->position.y - 0x100000)->drawGroup =121Zone->objectDrawGroup[1];122123for (int32 i = 0; i < 6; ++i) {124int32 x = self->position.x + RSDK.Rand(-0x80000, 0x80000);125int32 y = self->position.y + RSDK.Rand(-0x80000, 0x80000);126EntityDebris *debris = CREATE_ENTITY(Debris, NULL, x, y);127128debris->state = Debris_State_Fall;129debris->gravityStrength = 0x4000;130debris->velocity.x = RSDK.Rand(0, 0x20000);131if (debris->position.x < self->position.x)132debris->velocity.x = -debris->velocity.x;133134debris->velocity.y = RSDK.Rand(-0x40000, -0x10000);135debris->drawFX = FX_FLIP;136debris->direction = i & 3;137debris->drawGroup = Zone->objectDrawGroup[1];138RSDK.SetSpriteAnimation(ItemBox->aniFrames, 6, &debris->animator, true, RSDK.Rand(0, 4));139}140141self->state = LightBulb_State_Destroyed;142self->visible = false;143self->active = ACTIVE_NORMAL;144}145}146}147148void LightBulb_State_Destroyed(void)149{150RSDK_THIS(LightBulb);151152Vector2 range = { TO_FIXED(256), TO_FIXED(256) };153if (!RSDK.CheckOnScreen(self, &range)) {154self->state = LightBulb_State_CheckPlayerCollisions;155self->visible = true;156self->active = ACTIVE_BOUNDS;157}158}159160#if GAME_INCLUDE_EDITOR161void LightBulb_EditorDraw(void) { LightBulb_Draw(); }162163void LightBulb_EditorLoad(void)164{165LightBulb->aniFrames = RSDK.LoadSpriteAnimation("MSZ/LightBulb.bin", SCOPE_STAGE);166167RSDK_ACTIVE_VAR(LightBulb, priority);168RSDK_ENUM_VAR("High", LIGHTBULB_PRIO_HIGH);169RSDK_ENUM_VAR("Low", LIGHTBULB_PRIO_LOW);170}171#endif172173void LightBulb_Serialize(void)174{175RSDK_EDITABLE_VAR(LightBulb, VAR_BOOL, respawn);176RSDK_EDITABLE_VAR(LightBulb, VAR_ENUM, priority);177}178179180