Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/TMZ/TMZBarrier.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: TMZBarrier Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectTMZBarrier *TMZBarrier;
11
12
void TMZBarrier_Update(void)
13
{
14
RSDK_THIS(TMZBarrier);
15
16
if (self->cleared) {
17
TMZBarrier->clearedBarriers |= 1 << self->iD;
18
19
if (self->type)
20
RSDK.CopyTileLayer(Zone->fgLayer[0], self->position.x >> 20, self->position.y >> 20, Zone->moveLayer, 59, 32, 2, 4);
21
else
22
RSDK.CopyTileLayer(Zone->fgLayer[0], self->position.x >> 20, self->position.y >> 20, Zone->moveLayer, 56, 32, 2, 9);
23
24
destroyEntity(self);
25
}
26
}
27
28
void TMZBarrier_LateUpdate(void) {}
29
30
void TMZBarrier_StaticUpdate(void)
31
{
32
globals->tempFlags = TMZBarrier->clearedBarriers;
33
34
if (TMZBarrier->postID != StarPost->postIDs[0]) {
35
TMZBarrier->postID = StarPost->postIDs[0];
36
globals->restartFlags = TMZBarrier->clearedBarriers;
37
}
38
}
39
40
void TMZBarrier_Draw(void) {}
41
42
void TMZBarrier_Create(void *data)
43
{
44
RSDK_THIS(TMZBarrier);
45
46
if (!SceneInfo->inEditor)
47
self->active = ACTIVE_NORMAL;
48
}
49
50
void TMZBarrier_StageLoad(void)
51
{
52
if (SceneInfo->minutes || SceneInfo->seconds || SceneInfo->milliseconds) {
53
if (SceneInfo->minutes != globals->tempMinutes || SceneInfo->seconds != globals->tempSeconds
54
|| SceneInfo->milliseconds != globals->tempMilliseconds) {
55
TMZBarrier->clearedBarriers = globals->restartFlags;
56
}
57
else {
58
TMZBarrier->clearedBarriers = globals->tempFlags;
59
}
60
61
TMZBarrier->postID = StarPost->postIDs[0];
62
foreach_all(TMZBarrier, barrier)
63
{
64
if ((1 << barrier->iD) & TMZBarrier->clearedBarriers) {
65
if (barrier->type)
66
RSDK.CopyTileLayer(Zone->fgLayer[0], barrier->position.x >> 20, barrier->position.y >> 20, Zone->moveLayer, 59, 32, 2, 4);
67
else
68
RSDK.CopyTileLayer(Zone->fgLayer[0], barrier->position.x >> 20, barrier->position.y >> 20, Zone->moveLayer, 56, 32, 2, 9);
69
70
destroyEntity(barrier);
71
}
72
}
73
}
74
else {
75
TMZBarrier->postID = 0;
76
TMZBarrier->clearedBarriers = 0;
77
78
globals->restartFlags = 0;
79
globals->tempFlags = 0;
80
}
81
}
82
83
#if GAME_INCLUDE_EDITOR
84
void TMZBarrier_EditorDraw(void)
85
{
86
RSDK_THIS(TMZBarrier);
87
88
Animator animator;
89
RSDK.SetSpriteAnimation(TMZBarrier->postID, 0, &animator, true, self->type ? 3 : 4);
90
91
RSDK.DrawSprite(&animator, NULL, false);
92
93
if (showGizmos()) {
94
EntityWarpDoor *taggedDoor = NULL;
95
foreach_all(WarpDoor, door)
96
{
97
if (door->tag == self->warpTag) {
98
taggedDoor = door;
99
foreach_break;
100
}
101
}
102
103
if (taggedDoor) {
104
RSDK_DRAWING_OVERLAY(true);
105
if (taggedDoor) {
106
DrawHelpers_DrawArrow(taggedDoor->position.x, taggedDoor->position.y, self->position.x, self->position.y, 0xFFFF00, INK_NONE, 0xFF);
107
}
108
RSDK_DRAWING_OVERLAY(false);
109
}
110
}
111
}
112
113
void TMZBarrier_EditorLoad(void)
114
{
115
// borrowing this for "aniFrames" storage
116
TMZBarrier->postID = RSDK.LoadSpriteAnimation("TMZ1/Platform.bin", SCOPE_STAGE);
117
118
RSDK_ACTIVE_VAR(TMZBarrier, type);
119
RSDK_ENUM_VAR("Long", TMZBARRIER_LONG);
120
RSDK_ENUM_VAR("Short", TMZBARRIER_SHORT);
121
122
RSDK_ACTIVE_VAR(TMZBarrier, iD);
123
RSDK_ENUM_VAR("Barrier 1", 0);
124
RSDK_ENUM_VAR("Barrier 2", 1);
125
RSDK_ENUM_VAR("Barrier 3", 2);
126
RSDK_ENUM_VAR("Barrier 4", 3);
127
}
128
#endif
129
130
void TMZBarrier_Serialize(void)
131
{
132
RSDK_EDITABLE_VAR(TMZBarrier, VAR_UINT8, type);
133
RSDK_EDITABLE_VAR(TMZBarrier, VAR_UINT8, warpTag);
134
RSDK_EDITABLE_VAR(TMZBarrier, VAR_UINT8, iD);
135
}
136
137