Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/SPZ/PopcornKernel.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PopcornKernel Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPopcornKernel *PopcornKernel;
11
12
void PopcornKernel_Update(void)
13
{
14
RSDK_THIS(PopcornKernel);
15
16
StateMachine_Run(self->state);
17
18
self->angle += self->angleVel;
19
self->rotation = (self->angle >> 15) & 0x1FF;
20
}
21
22
void PopcornKernel_LateUpdate(void) {}
23
24
void PopcornKernel_StaticUpdate(void) {}
25
26
void PopcornKernel_Draw(void)
27
{
28
RSDK_THIS(PopcornKernel);
29
30
RSDK.DrawSprite(&self->animator, NULL, false);
31
}
32
33
void PopcornKernel_Create(void *data)
34
{
35
RSDK_THIS(PopcornKernel);
36
37
if (!SceneInfo->inEditor) {
38
self->drawFX = FX_ROTATE;
39
self->state = PopcornKernel_State_BounceAround;
40
41
RSDK.SetSpriteAnimation(PopcornKernel->aniFrames, 1, &self->animator, true, RSDK.Rand(0, 7));
42
if (self->animator.frameID >= 0 && (self->animator.frameID <= 1 || self->animator.frameID == 5))
43
self->drawGroup = Zone->objectDrawGroup[0] - 1;
44
else
45
self->drawGroup = Zone->objectDrawGroup[0];
46
47
self->active = ACTIVE_NORMAL;
48
self->updateRange.x = 0x800000;
49
self->updateRange.y = 0x2000000;
50
self->gravityStrength = 0x4000;
51
self->scale.x = 0x200;
52
self->scale.y = 0x200;
53
self->visible = true;
54
}
55
}
56
57
void PopcornKernel_StageLoad(void) { PopcornKernel->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/PopcornMachine.bin", SCOPE_STAGE); }
58
59
void PopcornKernel_State_BounceAround(void)
60
{
61
RSDK_THIS(PopcornKernel);
62
63
self->velocity.y += self->gravityStrength;
64
self->position.x += self->velocity.x;
65
self->position.y += self->velocity.y;
66
67
if (self->velocity.y >= 0) {
68
foreach_active(PopcornKernel, kernel)
69
{
70
if (kernel != self) {
71
int32 rx = (self->position.x - kernel->position.x) >> 16;
72
int32 ry = (self->position.y - kernel->position.y) >> 16;
73
if (rx * rx + ry * ry < 0x100) {
74
int32 angle = RSDK.ATan2(rx, ry);
75
self->velocity.x = RSDK.Cos256(angle) << 17 >> 8;
76
self->velocity.y = RSDK.Sin256(angle) << 17 >> 8;
77
}
78
}
79
}
80
}
81
82
if (self->position.x < self->bounds.x - 0x680000) {
83
self->position.x = self->bounds.x - 0x680000;
84
self->velocity.x = -self->velocity.x;
85
}
86
else if (self->position.x > self->bounds.x + 0x680000) {
87
self->position.x = self->bounds.x + 0x680000;
88
self->velocity.x = -self->velocity.x;
89
}
90
91
if (self->position.y > self->bounds.y - 0x380000) {
92
self->position.y = self->bounds.y - 0x380000;
93
self->velocity.y = -self->velocity.y >> 1;
94
}
95
}
96
97
void PopcornKernel_State_RiseUp(void)
98
{
99
RSDK_THIS(PopcornKernel);
100
101
self->velocity.y += 0x800;
102
self->position.x += self->velocity.x;
103
self->position.y += self->velocity.y;
104
105
if (self->position.y < self->maxY) {
106
self->state = PopcornKernel_State_FallDown;
107
//???
108
// Dunno why this is here but removing it would change the internal randSeed
109
RSDK.Rand(-0x80000, 0x80000);
110
}
111
}
112
113
void PopcornKernel_State_FallDown(void)
114
{
115
RSDK_THIS(PopcornKernel);
116
117
self->velocity.y += 0x3800;
118
self->position.x += self->velocity.x;
119
self->position.y += self->velocity.y;
120
121
if (!RSDK.CheckOnScreen(self, NULL))
122
destroyEntity(self);
123
}
124
125
#if GAME_INCLUDE_EDITOR
126
void PopcornKernel_EditorDraw(void)
127
{
128
RSDK_THIS(PopcornKernel);
129
RSDK.SetSpriteAnimation(PopcornKernel->aniFrames, 1, &self->animator, true, 0);
130
131
PopcornKernel_Draw();
132
}
133
134
void PopcornKernel_EditorLoad(void) { PopcornKernel->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/PopcornMachine.bin", SCOPE_STAGE); }
135
#endif
136
137
void PopcornKernel_Serialize(void) {}
138
139