Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Global/NoSwap.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: NoSwap Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
#if MANIA_USE_PLUS
11
ObjectNoSwap *NoSwap;
12
13
void NoSwap_Update(void)
14
{
15
RSDK_THIS(NoSwap);
16
17
if (Player->playerCount) {
18
int32 cnt = 0;
19
for (int32 p = 0; p < Player->playerCount; ++p) {
20
EntityPlayer *player = RSDK_GET_ENTITY(p, Player);
21
22
if (!Player_CheckValidState(player)) {
23
if (self->noDeathSwap) {
24
if (player->state == Player_State_Death || player->state == Player_State_Drown) {
25
Player->cantSwap = true;
26
++NoSwap->counter;
27
}
28
}
29
}
30
else {
31
self->playerPos.x = player->position.x;
32
self->playerPos.y = player->position.y;
33
}
34
35
if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {
36
if (self->always) {
37
Player->cantSwap = true;
38
++NoSwap->counter;
39
}
40
else {
41
++cnt;
42
}
43
}
44
}
45
46
if (cnt == 1) {
47
Player->cantSwap = true;
48
++NoSwap->counter;
49
}
50
}
51
}
52
53
void NoSwap_LateUpdate(void) {}
54
55
void NoSwap_StaticUpdate(void)
56
{
57
if (NoSwap->counter)
58
NoSwap->counter = 0;
59
else
60
Player->cantSwap = false;
61
}
62
63
void NoSwap_Draw(void)
64
{
65
RSDK_THIS(NoSwap);
66
67
RSDK.DrawLine(self->position.x - 16 * self->size.x, self->position.y - 16 * self->size.y, self->position.x + 16 * self->size.x,
68
self->position.y - 16 * self->size.y, 0xFF0000, 0xFF, INK_NONE, false);
69
RSDK.DrawLine(self->position.x - 16 * self->size.x, self->position.y + 16 * self->size.y, self->position.x + 16 * self->size.x,
70
self->position.y + 16 * self->size.y, 0xFF0000, 0xFF, INK_NONE, false);
71
RSDK.DrawLine(self->position.x - 16 * self->size.x, self->position.y - 16 * self->size.y, self->position.x - 16 * self->size.x,
72
self->position.y + 16 * self->size.y, 0xFF0000, 0xFF, INK_NONE, false);
73
RSDK.DrawLine(self->position.x + 16 * self->size.x, self->position.y - 16 * self->size.y, self->position.x + 16 * self->size.x,
74
self->position.y + 16 * self->size.y, 0xFF0000, 0xFF, INK_NONE, false);
75
}
76
77
void NoSwap_Create(void *data)
78
{
79
RSDK_THIS(NoSwap);
80
81
if (!SceneInfo->inEditor) {
82
self->updateRange.x = 16 * self->size.x;
83
self->updateRange.y = 16 * self->size.y;
84
85
self->hitbox.left = -(self->size.x >> 12);
86
self->hitbox.top = -(self->size.y >> 12);
87
self->hitbox.right = (self->size.x >> 12);
88
self->hitbox.bottom = (self->size.y >> 12);
89
self->active = ACTIVE_BOUNDS;
90
}
91
}
92
93
void NoSwap_StageLoad(void) { NoSwap->active = ACTIVE_ALWAYS; }
94
95
#if GAME_INCLUDE_EDITOR
96
void NoSwap_EditorDraw(void)
97
{
98
RSDK_THIS(NoSwap);
99
100
self->updateRange.x = TILE_SIZE * self->size.x;
101
self->updateRange.y = TILE_SIZE * self->size.y;
102
103
if (showGizmos()) {
104
RSDK_DRAWING_OVERLAY(true);
105
106
NoSwap_Draw();
107
108
RSDK_DRAWING_OVERLAY(false);
109
}
110
111
RSDK.SetSpriteAnimation(NoSwap->aniFrames, 0, &self->unusedAnimator1, true, 8);
112
RSDK.DrawSprite(&self->unusedAnimator1, NULL, false);
113
}
114
115
void NoSwap_EditorLoad(void) { NoSwap->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE); }
116
#endif
117
118
void NoSwap_Serialize(void)
119
{
120
RSDK_EDITABLE_VAR(NoSwap, VAR_VECTOR2, size);
121
RSDK_EDITABLE_VAR(NoSwap, VAR_BOOL, always);
122
RSDK_EDITABLE_VAR(NoSwap, VAR_BOOL, noDeathSwap);
123
}
124
#endif
125
126