Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Global/BoundsMarker.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: BoundsMarker Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectBoundsMarker *BoundsMarker;
11
12
void BoundsMarker_Update(void)
13
{
14
RSDK_THIS(BoundsMarker);
15
16
for (int32 p = 0; p < Player->playerCount; ++p) {
17
EntityPlayer *player = RSDK_GET_ENTITY(p, Player);
18
BoundsMarker_ApplyBounds(player, self, false);
19
}
20
}
21
22
void BoundsMarker_LateUpdate(void) {}
23
24
void BoundsMarker_StaticUpdate(void) {}
25
26
void BoundsMarker_Draw(void) {}
27
28
void BoundsMarker_Create(void *data)
29
{
30
RSDK_THIS(BoundsMarker);
31
32
if (!SceneInfo->inEditor) {
33
if (self->vsDisable && globals->gameMode == MODE_COMPETITION) {
34
destroyEntity(self);
35
}
36
else {
37
self->active = ACTIVE_XBOUNDS;
38
self->width = self->width ? (self->width << 15) : (48 << 15);
39
self->updateRange.x += self->width << 15;
40
41
for (int32 p = 0; p < Player->playerCount; ++p) {
42
EntityPlayer *player = RSDK_GET_ENTITY(p, Player);
43
BoundsMarker_ApplyBounds(player, self, true);
44
}
45
}
46
}
47
}
48
49
void BoundsMarker_StageLoad(void) {}
50
51
void BoundsMarker_ApplyBounds(EntityPlayer *player, EntityBoundsMarker *marker, bool32 setPos)
52
{
53
uint16 playerID = RSDK.GetEntitySlot(player);
54
55
if (Player_CheckValidState(player) || player->classID == DebugMode->classID) {
56
if (abs(marker->position.x - player->position.x) < marker->width) {
57
switch (marker->type) {
58
case BOUNDSMARKER_ANY_Y:
59
Zone->playerBoundsB[playerID] = marker->position.y;
60
Zone->cameraBoundsB[playerID] = FROM_FIXED(Zone->playerBoundsB[playerID]);
61
Zone->deathBoundary[playerID] = marker->position.y;
62
break;
63
64
case BOUNDSMARKER_ABOVE_Y:
65
if (player->position.y < marker->position.y - (marker->offset << 16)) {
66
Zone->playerBoundsB[playerID] = marker->position.y;
67
Zone->cameraBoundsB[playerID] = FROM_FIXED(Zone->playerBoundsB[playerID]);
68
Zone->deathBoundary[playerID] = marker->position.y;
69
}
70
break;
71
72
case BOUNDSMARKER_BELOW_Y:
73
if (player->position.y > marker->position.y + (marker->offset << 16)) {
74
Zone->playerBoundsT[playerID] = marker->position.y;
75
Zone->cameraBoundsT[playerID] = FROM_FIXED(Zone->playerBoundsT[playerID]);
76
}
77
break;
78
79
case BOUNDSMARKER_BELOW_Y_ANY:
80
Zone->playerBoundsT[playerID] = marker->position.y;
81
Zone->cameraBoundsT[playerID] = FROM_FIXED(Zone->playerBoundsT[playerID]);
82
break;
83
84
default: break;
85
}
86
}
87
88
if (setPos) {
89
EntityCamera *camera = player->camera;
90
if (camera) {
91
camera->boundsL = Zone->cameraBoundsL[playerID];
92
camera->boundsR = Zone->cameraBoundsR[playerID];
93
camera->boundsT = Zone->cameraBoundsT[playerID];
94
camera->boundsB = Zone->cameraBoundsB[playerID];
95
}
96
}
97
}
98
}
99
void BoundsMarker_ApplyAllBounds(EntityPlayer *player, bool32 setPos)
100
{
101
if (Player_CheckValidState(player) || player->classID == DebugMode->classID) {
102
foreach_all(BoundsMarker, entity) { BoundsMarker_ApplyBounds(player, entity, setPos); }
103
}
104
}
105
106
#if GAME_INCLUDE_EDITOR
107
void BoundsMarker_EditorDraw(void)
108
{
109
RSDK_THIS(BoundsMarker);
110
111
Animator animator;
112
RSDK.SetSpriteAnimation(BoundsMarker->aniFrames, 0, &animator, true, 2);
113
RSDK.DrawSprite(&animator, NULL, false);
114
115
int32 w = self->width ? (self->width << 15) : (48 << 15);
116
self->updateRange.x = w;
117
118
// Bounds
119
RSDK_DRAWING_OVERLAY(true);
120
121
RSDK.DrawLine(self->position.x - w, self->position.y, self->position.x + w, self->position.y, 0xFFFF00, 0xFF, INK_NONE, false);
122
if (self->type == BOUNDSMARKER_ABOVE_Y) {
123
RSDK.DrawLine(self->position.x + w, self->position.y - (self->offset << 16), self->position.x + w, self->position.y - (self->offset << 16),
124
0xFFFF00, 0x80, INK_BLEND, false);
125
}
126
else if (self->type == BOUNDSMARKER_BELOW_Y) {
127
RSDK.DrawLine(self->position.x + w, self->position.y + (self->offset << 16), self->position.x + w, self->position.y + (self->offset << 16),
128
0xFFFF00, 0x80, INK_BLEND, false);
129
}
130
131
RSDK_DRAWING_OVERLAY(false);
132
}
133
134
void BoundsMarker_EditorLoad(void)
135
{
136
BoundsMarker->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE);
137
138
RSDK_ACTIVE_VAR(BoundsMarker, type);
139
RSDK_ENUM_VAR("Any Y", BOUNDSMARKER_ANY_Y);
140
RSDK_ENUM_VAR("Above Y", BOUNDSMARKER_ABOVE_Y);
141
RSDK_ENUM_VAR("Below Y", BOUNDSMARKER_BELOW_Y);
142
RSDK_ENUM_VAR("Below Y Any", BOUNDSMARKER_BELOW_Y_ANY);
143
}
144
#endif
145
146
void BoundsMarker_Serialize(void)
147
{
148
RSDK_EDITABLE_VAR(BoundsMarker, VAR_UINT8, type);
149
RSDK_EDITABLE_VAR(BoundsMarker, VAR_ENUM, width);
150
RSDK_EDITABLE_VAR(BoundsMarker, VAR_BOOL, vsDisable);
151
RSDK_EDITABLE_VAR(BoundsMarker, VAR_ENUM, offset);
152
}
153
154