Path: blob/master/SonicMania/Objects/Pinball/PBL_Ring.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PBL_Ring Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectPBL_Ring *PBL_Ring;1112void PBL_Ring_Update(void)13{14RSDK_THIS(PBL_Ring);1516StateMachine_Run(self->state);17}1819void PBL_Ring_LateUpdate(void)20{21RSDK_THIS(PBL_Ring);2223int32 x = self->position.x >> 8;24int32 y = self->height >> 8;25int32 z = self->position.y >> 8;2627Matrix *m = &PBL_Camera->matWorld;2829self->worldX = m->values[0][3] + (y * m->values[0][1] >> 8) + (z * m->values[0][2] >> 8) + (x * m->values[0][0] >> 8);30self->worldY = m->values[1][3] + (y * m->values[1][1] >> 8) + (z * m->values[1][2] >> 8) + (x * m->values[1][0] >> 8);31self->zdepth = m->values[2][3] + (y * m->values[2][1] >> 8) + (z * m->values[2][2] >> 8) + (x * m->values[2][0] >> 8);32}3334void PBL_Ring_StaticUpdate(void) {}3536void PBL_Ring_Draw(void)37{38RSDK_THIS(PBL_Ring);3940if (self->zdepth >= 0x100) {41self->direction = self->animator.frameID > 8;4243Vector2 drawPos;44drawPos.x = (ScreenInfo->center.x + (self->worldX << 8) / self->zdepth) << 16;45drawPos.y = (ScreenInfo->center.y - (self->worldY << 8) / self->zdepth) << 16;4647self->scale.x = 0x1000000 / self->zdepth;48self->scale.y = 0x1000000 / self->zdepth;4950if (self->state == PBL_Ring_State_Ring)51self->animator.frameID = PBL_Setup->ringFrame;5253RSDK.DrawSprite(&self->animator, &drawPos, true);54}55}5657void PBL_Ring_Create(void *data)58{59RSDK_THIS(PBL_Ring);6061if (!SceneInfo->inEditor) {62self->visible = true;63self->drawFX = FX_SCALE | FX_FLIP;64self->drawGroup = 4;65self->active = ACTIVE_BOUNDS;66self->updateRange.x = 0x400000;67self->updateRange.y = 0x400000;6869if (!self->height)70self->height = 12;71self->height <<= 16;7273self->state = PBL_Ring_State_Ring;74RSDK.SetSpriteAnimation(PBL_Ring->aniFrames, 1, &self->animator, true, 0);75}76}7778void PBL_Ring_StageLoad(void)79{80PBL_Ring->aniFrames = RSDK.LoadSpriteAnimation("Global/Ring.bin", SCOPE_STAGE);8182PBL_Ring->sfxRing = RSDK.GetSfx("Global/Ring.wav");83}8485void PBL_Ring_GiveRing(void)86{87if (PBL_Setup->rings < 999)88PBL_Setup->rings++;8990PBL_Setup_GiveScore(10);9192if (PBL_Setup->ringPan) {93int32 channel = RSDK.PlaySfx(PBL_Ring->sfxRing, false, 0xFF);94RSDK.SetChannelAttributes(channel, 1.0, -1.0, 1.0);95PBL_Setup->ringPan = 0;96}97else {98int32 channel = RSDK.PlaySfx(PBL_Ring->sfxRing, false, 0xFF);99RSDK.SetChannelAttributes(channel, 1.0, 1.0, 1.0);100PBL_Setup->ringPan = 1;101}102}103104void PBL_Ring_State_Ring(void)105{106RSDK_THIS(PBL_Ring);107108foreach_active(PBL_Player, player)109{110int32 ry = (self->height - player->height - 0xA0000) >> 16;111int32 rz = (self->position.y - player->position.y) >> 16;112int32 rx = (self->position.x - player->position.x) >> 16;113114if (rx * rx + rz * rz + ry * ry < 0x100) {115RSDK.SetSpriteAnimation(PBL_Ring->aniFrames, 2, &self->animator, true, 4);116++self->drawGroup;117118self->state = PBL_Ring_State_RingSparkle;119PBL_Ring_GiveRing();120}121}122}123124void PBL_Ring_State_RingSparkle(void)125{126RSDK_THIS(PBL_Ring);127128RSDK.ProcessAnimation(&self->animator);129130if (self->animator.frameID == 15) {131self->state = StateMachine_None;132self->active = ACTIVE_NEVER;133}134}135136#if GAME_INCLUDE_EDITOR137void PBL_Ring_EditorDraw(void)138{139RSDK_THIS(PBL_Ring);140141RSDK.SetSpriteAnimation(PBL_Ring->aniFrames, 0, &self->animator, true, 0);142143RSDK.DrawSprite(&self->animator, NULL, false);144}145146void PBL_Ring_EditorLoad(void) { PBL_Ring->aniFrames = RSDK.LoadSpriteAnimation("Global/Ring.bin", SCOPE_STAGE); }147#endif148149void PBL_Ring_Serialize(void) { RSDK_EDITABLE_VAR(PBL_Ring, VAR_ENUM, height); }150#endif151152153