Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Pinball/PBL_Bumper.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PBL_Bumper 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_Bumper *PBL_Bumper;
12
13
void PBL_Bumper_Update(void)
14
{
15
RSDK_THIS(PBL_Bumper);
16
17
StateMachine_Run(self->state);
18
}
19
20
void PBL_Bumper_LateUpdate(void)
21
{
22
RSDK_THIS(PBL_Bumper);
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_Bumper_StaticUpdate(void) {}
39
40
void PBL_Bumper_Draw(void)
41
{
42
RSDK_THIS(PBL_Bumper);
43
44
if (self->zdepth >= 0x4000) {
45
RSDK.Prepare3DScene(PBL_Bumper->sceneIndex);
46
47
RSDK.MatrixScaleXYZ(&self->matTransform, self->scale.x, self->scale.y, self->scale.x);
48
RSDK.MatrixTranslateXYZ(&self->matTransform, self->position.x, self->height, self->position.y, false);
49
RSDK.MatrixRotateY(&self->matNormal, self->angle);
50
51
RSDK.MatrixMultiply(&self->matWorld, &self->matNormal, &self->matTransform);
52
RSDK.MatrixMultiply(&self->matWorld, &self->matWorld, &PBL_Camera->matWorld);
53
RSDK.MatrixMultiply(&self->matNormal, &self->matNormal, &PBL_Camera->matNormalItem);
54
55
RSDK.AddModelTo3DScene(PBL_Bumper->modelFrames, PBL_Bumper->sceneIndex, S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN, &self->matWorld,
56
&self->matNormal, 0xFFFFFF);
57
58
RSDK.Draw3DScene(PBL_Bumper->sceneIndex);
59
}
60
}
61
62
void PBL_Bumper_Create(void *data)
63
{
64
RSDK_THIS(PBL_Bumper);
65
66
if (!SceneInfo->inEditor) {
67
self->visible = true;
68
self->drawGroup = 4;
69
self->active = ACTIVE_BOUNDS;
70
self->updateRange.x = 0x400000;
71
self->updateRange.y = 0x400000;
72
self->angle = 0x200;
73
self->scale.x = 0x100;
74
self->scale.y = 0x100;
75
self->state = PBL_Bumper_State_CheckBumps;
76
RSDK.SetModelAnimation(PBL_Bumper->modelFrames, &self->animator, 96, 0, true, 0);
77
}
78
}
79
80
void PBL_Bumper_StageLoad(void)
81
{
82
PBL_Bumper->modelFrames = RSDK.LoadMesh("Pinball/Bumper.bin", SCOPE_STAGE);
83
84
PBL_Bumper->sceneIndex = RSDK.Create3DScene("View:Pinball", 0x1000, SCOPE_STAGE);
85
86
PBL_Bumper->hitbox.left = -14;
87
PBL_Bumper->hitbox.top = -14;
88
PBL_Bumper->hitbox.right = 14;
89
PBL_Bumper->hitbox.bottom = 14;
90
91
PBL_Bumper->sfxBumper = RSDK.GetSfx("Stage/Bumper.wav");
92
}
93
94
void PBL_Bumper_HandlePlayerInteractions(void)
95
{
96
RSDK_THIS(PBL_Bumper);
97
98
foreach_active(PBL_Player, player)
99
{
100
if (RSDK.CheckObjectCollisionTouchBox(self, &PBL_Bumper->hitbox, player, &PBL_Player->outerBox)) {
101
if (self->state == PBL_Bumper_State_CheckBumps) {
102
self->scaleFactor = 0;
103
self->scaleVel = 0x8000;
104
self->active = ACTIVE_NORMAL;
105
self->state = PBL_Bumper_State_Bumped;
106
RSDK.PlaySfx(PBL_Bumper->sfxBumper, false, 255);
107
}
108
109
int32 angle = RSDK.ATan2(player->position.x - self->position.x, player->position.y - self->position.y);
110
player->velocity.x >>= 1;
111
player->velocity.y >>= 1;
112
player->velocity.x += 0x700 * RSDK.Cos256(angle);
113
player->velocity.y += 0x700 * RSDK.Sin256(angle);
114
player->onGround = false;
115
PBL_Setup_GiveScore(250);
116
}
117
}
118
}
119
120
void PBL_Bumper_State_CheckBumps(void) { PBL_Bumper_HandlePlayerInteractions(); }
121
122
void PBL_Bumper_State_Bumped(void)
123
{
124
RSDK_THIS(PBL_Bumper);
125
126
self->scaleVel += 0x1000;
127
self->scaleFactor += self->scaleVel;
128
129
if (self->scaleFactor > 0x8000) {
130
self->scaleVel = -(self->scaleVel >> 1);
131
if (++self->timer > 6) {
132
self->timer = 0;
133
self->state = PBL_Bumper_State_FinishedBump;
134
}
135
}
136
137
self->scale.x = (self->scaleFactor >> 8) + 0x100;
138
self->scale.y = (self->scaleFactor >> 8) + 0x100;
139
PBL_Bumper_HandlePlayerInteractions();
140
}
141
142
void PBL_Bumper_State_FinishedBump(void)
143
{
144
RSDK_THIS(PBL_Bumper);
145
146
self->scaleFactor -= self->scaleFactor >> 2;
147
if (self->scaleFactor < 0x100) {
148
self->scaleFactor = 0;
149
self->active = ACTIVE_BOUNDS;
150
self->state = PBL_Bumper_State_CheckBumps;
151
}
152
153
self->scale.x = (self->scaleFactor >> 8) + 0x100;
154
self->scale.y = (self->scaleFactor >> 8) + 0x100;
155
156
PBL_Bumper_HandlePlayerInteractions();
157
}
158
159
#if GAME_INCLUDE_EDITOR
160
void PBL_Bumper_EditorDraw(void) {}
161
162
void PBL_Bumper_EditorLoad(void) {}
163
#endif
164
165
void PBL_Bumper_Serialize(void) {}
166
#endif
167
168