Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Puyo/PuyoAttack.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PuyoAttack Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPuyoAttack *PuyoAttack;
11
12
void PuyoAttack_Update(void)
13
{
14
RSDK_THIS(PuyoAttack);
15
16
if (self->delay > 0) {
17
if (--self->delay)
18
return;
19
20
self->visible = true;
21
}
22
23
RSDK.ProcessAnimation(&self->animator);
24
25
int32 angle = RSDK.ATan2((self->targetPos.x - self->position.x) >> 16, (self->targetPos.y - self->position.y) >> 16);
26
int32 rot = 2 * angle;
27
int32 targetRotation = rot - self->rotation;
28
29
if (abs(rot - self->rotation) >= abs(targetRotation - 0x200)) {
30
if (abs(targetRotation - 0x200) < abs(targetRotation + 0x200))
31
self->rotation += ((targetRotation - 0x200) >> 3);
32
else
33
self->rotation += ((targetRotation + 0x200) >> 3);
34
}
35
else {
36
if (abs(rot - self->rotation) >= abs(targetRotation + 0x200))
37
self->rotation += ((targetRotation + 0x200) >> 3);
38
else
39
self->rotation += (targetRotation >> 3);
40
}
41
42
self->rotation &= 0x1FF;
43
self->position.x += self->radius * RSDK.Cos512(self->rotation);
44
self->position.y += self->radius * RSDK.Sin512(self->rotation);
45
46
if (self->radius < 1024)
47
self->radius += 8;
48
49
if (self->position.y < self->targetPos.y) {
50
PuyoMatch_AddPuyoCombo(self->playerID, self->score);
51
destroyEntity(self);
52
}
53
}
54
55
void PuyoAttack_LateUpdate(void) {}
56
57
void PuyoAttack_StaticUpdate(void) {}
58
59
void PuyoAttack_Draw(void)
60
{
61
RSDK_THIS(PuyoAttack);
62
63
RSDK.DrawSprite(&self->animator, NULL, false);
64
}
65
66
void PuyoAttack_Create(void *data)
67
{
68
RSDK_THIS(PuyoAttack);
69
70
if (!SceneInfo->inEditor) {
71
self->delay = 16;
72
self->radius = 512;
73
self->drawGroup = Zone->hudDrawGroup;
74
75
self->playerID = VOID_TO_INT(data);
76
self->rotation = self->playerID ? 0x140 : 0x40;
77
self->active = ACTIVE_NORMAL;
78
RSDK.SetSpriteAnimation(PuyoAttack->aniFrames, self->playerID ^ 1, &self->animator, true, 0);
79
}
80
}
81
82
void PuyoAttack_StageLoad(void)
83
{
84
PuyoAttack->aniFrames = RSDK.LoadSpriteAnimation("Puyo/Combos.bin", SCOPE_STAGE);
85
86
PuyoAttack->sfxAttack = RSDK.GetSfx("Puyo/Attack.wav");
87
}
88
89
#if GAME_INCLUDE_EDITOR
90
void PuyoAttack_EditorDraw(void)
91
{
92
RSDK_THIS(PuyoAttack);
93
RSDK.SetSpriteAnimation(PuyoAttack->aniFrames, 0, &self->animator, true, 3);
94
95
PuyoAttack_Draw();
96
}
97
98
void PuyoAttack_EditorLoad(void) { PuyoAttack->aniFrames = RSDK.LoadSpriteAnimation("Puyo/Combos.bin", SCOPE_STAGE); }
99
#endif
100
101
void PuyoAttack_Serialize(void) {}
102
103