Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/PGZ/PSZLauncher.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PSZLauncher Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPSZLauncher *PSZLauncher;
11
12
void PSZLauncher_Update(void)
13
{
14
RSDK_THIS(PSZLauncher);
15
16
StateMachine_Run(self->state);
17
}
18
19
void PSZLauncher_LateUpdate(void) {}
20
21
void PSZLauncher_StaticUpdate(void) {}
22
23
void PSZLauncher_Draw(void)
24
{
25
RSDK_THIS(PSZLauncher);
26
27
RSDK.DrawSprite(&self->animator, NULL, false);
28
}
29
30
void PSZLauncher_Create(void *data)
31
{
32
RSDK_THIS(PSZLauncher);
33
34
self->visible = true;
35
self->drawGroup = Zone->objectDrawGroup[1] - 1;
36
self->drawFX = FX_FLIP;
37
38
if (SceneInfo->inEditor && !self->power)
39
self->power = 10;
40
41
self->active = ACTIVE_BOUNDS;
42
self->updateRange.x = 0x800000;
43
self->updateRange.y = 0x800000;
44
self->state = PSZLauncher_State_Init;
45
}
46
47
void PSZLauncher_StageLoad(void)
48
{
49
PSZLauncher->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PSZLauncher.bin", SCOPE_STAGE);
50
51
PSZLauncher->hitboxLaunch.left = -32;
52
PSZLauncher->hitboxLaunch.top = 0;
53
PSZLauncher->hitboxLaunch.right = 32;
54
PSZLauncher->hitboxLaunch.bottom = 1;
55
56
DEBUGMODE_ADD_OBJ(PSZLauncher);
57
}
58
59
void PSZLauncher_DebugSpawn(void)
60
{
61
RSDK_THIS(PSZLauncher);
62
63
EntityPSZLauncher *launcher = CREATE_ENTITY(PSZLauncher, NULL, self->position.x, self->position.y);
64
launcher->direction = self->direction;
65
}
66
67
void PSZLauncher_DebugDraw(void)
68
{
69
RSDK.SetSpriteAnimation(PSZLauncher->aniFrames, 0, &DebugMode->animator, true, 0);
70
RSDK.DrawSprite(&DebugMode->animator, NULL, false);
71
}
72
73
void PSZLauncher_State_Init(void)
74
{
75
RSDK_THIS(PSZLauncher);
76
77
RSDK.SetSpriteAnimation(PSZLauncher->aniFrames, 0, &self->animator, true, 0);
78
self->stoodPlayers = 0;
79
self->activePlayers = 0;
80
81
self->state = PSZLauncher_State_Active;
82
83
PSZLauncher_HandlePlayerCollisions();
84
PSZLauncher_HandlePlayerInteractions();
85
}
86
87
void PSZLauncher_HandlePlayerCollisions(void)
88
{
89
RSDK_THIS(PSZLauncher);
90
91
Hitbox hitboxStand;
92
hitboxStand.left = -32;
93
hitboxStand.right = 0;
94
hitboxStand.bottom = 0;
95
foreach_active(Player, player)
96
{
97
int32 playerID = RSDK.GetEntitySlot(player);
98
99
int32 standPos = 31 - CLAMP(abs(player->position.x - self->position.x) >> 16, 0, 31);
100
if ((self->direction == FLIP_NONE && player->position.x > self->position.x)
101
|| (self->direction == FLIP_X && player->position.x < self->position.x))
102
standPos = 31;
103
104
hitboxStand.top = -PSZLauncher->heightTable[standPos];
105
if ((1 << playerID) & self->stoodPlayers)
106
player->position.y += 0x10000;
107
108
if (Player_CheckCollisionPlatform(player, self, &hitboxStand)) {
109
self->stoodPlayers |= 1 << playerID;
110
player->position.y &= 0xFFFF0000;
111
}
112
else {
113
self->stoodPlayers &= ~(1 << playerID);
114
}
115
}
116
}
117
118
void PSZLauncher_HandlePlayerInteractions(void)
119
{
120
RSDK_THIS(PSZLauncher);
121
122
foreach_active(Player, player)
123
{
124
int32 playerID = RSDK.GetEntitySlot(player);
125
126
if (Player_CheckCollisionTouch(player, self, &PSZLauncher->hitboxLaunch)) {
127
if (!((1 << playerID) & self->activePlayers) && !((1 << playerID) & self->stoodPlayers) && player->velocity.y <= 0) {
128
self->activePlayers |= 1 << playerID;
129
player->velocity.y = -0x10000 * self->power;
130
player->velocity.x = 0;
131
132
if (self->direction)
133
player->position.x = self->position.x - 0x100000;
134
else
135
player->position.x = self->position.x + 0x100000;
136
137
player->applyJumpCap = false;
138
player->jumpAbilityState = 0;
139
player->collisionMode = 0;
140
player->groundVel = 0;
141
player->state = Player_State_Air;
142
player->onGround = false;
143
144
RSDK.PlaySfx(Player->sfxRelease, false, 255);
145
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
146
}
147
}
148
else {
149
self->activePlayers &= ~(1 << playerID);
150
}
151
}
152
}
153
154
void PSZLauncher_State_Active(void)
155
{
156
PSZLauncher_HandlePlayerCollisions();
157
PSZLauncher_HandlePlayerInteractions();
158
}
159
160
#if GAME_INCLUDE_EDITOR
161
void PSZLauncher_EditorDraw(void)
162
{
163
RSDK_THIS(PSZLauncher);
164
RSDK.SetSpriteAnimation(PSZLauncher->aniFrames, 0, &self->animator, true, 0);
165
166
PSZLauncher_Draw();
167
}
168
169
void PSZLauncher_EditorLoad(void)
170
{
171
PSZLauncher->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PSZLauncher.bin", SCOPE_STAGE);
172
173
RSDK_ACTIVE_VAR(PSZLauncher, direction);
174
RSDK_ENUM_VAR("Left", FLIP_NONE);
175
RSDK_ENUM_VAR("Right", FLIP_X);
176
}
177
#endif
178
179
void PSZLauncher_Serialize(void)
180
{
181
RSDK_EDITABLE_VAR(PSZLauncher, VAR_UINT8, direction);
182
RSDK_EDITABLE_VAR(PSZLauncher, VAR_UINT8, power);
183
}
184
185