Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/FBZ/LightBarrier.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: LightBarrier Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectLightBarrier *LightBarrier;
11
12
void LightBarrier_Update(void) {}
13
14
void LightBarrier_LateUpdate(void)
15
{
16
RSDK_THIS(LightBarrier);
17
18
if (self->enabled) {
19
if (self->barrierAlpha < 0xA0)
20
self->barrierAlpha += 4;
21
22
foreach_active(Player, player)
23
{
24
if (self->position.x > (ScreenInfo->position.x + ScreenInfo->center.x) << 16 || player->velocity.x < 0)
25
Player_CheckCollisionBox(player, self, &self->hitboxBarrier);
26
}
27
28
self->timer = (self->timer + 2) & 0x3F;
29
self->alpha = self->barrierAlpha + (RSDK.Sin256(2 * Zone->timer) >> 3);
30
}
31
}
32
33
void LightBarrier_StaticUpdate(void) {}
34
35
void LightBarrier_Draw(void)
36
{
37
RSDK_THIS(LightBarrier);
38
39
Vector2 drawPos = self->position;
40
self->inkEffect = INK_NONE;
41
self->direction = FLIP_NONE;
42
43
drawPos.y += self->size << 15;
44
RSDK.DrawSprite(&self->emitterAnimator, &drawPos, false);
45
46
drawPos.y -= self->size << 16;
47
self->direction = FLIP_Y;
48
RSDK.DrawSprite(&self->emitterAnimator, &drawPos, false);
49
50
self->direction = FLIP_NONE;
51
if (self->enabled) {
52
self->inkEffect = INK_ADD;
53
int32 timer = self->timer;
54
SpriteFrame *frame = RSDK.GetFrame(LightBarrier->aniFrames, 0, 1);
55
drawPos.y += 0x80000;
56
57
int32 size = self->size - 8;
58
for (int32 i = 8; i < size;) {
59
int32 height = 64 - timer;
60
if (64 - timer + i > size)
61
height = size - i;
62
63
frame->sprY = timer + (self->sprY & 0xFFFF);
64
frame->height = height;
65
RSDK.DrawSprite(&self->barrierAnimator, &drawPos, false);
66
67
i += height;
68
drawPos.y += height << 16;
69
timer = (timer + height) & 0x3F;
70
}
71
}
72
}
73
74
void LightBarrier_Create(void *data)
75
{
76
RSDK_THIS(LightBarrier);
77
78
self->drawFX = FX_FLIP;
79
if (!SceneInfo->inEditor) {
80
self->active = ACTIVE_BOUNDS;
81
self->visible = true;
82
self->drawGroup = Zone->objectDrawGroup[1];
83
self->updateRange.x = 0x800000;
84
self->updateRange.y = self->size << 15;
85
86
RSDK.SetSpriteAnimation(LightBarrier->aniFrames, 0, &self->emitterAnimator, true, 0);
87
RSDK.SetSpriteAnimation(LightBarrier->aniFrames, 0, &self->barrierAnimator, true, 1);
88
SpriteFrame *frame = RSDK.GetFrame(LightBarrier->aniFrames, 0, 1);
89
self->sprY = frame->sprY;
90
91
self->hitboxBarrier.left = -8;
92
self->hitboxBarrier.top = -(self->size >> 1);
93
self->hitboxBarrier.right = 8;
94
self->hitboxBarrier.bottom = self->size >> 1;
95
96
if (self->enabled)
97
self->barrierAlpha = 0xA0;
98
}
99
}
100
101
void LightBarrier_StageLoad(void) { LightBarrier->aniFrames = RSDK.LoadSpriteAnimation("FBZ/LightBarrier.bin", SCOPE_STAGE); }
102
103
#if GAME_INCLUDE_EDITOR
104
void LightBarrier_EditorDraw(void)
105
{
106
RSDK_THIS(LightBarrier);
107
self->alpha = 0xA0;
108
109
self->updateRange.x = 0x800000;
110
self->updateRange.y = self->size << 15;
111
112
RSDK.SetSpriteAnimation(LightBarrier->aniFrames, 0, &self->emitterAnimator, true, 0);
113
RSDK.SetSpriteAnimation(LightBarrier->aniFrames, 0, &self->barrierAnimator, true, 1);
114
SpriteFrame *frame = RSDK.GetFrame(LightBarrier->aniFrames, 0, 1);
115
self->sprY = frame->sprY;
116
117
LightBarrier_Draw();
118
119
frame->sprY = self->sprY;
120
}
121
122
void LightBarrier_EditorLoad(void) { LightBarrier->aniFrames = RSDK.LoadSpriteAnimation("FBZ/LightBarrier.bin", SCOPE_STAGE); }
123
#endif
124
125
void LightBarrier_Serialize(void)
126
{
127
RSDK_EDITABLE_VAR(LightBarrier, VAR_ENUM, size);
128
RSDK_EDITABLE_VAR(LightBarrier, VAR_BOOL, enabled);
129
}
130
131