Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/MSZ/LightBulb.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: LightBulb Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectLightBulb *LightBulb;
11
12
void LightBulb_Update(void)
13
{
14
RSDK_THIS(LightBulb);
15
16
StateMachine_Run(self->state);
17
}
18
19
void LightBulb_LateUpdate(void) {}
20
21
void LightBulb_StaticUpdate(void) {}
22
23
void LightBulb_Draw(void)
24
{
25
RSDK_THIS(LightBulb);
26
27
self->alpha = 0x200;
28
self->inkEffect = INK_SUB;
29
self->animator.frameID = 0;
30
RSDK.DrawSprite(&self->animator, NULL, false);
31
32
self->inkEffect = INK_ADD;
33
self->alpha = (RSDK.Sin256(4 * Zone->timer) >> 2) + 192;
34
self->animator.frameID = 2;
35
RSDK.DrawSprite(&self->animator, NULL, false);
36
37
self->alpha = 0x200;
38
self->animator.frameID = 1;
39
RSDK.DrawSprite(&self->animator, NULL, false);
40
}
41
42
void LightBulb_Create(void *data)
43
{
44
RSDK_THIS(LightBulb);
45
46
self->drawGroup = (self->priority != LIGHTBULB_PRIO_HIGH) ? Zone->objectDrawGroup[0] : Zone->objectDrawGroup[1];
47
self->visible = true;
48
self->alpha = 0x100;
49
self->active = ACTIVE_BOUNDS;
50
self->updateRange.x = 0x400000;
51
self->updateRange.y = 0x400000;
52
self->state = LightBulb_State_CheckPlayerCollisions;
53
RSDK.SetSpriteAnimation(LightBulb->aniFrames, 0, &self->animator, true, 0);
54
}
55
56
void LightBulb_StageLoad(void)
57
{
58
LightBulb->aniFrames = RSDK.LoadSpriteAnimation("MSZ/LightBulb.bin", SCOPE_STAGE);
59
60
LightBulb->hitboxLightBulb.left = -12;
61
LightBulb->hitboxLightBulb.top = -12;
62
LightBulb->hitboxLightBulb.right = 12;
63
LightBulb->hitboxLightBulb.bottom = 12;
64
65
LightBulb->sfxBulbPop = RSDK.GetSfx("Stage/BulbPop.wav");
66
DEBUGMODE_ADD_OBJ(LightBulb);
67
}
68
69
void LightBulb_DebugSpawn(void)
70
{
71
RSDK_THIS(DebugMode);
72
73
CREATE_ENTITY(LightBulb, NULL, self->position.x, self->position.y);
74
}
75
76
void LightBulb_DebugDraw(void)
77
{
78
RSDK.SetSpriteAnimation(LightBulb->aniFrames, 0, &DebugMode->animator, true, 0);
79
RSDK.DrawSprite(&DebugMode->animator, NULL, false);
80
}
81
82
void LightBulb_State_CheckPlayerCollisions(void)
83
{
84
RSDK_THIS(LightBulb);
85
86
foreach_active(Player, player)
87
{
88
if (player->animator.animationID != ANI_HURT && Player_CheckCollisionTouch(player, self, &LightBulb->hitboxLightBulb)) {
89
RSDK.PlaySfx(LightBulb->sfxBulbPop, false, 255);
90
91
#if MANIA_USE_PLUS
92
if (player->state != Player_State_MightyHammerDrop) {
93
#endif
94
if (player->state == Player_State_FlyCarried)
95
RSDK_GET_ENTITY(SLOT_PLAYER2, Player)->flyCarryTimer = 30;
96
97
int32 anim = player->animator.animationID;
98
if (anim != ANI_FLY && anim != ANI_FLY_LIFT_TIRED) {
99
if (player->state != Player_State_TailsFlight) {
100
if (player->state != Player_State_DropDash)
101
player->state = Player_State_Air;
102
103
if (anim != ANI_JUMP && anim != ANI_JOG && anim != ANI_RUN && anim != ANI_DASH)
104
player->animator.animationID = ANI_WALK;
105
}
106
}
107
108
if (player->animator.animationID != ANI_FLY)
109
player->applyJumpCap = false;
110
111
if (player->velocity.y > -0x80000)
112
player->velocity.y = -0x80000;
113
114
player->onGround = false;
115
player->tileCollisions = TILECOLLISION_DOWN;
116
#if MANIA_USE_PLUS
117
}
118
#endif
119
CREATE_ENTITY(ScoreBonus, NULL, self->position.x, self->position.y)->animator.frameID = 16;
120
Player_GiveScore(player, 10);
121
CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_BOSSPUFF), self->position.x, self->position.y - 0x100000)->drawGroup =
122
Zone->objectDrawGroup[1];
123
124
for (int32 i = 0; i < 6; ++i) {
125
int32 x = self->position.x + RSDK.Rand(-0x80000, 0x80000);
126
int32 y = self->position.y + RSDK.Rand(-0x80000, 0x80000);
127
EntityDebris *debris = CREATE_ENTITY(Debris, NULL, x, y);
128
129
debris->state = Debris_State_Fall;
130
debris->gravityStrength = 0x4000;
131
debris->velocity.x = RSDK.Rand(0, 0x20000);
132
if (debris->position.x < self->position.x)
133
debris->velocity.x = -debris->velocity.x;
134
135
debris->velocity.y = RSDK.Rand(-0x40000, -0x10000);
136
debris->drawFX = FX_FLIP;
137
debris->direction = i & 3;
138
debris->drawGroup = Zone->objectDrawGroup[1];
139
RSDK.SetSpriteAnimation(ItemBox->aniFrames, 6, &debris->animator, true, RSDK.Rand(0, 4));
140
}
141
142
self->state = LightBulb_State_Destroyed;
143
self->visible = false;
144
self->active = ACTIVE_NORMAL;
145
}
146
}
147
}
148
149
void LightBulb_State_Destroyed(void)
150
{
151
RSDK_THIS(LightBulb);
152
153
Vector2 range = { TO_FIXED(256), TO_FIXED(256) };
154
if (!RSDK.CheckOnScreen(self, &range)) {
155
self->state = LightBulb_State_CheckPlayerCollisions;
156
self->visible = true;
157
self->active = ACTIVE_BOUNDS;
158
}
159
}
160
161
#if GAME_INCLUDE_EDITOR
162
void LightBulb_EditorDraw(void) { LightBulb_Draw(); }
163
164
void LightBulb_EditorLoad(void)
165
{
166
LightBulb->aniFrames = RSDK.LoadSpriteAnimation("MSZ/LightBulb.bin", SCOPE_STAGE);
167
168
RSDK_ACTIVE_VAR(LightBulb, priority);
169
RSDK_ENUM_VAR("High", LIGHTBULB_PRIO_HIGH);
170
RSDK_ENUM_VAR("Low", LIGHTBULB_PRIO_LOW);
171
}
172
#endif
173
174
void LightBulb_Serialize(void)
175
{
176
RSDK_EDITABLE_VAR(LightBulb, VAR_BOOL, respawn);
177
RSDK_EDITABLE_VAR(LightBulb, VAR_ENUM, priority);
178
}
179
180