Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Unused/TargetBumper.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: TargetBumper Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectTargetBumper *TargetBumper = NULL;
11
12
void TargetBumper_Update(void)
13
{
14
RSDK_THIS(TargetBumper);
15
StateMachine_Run(self->state);
16
}
17
18
void TargetBumper_LateUpdate(void) {}
19
20
void TargetBumper_StaticUpdate(void) {}
21
22
void TargetBumper_Draw(void)
23
{
24
RSDK_THIS(TargetBumper);
25
RSDK.DrawSprite(&self->animator, NULL, false);
26
}
27
28
void TargetBumper_Create(void *data)
29
{
30
RSDK_THIS(TargetBumper);
31
self->visible = true;
32
self->drawFX |= FX_FLIP;
33
self->drawGroup = Zone->objectDrawGroup[0];
34
self->startPos = self->position;
35
self->active = ACTIVE_BOUNDS;
36
self->updateRange.x = 0x400000;
37
self->updateRange.y = 0x400000;
38
RSDK.SetSpriteAnimation(TargetBumper->aniFrames, self->type, &self->animator, true, 0);
39
self->animator.frameID = self->hitCount;
40
self->state = TargetBumper_State_Idle;
41
}
42
43
void TargetBumper_StageLoad(void)
44
{
45
TargetBumper->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/TargetBumper.bin", SCOPE_STAGE);
46
47
DEBUGMODE_ADD_OBJ(TargetBumper);
48
}
49
50
void TargetBumper_DebugSpawn(void)
51
{
52
RSDK_THIS(TargetBumper);
53
CREATE_ENTITY(TargetBumper, NULL, self->position.x, self->position.y);
54
}
55
56
void TargetBumper_DebugDraw(void)
57
{
58
RSDK.SetSpriteAnimation(TargetBumper->aniFrames, 0, &DebugMode->animator, true, 0);
59
RSDK.DrawSprite(&DebugMode->animator, NULL, false);
60
}
61
62
void TargetBumper_CheckPlayerCollisions(void)
63
{
64
RSDK_THIS(TargetBumper);
65
66
Hitbox hitboxBumper;
67
switch (self->type) {
68
case TARGETBUMP_HORIZONTAL:
69
hitboxBumper.left = -14;
70
hitboxBumper.top = -4;
71
hitboxBumper.right = 14;
72
hitboxBumper.bottom = 4;
73
break;
74
75
case TARGETBUMP_VERTICAL:
76
hitboxBumper.left = -4;
77
hitboxBumper.top = -14;
78
hitboxBumper.right = 4;
79
hitboxBumper.bottom = 14;
80
break;
81
82
case TARGETBUMP_DIAGONAL:
83
hitboxBumper.left = -8;
84
hitboxBumper.top = -8;
85
hitboxBumper.right = 8;
86
hitboxBumper.bottom = 8;
87
break;
88
}
89
90
foreach_active(Player, player)
91
{
92
if (Player_CheckCollisionTouch(player, self, &hitboxBumper) && player->animator.animationID != ANI_HURT) {
93
self->curPos = self->startPos;
94
self->state = TargetBumper_State_Hit;
95
self->active = ACTIVE_NORMAL;
96
97
switch (self->type) {
98
case TARGETBUMP_HORIZONTAL:
99
if (player->position.y <= self->position.y) {
100
player->velocity.y = -0x70000;
101
self->curPos.y += 0x20000;
102
}
103
else {
104
player->velocity.y = 0x70000;
105
self->curPos.y -= 0x20000;
106
}
107
break;
108
109
case TARGETBUMP_VERTICAL:
110
if (player->position.x <= self->position.x) {
111
player->velocity.x = -0x70000;
112
self->curPos.x += 0x20000;
113
}
114
else {
115
player->velocity.x = 0x70000;
116
self->curPos.x -= 0x20000;
117
}
118
break;
119
120
case TARGETBUMP_DIAGONAL: {
121
int32 angle = 96;
122
if (self->direction)
123
angle = 32;
124
125
int32 ang2 = 0;
126
uint8 atan = RSDK.ATan2(player->velocity.x, player->velocity.y);
127
int32 ang = atan - angle;
128
if (atan - angle >= 0)
129
ang2 = ang;
130
else
131
ang2 = -ang;
132
133
if (ang2 < 0x40) {
134
if (ang2 < 0x38) {
135
angle -= ang;
136
angle &= 0xFF;
137
}
138
139
if ((self->direction & FLIP_X))
140
self->curPos.x += 0x20000;
141
else
142
self->curPos.x -= 0x20000;
143
144
self->curPos.y += 0x20000;
145
}
146
else {
147
angle += 0x80;
148
if ((0x80 - ang2) < 0x38) {
149
angle -= ang;
150
angle &= 0xFF;
151
}
152
153
if ((self->direction & FLIP_X))
154
self->curPos.x -= 0x20000;
155
else
156
self->curPos.x += 0x20000;
157
158
self->curPos.y -= 0x20000;
159
}
160
player->velocity.x = -0x700 * RSDK.Cos256(angle);
161
player->velocity.y = -0x700 * RSDK.Sin256(angle);
162
break;
163
}
164
}
165
166
if (player->state == Player_State_FlyCarried)
167
RSDK_GET_ENTITY(SLOT_PLAYER2, Player)->flyCarryTimer = 30;
168
169
int32 anim = player->animator.animationID;
170
if (anim != ANI_FLY && anim != ANI_FLY_LIFT_TIRED && player->state != Player_State_TailsFlight) {
171
player->state = Player_State_Air;
172
if (anim != ANI_JUMP && anim != ANI_JOG && anim != ANI_RUN && anim != ANI_DASH)
173
player->animator.animationID = ANI_WALK;
174
}
175
176
if (player->animator.animationID != ANI_FLY)
177
player->groundVel = player->velocity.x;
178
179
player->onGround = false;
180
player->tileCollisions = TILECOLLISION_DOWN;
181
if (self->hitCount < 3) {
182
self->hitTimer = 0;
183
184
EntityScoreBonus *bonus = CREATE_ENTITY(ScoreBonus, NULL, self->position.x, self->position.y);
185
bonus->animator.frameID = 16;
186
Player_GiveScore(player, 10);
187
if (++self->hitCount < 3)
188
self->animator.frameID = self->hitCount;
189
}
190
}
191
}
192
}
193
194
void TargetBumper_State_Idle(void) { TargetBumper_CheckPlayerCollisions(); }
195
196
void TargetBumper_State_Hit(void)
197
{
198
RSDK_THIS(TargetBumper);
199
TargetBumper_CheckPlayerCollisions();
200
201
if ((self->hitTimer & 4)) {
202
self->position.x = self->startPos.x;
203
self->position.y = self->startPos.y;
204
}
205
else {
206
self->position.x = self->curPos.x;
207
self->position.y = self->curPos.y;
208
}
209
210
if (++self->hitTimer == 12) {
211
if (self->hitCount < 3) {
212
self->position.x = self->startPos.x;
213
self->position.y = self->startPos.y;
214
self->hitTimer = 0;
215
self->state = TargetBumper_State_Idle;
216
}
217
else {
218
destroyEntity(self);
219
}
220
}
221
}
222
223
#if GAME_INCLUDE_EDITOR
224
void TargetBumper_EditorDraw(void)
225
{
226
RSDK_THIS(TargetBumper);
227
RSDK.SetSpriteAnimation(TargetBumper->aniFrames, self->type, &self->animator, true, 0);
228
self->animator.frameID = self->hitCount;
229
230
RSDK.DrawSprite(&self->animator, NULL, false);
231
}
232
233
void TargetBumper_EditorLoad(void)
234
{
235
TargetBumper->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/TargetBumper.bin", SCOPE_STAGE);
236
237
RSDK_ACTIVE_VAR(TargetBumper, type);
238
RSDK_ENUM_VAR("Horizontal", TARGETBUMP_HORIZONTAL);
239
RSDK_ENUM_VAR("Vertical", TARGETBUMP_VERTICAL);
240
RSDK_ENUM_VAR("Diagonal", TARGETBUMP_DIAGONAL);
241
242
RSDK_ACTIVE_VAR(TargetBumper, hitCount);
243
RSDK_ENUM_VAR("Three Hits", TARGETBUMP_THREE_HIT);
244
RSDK_ENUM_VAR("Two Hits", TARGETBUMP_TWO_HIT);
245
RSDK_ENUM_VAR("One Hit", TARGETBUMP_ONE_HIT);
246
247
RSDK_ACTIVE_VAR(TargetBumper, direction);
248
RSDK_ENUM_VAR("No Flip", FLIP_NONE);
249
RSDK_ENUM_VAR("Flipped", FLIP_X);
250
}
251
#endif
252
253
void TargetBumper_Serialize(void)
254
{
255
RSDK_EDITABLE_VAR(TargetBumper, VAR_ENUM, type);
256
RSDK_EDITABLE_VAR(TargetBumper, VAR_ENUM, hitCount);
257
RSDK_EDITABLE_VAR(TargetBumper, VAR_UINT8, direction);
258
}
259
260