Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/CPZ/ChemBubble.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ChemBubble Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectChemBubble *ChemBubble;
11
12
void ChemBubble_Update(void)
13
{
14
RSDK_THIS(ChemBubble);
15
16
StateMachine_Run(self->state);
17
}
18
19
void ChemBubble_LateUpdate(void) {}
20
21
void ChemBubble_StaticUpdate(void) {}
22
23
void ChemBubble_Draw(void)
24
{
25
RSDK_THIS(ChemBubble);
26
27
RSDK.DrawSprite(&self->animator, NULL, false);
28
}
29
30
void ChemBubble_Create(void *data)
31
{
32
RSDK_THIS(ChemBubble);
33
34
if (!SceneInfo->inEditor) {
35
self->visible = true;
36
self->active = ACTIVE_NORMAL;
37
self->drawGroup = Zone->objectDrawGroup[1] - 2;
38
self->startPos = self->position;
39
40
self->velocity.y = ZONE_RAND(-0x20000, 0);
41
self->angleShift = ZONE_RAND(12, 16);
42
self->amplitude = ZONE_RAND(9, 10);
43
44
RSDK.SetSpriteAnimation(ChemBubble->aniFrames, RSDK.Rand(1, 3), &self->animator, true, 0);
45
self->drawFX = FX_SCALE;
46
self->state = ChemBubble_State_Appear;
47
}
48
}
49
50
void ChemBubble_StageLoad(void) { ChemBubble->aniFrames = RSDK.LoadSpriteAnimation("CPZ/ChemPool.bin", SCOPE_STAGE); }
51
52
void ChemBubble_State_Appear(void)
53
{
54
RSDK_THIS(ChemBubble);
55
56
self->scale.x += 0x20;
57
self->scale.y = self->scale.x;
58
59
if (self->scale.x == 0x200) {
60
self->drawFX = FX_NONE;
61
self->state = ChemBubble_State_Rising;
62
}
63
}
64
65
void ChemBubble_State_Rising(void)
66
{
67
RSDK_THIS(ChemBubble);
68
EntityChemicalPool *parent = self->parent;
69
70
self->velocity.y -= 0x2000;
71
self->position.y += self->velocity.y;
72
73
int32 x = (RSDK.Sin256(self->position.y >> self->angleShift) << self->amplitude) + self->startPos.x;
74
self->position.x = x;
75
76
int32 deform = ChemicalPool->surfaceDeformation[x >> 20];
77
int32 y = parent->offsetY + (((x >> 12) & 0xFF) * (ChemicalPool->surfaceDeformation[(x + 0x100000) >> 20] - deform) >> 8) + deform + 0x20000;
78
79
if (self->position.y <= y) {
80
self->position.y = y;
81
if (self->animator.animationID == 2) {
82
RSDK.SetSpriteAnimation(ChemBubble->aniFrames, 3, &self->animator, true, 0);
83
self->timer = RSDK.Rand(8, 32);
84
}
85
else {
86
RSDK.SetSpriteAnimation(ChemBubble->aniFrames, 4, &self->animator, true, 5);
87
}
88
89
self->state = ChemBubble_State_Surfaced;
90
}
91
}
92
93
void ChemBubble_State_Surfaced(void)
94
{
95
RSDK_THIS(ChemBubble);
96
EntityChemicalPool *parent = self->parent;
97
98
RSDK.ProcessAnimation(&self->animator);
99
100
int32 x = self->position.x;
101
102
int32 deform = ChemicalPool->surfaceDeformation[x >> 20];
103
self->position.y =
104
parent->offsetY + (((x >> 12) & 0xFF) * (ChemicalPool->surfaceDeformation[(x + 0x100000) >> 20] - deform) >> 8) + deform + 0x20000;
105
106
if (self->animator.animationID == 4) {
107
if (self->animator.frameID == self->animator.frameCount - 1)
108
destroyEntity(self);
109
}
110
else if (--self->timer <= 0) {
111
RSDK.SetSpriteAnimation(ChemBubble->aniFrames, 4, &self->animator, true, 5);
112
}
113
}
114
115
#if GAME_INCLUDE_EDITOR
116
void ChemBubble_EditorDraw(void)
117
{
118
RSDK_THIS(ChemBubble);
119
120
RSDK.SetSpriteAnimation(ChemBubble->aniFrames, 1, &self->animator, true, 0);
121
122
ChemBubble_Draw();
123
}
124
125
void ChemBubble_EditorLoad(void) { ChemBubble->aniFrames = RSDK.LoadSpriteAnimation("CPZ/ChemPool.bin", SCOPE_STAGE); }
126
#endif
127
128
void ChemBubble_Serialize(void) {}
129
130