Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/MMZ/MMZWheel.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: MMZWheel Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectMMZWheel *MMZWheel;
11
12
void MMZWheel_Update(void)
13
{
14
RSDK_THIS(MMZWheel);
15
16
RSDK.ProcessAnimation(&self->animator);
17
18
self->offset.x = -self->position.x;
19
self->offset.y = -self->position.y;
20
21
switch (self->motionType) {
22
default: break;
23
24
case MMZWHEEL_MOTION_STIFF: {
25
int32 direction = 2 * (self->direction != FLIP_NONE) - 1;
26
self->position.x += direction * (self->speed << 14);
27
28
if (abs(self->position.x - self->center.x) >= self->amplitude << 16) {
29
self->direction = self->direction == FLIP_NONE;
30
self->position.x = self->center.x + (self->amplitude << 16) * direction;
31
}
32
break;
33
}
34
35
case MMZWHEEL_MOTION_SMOOTH: self->position.x = self->center.x + (self->amplitude << 6) * RSDK.Sin1024(self->speed * Zone->timer); break;
36
}
37
38
RSDK.ObjectTileGrip(self, Zone->collisionLayers, 0, CMODE_FLOOR, 0, 0x180000, 8);
39
40
self->offset.x += self->position.x;
41
self->offset.y += self->position.y;
42
43
int32 id = SceneInfo->entitySlot;
44
for (int32 i = 0; i < self->childCount; ++i) {
45
Entity *child = RSDK_GET_ENTITY_GEN(++id);
46
child->position.x += self->offset.x;
47
child->position.y += self->offset.y;
48
}
49
}
50
51
void MMZWheel_LateUpdate(void) {}
52
53
void MMZWheel_StaticUpdate(void) {}
54
55
void MMZWheel_Draw(void)
56
{
57
RSDK_THIS(MMZWheel);
58
59
RSDK.DrawSprite(&self->animator, NULL, false);
60
}
61
62
void MMZWheel_Create(void *data)
63
{
64
RSDK_THIS(MMZWheel);
65
66
self->active = ACTIVE_BOUNDS;
67
self->visible = true;
68
self->drawGroup = Zone->objectDrawGroup[0];
69
if (SceneInfo->inEditor && !self->speed)
70
self->speed = 1;
71
72
self->updateRange.y = 0x800000;
73
self->updateRange.x = (self->amplitude + 0x80) << 16;
74
self->center.x = self->position.x;
75
self->center.y = self->position.y;
76
RSDK.SetSpriteAnimation(MMZWheel->aniFrames, 0, &self->animator, true, 0);
77
}
78
79
void MMZWheel_StageLoad(void) { MMZWheel->aniFrames = RSDK.LoadSpriteAnimation("MMZ/MMZWheel.bin", SCOPE_STAGE); }
80
81
#if GAME_INCLUDE_EDITOR
82
void MMZWheel_EditorDraw(void)
83
{
84
RSDK_THIS(MMZWheel);
85
86
MMZWheel_Create(NULL);
87
MMZWheel_Draw();
88
89
if (showGizmos()) {
90
RSDK_DRAWING_OVERLAY(true);
91
92
for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {
93
Entity *child = RSDK_GET_ENTITY_GEN(s + i);
94
if (!child)
95
continue;
96
97
DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);
98
}
99
100
RSDK_DRAWING_OVERLAY(false);
101
}
102
}
103
104
void MMZWheel_EditorLoad(void)
105
{
106
MMZWheel->aniFrames = RSDK.LoadSpriteAnimation("MMZ/MMZWheel.bin", SCOPE_STAGE);
107
108
RSDK_ACTIVE_VAR(MMZWheel, motionType);
109
RSDK_ENUM_VAR("Stiff", MMZWHEEL_MOTION_STIFF);
110
RSDK_ENUM_VAR("Smooth", MMZWHEEL_MOTION_SMOOTH);
111
}
112
#endif
113
114
void MMZWheel_Serialize(void)
115
{
116
RSDK_EDITABLE_VAR(MMZWheel, VAR_UINT32, amplitude);
117
RSDK_EDITABLE_VAR(MMZWheel, VAR_UINT8, childCount);
118
RSDK_EDITABLE_VAR(MMZWheel, VAR_ENUM, speed);
119
RSDK_EDITABLE_VAR(MMZWheel, VAR_UINT8, motionType);
120
}
121
122