Path: blob/master/SonicMania/Objects/MMZ/MMZWheel.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: MMZWheel Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectMMZWheel *MMZWheel;1011void MMZWheel_Update(void)12{13RSDK_THIS(MMZWheel);1415RSDK.ProcessAnimation(&self->animator);1617self->offset.x = -self->position.x;18self->offset.y = -self->position.y;1920switch (self->motionType) {21default: break;2223case MMZWHEEL_MOTION_STIFF: {24int32 direction = 2 * (self->direction != FLIP_NONE) - 1;25self->position.x += direction * (self->speed << 14);2627if (abs(self->position.x - self->center.x) >= self->amplitude << 16) {28self->direction = self->direction == FLIP_NONE;29self->position.x = self->center.x + (self->amplitude << 16) * direction;30}31break;32}3334case MMZWHEEL_MOTION_SMOOTH: self->position.x = self->center.x + (self->amplitude << 6) * RSDK.Sin1024(self->speed * Zone->timer); break;35}3637RSDK.ObjectTileGrip(self, Zone->collisionLayers, 0, CMODE_FLOOR, 0, 0x180000, 8);3839self->offset.x += self->position.x;40self->offset.y += self->position.y;4142int32 id = SceneInfo->entitySlot;43for (int32 i = 0; i < self->childCount; ++i) {44Entity *child = RSDK_GET_ENTITY_GEN(++id);45child->position.x += self->offset.x;46child->position.y += self->offset.y;47}48}4950void MMZWheel_LateUpdate(void) {}5152void MMZWheel_StaticUpdate(void) {}5354void MMZWheel_Draw(void)55{56RSDK_THIS(MMZWheel);5758RSDK.DrawSprite(&self->animator, NULL, false);59}6061void MMZWheel_Create(void *data)62{63RSDK_THIS(MMZWheel);6465self->active = ACTIVE_BOUNDS;66self->visible = true;67self->drawGroup = Zone->objectDrawGroup[0];68if (SceneInfo->inEditor && !self->speed)69self->speed = 1;7071self->updateRange.y = 0x800000;72self->updateRange.x = (self->amplitude + 0x80) << 16;73self->center.x = self->position.x;74self->center.y = self->position.y;75RSDK.SetSpriteAnimation(MMZWheel->aniFrames, 0, &self->animator, true, 0);76}7778void MMZWheel_StageLoad(void) { MMZWheel->aniFrames = RSDK.LoadSpriteAnimation("MMZ/MMZWheel.bin", SCOPE_STAGE); }7980#if GAME_INCLUDE_EDITOR81void MMZWheel_EditorDraw(void)82{83RSDK_THIS(MMZWheel);8485MMZWheel_Create(NULL);86MMZWheel_Draw();8788if (showGizmos()) {89RSDK_DRAWING_OVERLAY(true);9091for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {92Entity *child = RSDK_GET_ENTITY_GEN(s + i);93if (!child)94continue;9596DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);97}9899RSDK_DRAWING_OVERLAY(false);100}101}102103void MMZWheel_EditorLoad(void)104{105MMZWheel->aniFrames = RSDK.LoadSpriteAnimation("MMZ/MMZWheel.bin", SCOPE_STAGE);106107RSDK_ACTIVE_VAR(MMZWheel, motionType);108RSDK_ENUM_VAR("Stiff", MMZWHEEL_MOTION_STIFF);109RSDK_ENUM_VAR("Smooth", MMZWHEEL_MOTION_SMOOTH);110}111#endif112113void MMZWheel_Serialize(void)114{115RSDK_EDITABLE_VAR(MMZWheel, VAR_UINT32, amplitude);116RSDK_EDITABLE_VAR(MMZWheel, VAR_UINT8, childCount);117RSDK_EDITABLE_VAR(MMZWheel, VAR_ENUM, speed);118RSDK_EDITABLE_VAR(MMZWheel, VAR_UINT8, motionType);119}120121122