Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/HCZ/Pointdexter.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Pointdexter Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPointdexter *Pointdexter;
11
12
void Pointdexter_Update(void)
13
{
14
RSDK_THIS(Pointdexter);
15
16
StateMachine_Run(self->state);
17
}
18
19
void Pointdexter_LateUpdate(void) {}
20
21
void Pointdexter_StaticUpdate(void) {}
22
23
void Pointdexter_Draw(void)
24
{
25
RSDK_THIS(Pointdexter);
26
27
RSDK.DrawSprite(&self->animator, NULL, false);
28
}
29
30
void Pointdexter_Create(void *data)
31
{
32
RSDK_THIS(Pointdexter);
33
34
self->visible = true;
35
self->drawGroup = Zone->objectDrawGroup[0];
36
self->drawFX |= FX_FLIP;
37
self->startPos = self->position;
38
self->startDir = self->direction;
39
self->active = ACTIVE_BOUNDS;
40
self->updateRange.x = 0x800000;
41
self->updateRange.y = 0x800000;
42
43
RSDK.SetSpriteAnimation(Pointdexter->aniFrames, 0, &self->animator, true, 0);
44
self->state = Pointdexter_State_Init;
45
}
46
47
void Pointdexter_StageLoad(void)
48
{
49
if (RSDK.CheckSceneFolder("HCZ"))
50
Pointdexter->aniFrames = RSDK.LoadSpriteAnimation("HCZ/Pointdexter.bin", SCOPE_STAGE);
51
52
Pointdexter->hitbox.left = -16;
53
Pointdexter->hitbox.top = -6;
54
Pointdexter->hitbox.right = 16;
55
Pointdexter->hitbox.bottom = 6;
56
57
DEBUGMODE_ADD_OBJ(Pointdexter);
58
}
59
60
void Pointdexter_DebugSpawn(void)
61
{
62
RSDK_THIS(DebugMode);
63
64
CREATE_ENTITY(Pointdexter, NULL, self->position.x, self->position.y);
65
}
66
67
void Pointdexter_DebugDraw(void)
68
{
69
RSDK.SetSpriteAnimation(Pointdexter->aniFrames, 0, &DebugMode->animator, true, 0);
70
RSDK.DrawSprite(&DebugMode->animator, NULL, false);
71
}
72
73
void Pointdexter_CheckOffScreen(void)
74
{
75
RSDK_THIS(Pointdexter);
76
77
if (!RSDK.CheckOnScreen(self, NULL) && !RSDK.CheckPosOnScreen(&self->startPos, &self->updateRange)) {
78
self->position = self->startPos;
79
self->direction = self->startDir;
80
Pointdexter_Create(NULL);
81
}
82
}
83
84
void Pointdexter_CheckPlayerCollisions(void)
85
{
86
RSDK_THIS(Pointdexter);
87
88
foreach_active(Player, player)
89
{
90
if (Player_CheckBadnikTouch(player, self, &Pointdexter->hitbox)) {
91
if (self->animator.frameID != 2 || player->invincibleTimer || player->blinkTimer
92
#if MANIA_USE_PLUS
93
|| player->state == Player_State_MightyHammerDrop
94
#endif
95
) {
96
Player_CheckBadnikBreak(player, self, true);
97
}
98
#if MANIA_USE_PLUS
99
else if (!Player_CheckMightyUnspin(player, 0x200, 2, &player->uncurlTimer))
100
#else
101
else
102
#endif
103
Player_Hurt(player, self);
104
}
105
}
106
}
107
108
void Pointdexter_State_Init(void)
109
{
110
RSDK_THIS(Pointdexter);
111
112
if (self->position.y >= Water->waterLevel) {
113
self->active = ACTIVE_NORMAL;
114
self->velocity.x = self->direction == FLIP_NONE ? -0x4000 : 0x4000;
115
self->timer = 0;
116
117
self->state = Pointdexter_State_Swimming;
118
Pointdexter_State_Swimming();
119
}
120
else {
121
destroyEntity(self);
122
}
123
}
124
125
void Pointdexter_State_Swimming(void)
126
{
127
RSDK_THIS(Pointdexter);
128
129
self->position.x += self->velocity.x;
130
131
if (!--self->timer) {
132
self->direction ^= FLIP_X;
133
self->velocity.x = -self->velocity.x;
134
self->timer = 0;
135
}
136
137
self->position.y += 32 * RSDK.Sin256(self->angle);
138
self->angle = (self->angle + 2) & 0xFF;
139
140
RSDK.ProcessAnimation(&self->animator);
141
142
Pointdexter_CheckPlayerCollisions();
143
Pointdexter_CheckOffScreen();
144
}
145
146
#if GAME_INCLUDE_EDITOR
147
void Pointdexter_EditorDraw(void) { Pointdexter_Draw(); }
148
149
void Pointdexter_EditorLoad(void)
150
{
151
Pointdexter->aniFrames = RSDK.LoadSpriteAnimation("HCZ/Pointdexter.bin", SCOPE_STAGE);
152
153
RSDK_ACTIVE_VAR(Pointdexter, direction);
154
RSDK_ENUM_VAR("Left", FLIP_NONE);
155
RSDK_ENUM_VAR("Right", FLIP_X);
156
}
157
#endif
158
159
void Pointdexter_Serialize(void) { RSDK_EDITABLE_VAR(Pointdexter, VAR_UINT8, direction); }
160
161