Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Pinball/PBL_TargetBumper.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PBL_TargetBumper 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
ObjectPBL_TargetBumper *PBL_TargetBumper;
12
13
void PBL_TargetBumper_Update(void)
14
{
15
RSDK_THIS(PBL_TargetBumper);
16
17
StateMachine_Run(self->state);
18
}
19
20
void PBL_TargetBumper_LateUpdate(void)
21
{
22
RSDK_THIS(PBL_TargetBumper);
23
24
int32 x = self->position.x;
25
int32 y = self->height;
26
int32 z = self->position.y;
27
28
Matrix *m = &PBL_Camera->matWorld;
29
self->zdepth = m->values[2][1] * (y >> 16) + m->values[2][2] * (z >> 16) + m->values[2][0] * (x >> 16) + m->values[2][3];
30
31
if (self->zdepth >= 0x4000) {
32
int32 depth = ((m->values[0][3] << 8) + ((m->values[0][2] * (z >> 8)) & 0xFFFFFF00) + ((m->values[0][0] * (x >> 8)) & 0xFFFFFF00)
33
+ ((m->values[0][1] * (self->height >> 8)) & 0xFFFFFF00));
34
depth /= self->zdepth;
35
}
36
}
37
38
void PBL_TargetBumper_StaticUpdate(void) {}
39
40
void PBL_TargetBumper_Draw(void)
41
{
42
RSDK_THIS(PBL_TargetBumper);
43
44
if (self->zdepth >= 0x4000) {
45
uint32 color = RSDK.GetPaletteEntry(0, (self->color & 0xFF) - 80);
46
RSDK.SetDiffuseColor(PBL_TargetBumper->sceneIndex, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
47
48
RSDK.Prepare3DScene(PBL_TargetBumper->sceneIndex);
49
50
RSDK.MatrixScaleXYZ(&self->matTransform, self->scale.x, self->scale.y, 256);
51
RSDK.MatrixTranslateXYZ(&self->matTransform, self->position.x, self->height, self->position.y, false);
52
RSDK.MatrixRotateY(&self->matNormal, self->angle);
53
54
RSDK.MatrixMultiply(&self->matWorld, &self->matNormal, &self->matTransform);
55
RSDK.MatrixMultiply(&self->matWorld, &self->matWorld, &PBL_Camera->matWorld);
56
RSDK.MatrixMultiply(&self->matNormal, &self->matNormal, &PBL_Camera->matNormal);
57
58
RSDK.AddModelTo3DScene(PBL_TargetBumper->modelFrames, PBL_TargetBumper->sceneIndex, PBL_TargetBumper->drawType, &self->matWorld,
59
&self->matNormal, 0xFFFFFF);
60
61
RSDK.Draw3DScene(PBL_TargetBumper->sceneIndex);
62
}
63
}
64
65
void PBL_TargetBumper_Create(void *data)
66
{
67
RSDK_THIS(PBL_TargetBumper);
68
69
if (!SceneInfo->inEditor) {
70
self->visible = true;
71
self->drawGroup = 4;
72
self->active = ACTIVE_BOUNDS;
73
self->updateRange.x = 0x400000;
74
self->updateRange.y = 0x400000;
75
self->scale.x = 0x100;
76
self->scale.y = 0x100;
77
self->state = PBL_TargetBumper_State_Active;
78
self->color = 2 * (RSDK.GetEntitySlot(self) % 3);
79
80
RSDK.SetModelAnimation(PBL_TargetBumper->modelFrames, &self->animator, 96, 0, true, 0);
81
}
82
}
83
84
void PBL_TargetBumper_StageLoad(void)
85
{
86
PBL_TargetBumper->modelFrames = RSDK.LoadMesh("Pinball/TargetBumper.bin", SCOPE_STAGE);
87
88
PBL_TargetBumper->sceneIndex = RSDK.Create3DScene("View:TargetBumper", 256, SCOPE_STAGE);
89
90
RSDK.SetDiffuseIntensity(PBL_TargetBumper->sceneIndex, 9, 9, 9);
91
RSDK.SetSpecularIntensity(PBL_TargetBumper->sceneIndex, 15, 15, 15);
92
93
PBL_TargetBumper->drawType = S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN;
94
95
PBL_TargetBumper->hitbox.left = -16;
96
PBL_TargetBumper->hitbox.top = -6;
97
PBL_TargetBumper->hitbox.right = 12;
98
PBL_TargetBumper->hitbox.bottom = 6;
99
100
PBL_TargetBumper->sfxTargetBumper = RSDK.GetSfx("Pinball/TargetBumper.wav");
101
PBL_TargetBumper->sfxFlipper = RSDK.GetSfx("Pinball/Flipper.wav");
102
}
103
104
void PBL_TargetBumper_HandlePlayerInteractions(void)
105
{
106
RSDK_THIS(PBL_TargetBumper);
107
108
if (self->scale.y >= 0x80) {
109
int32 angle = self->angle >> 2;
110
int32 negAngle = -angle;
111
112
Vector2 originVel = { 0, 0 };
113
foreach_active(PBL_Player, player)
114
{
115
int32 posX = player->position.x;
116
int32 posY = player->position.y;
117
int32 velStoreX = player->velocity.x;
118
int32 velStoreY = player->velocity.y;
119
120
121
Zone_RotateOnPivot(&player->position, &self->position, angle);
122
Zone_RotateOnPivot(&player->velocity, &originVel, angle);
123
124
int32 velX = player->velocity.x;
125
int32 velY = player->velocity.y;
126
switch (RSDK.CheckObjectCollisionBox(self, &PBL_TargetBumper->hitbox, player, &PBL_Player->outerBox, true)) {
127
case C_NONE:
128
player->position.x = posX;
129
player->position.y = posY;
130
player->velocity.x = velStoreX;
131
player->velocity.y = velStoreY;
132
break;
133
134
case C_TOP:
135
case C_BOTTOM:
136
player->onGround = false;
137
if (abs(velY) < 0x40000)
138
velY <<= 1;
139
140
player->velocity.y = -velY;
141
Zone_RotateOnPivot(&player->position, &self->position, negAngle);
142
Zone_RotateOnPivot(&player->velocity, &originVel, negAngle);
143
144
self->state = PBL_TargetBumper_State_Reced;
145
self->velocity.y = -8;
146
PBL_Setup_GiveScore(1000);
147
148
RSDK.PlaySfx(PBL_TargetBumper->sfxTargetBumper, false, 255);
149
break;
150
151
case C_LEFT:
152
if (velX < 0) {
153
player->velocity.x = velX;
154
}
155
else {
156
player->velocity.x = -(velX >> 1);
157
158
if (player->velocity.x <= -0x10000) {
159
if (player->velocity.x < -0x80000)
160
player->velocity.x = -0x80000;
161
162
player->velocity.y -= 0x20000;
163
}
164
else {
165
player->velocity.x = -0x10000;
166
player->velocity.y -= 0x20000;
167
}
168
169
Zone_RotateOnPivot(&player->position, &self->position, negAngle);
170
Zone_RotateOnPivot(&player->velocity, &originVel, negAngle);
171
player->onGround = false;
172
}
173
break;
174
175
case C_RIGHT:
176
if (velX > 0) {
177
player->velocity.x = velX;
178
}
179
else {
180
player->velocity.x = -(velX >> 1);
181
182
if (player->velocity.x >= 0x10000) {
183
if (player->velocity.x > 0x80000)
184
player->velocity.x = 0x80000;
185
186
player->velocity.y -= 0x20000;
187
}
188
else {
189
player->velocity.x = 0x10000;
190
player->velocity.y -= 0x20000;
191
}
192
}
193
194
Zone_RotateOnPivot(&player->position, &self->position, negAngle);
195
Zone_RotateOnPivot(&player->velocity, &originVel, negAngle);
196
player->onGround = false;
197
break;
198
199
default: break;
200
}
201
}
202
}
203
}
204
205
void PBL_TargetBumper_State_Active(void) { PBL_TargetBumper_HandlePlayerInteractions(); }
206
207
void PBL_TargetBumper_State_Reced(void)
208
{
209
RSDK_THIS(PBL_TargetBumper);
210
211
self->velocity.y += 2;
212
self->scale.y -= self->velocity.y;
213
214
if (self->scale.y <= 0) {
215
self->velocity.y = 0;
216
self->scale.y = 0;
217
self->state = StateMachine_None;
218
}
219
}
220
221
void PBL_TargetBumper_State_Rise(void)
222
{
223
RSDK_THIS(PBL_TargetBumper);
224
225
self->velocity.y -= 2;
226
self->scale.y += self->velocity.y;
227
228
if (self->velocity.y < 0 && self->scale.y <= 0x100) {
229
self->active = ACTIVE_BOUNDS;
230
self->velocity.y = 0;
231
self->scale.y = 256;
232
self->state = PBL_TargetBumper_State_Active;
233
}
234
}
235
236
#if GAME_INCLUDE_EDITOR
237
void PBL_TargetBumper_EditorDraw(void) {}
238
239
void PBL_TargetBumper_EditorLoad(void) {}
240
#endif
241
242
void PBL_TargetBumper_Serialize(void) { RSDK_EDITABLE_VAR(PBL_TargetBumper, VAR_ENUM, angle); }
243
#endif
244
245