Path: blob/master/SonicMania/Objects/Pinball/PBL_Bumper.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PBL_Bumper Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectPBL_Bumper *PBL_Bumper;1112void PBL_Bumper_Update(void)13{14RSDK_THIS(PBL_Bumper);1516StateMachine_Run(self->state);17}1819void PBL_Bumper_LateUpdate(void)20{21RSDK_THIS(PBL_Bumper);2223int32 x = self->position.x;24int32 y = self->height;25int32 z = self->position.y;2627Matrix *m = &PBL_Camera->matWorld;28self->zdepth = m->values[2][1] * (y >> 16) + m->values[2][2] * (z >> 16) + m->values[2][0] * (x >> 16) + m->values[2][3];2930if (self->zdepth >= 0x4000) {31int32 depth = ((m->values[0][3] << 8) + ((m->values[0][2] * (z >> 8)) & 0xFFFFFF00) + ((m->values[0][0] * (x >> 8)) & 0xFFFFFF00)32+ ((m->values[0][1] * (self->height >> 8)) & 0xFFFFFF00));33depth /= self->zdepth;34}35}3637void PBL_Bumper_StaticUpdate(void) {}3839void PBL_Bumper_Draw(void)40{41RSDK_THIS(PBL_Bumper);4243if (self->zdepth >= 0x4000) {44RSDK.Prepare3DScene(PBL_Bumper->sceneIndex);4546RSDK.MatrixScaleXYZ(&self->matTransform, self->scale.x, self->scale.y, self->scale.x);47RSDK.MatrixTranslateXYZ(&self->matTransform, self->position.x, self->height, self->position.y, false);48RSDK.MatrixRotateY(&self->matNormal, self->angle);4950RSDK.MatrixMultiply(&self->matWorld, &self->matNormal, &self->matTransform);51RSDK.MatrixMultiply(&self->matWorld, &self->matWorld, &PBL_Camera->matWorld);52RSDK.MatrixMultiply(&self->matNormal, &self->matNormal, &PBL_Camera->matNormalItem);5354RSDK.AddModelTo3DScene(PBL_Bumper->modelFrames, PBL_Bumper->sceneIndex, S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN, &self->matWorld,55&self->matNormal, 0xFFFFFF);5657RSDK.Draw3DScene(PBL_Bumper->sceneIndex);58}59}6061void PBL_Bumper_Create(void *data)62{63RSDK_THIS(PBL_Bumper);6465if (!SceneInfo->inEditor) {66self->visible = true;67self->drawGroup = 4;68self->active = ACTIVE_BOUNDS;69self->updateRange.x = 0x400000;70self->updateRange.y = 0x400000;71self->angle = 0x200;72self->scale.x = 0x100;73self->scale.y = 0x100;74self->state = PBL_Bumper_State_CheckBumps;75RSDK.SetModelAnimation(PBL_Bumper->modelFrames, &self->animator, 96, 0, true, 0);76}77}7879void PBL_Bumper_StageLoad(void)80{81PBL_Bumper->modelFrames = RSDK.LoadMesh("Pinball/Bumper.bin", SCOPE_STAGE);8283PBL_Bumper->sceneIndex = RSDK.Create3DScene("View:Pinball", 0x1000, SCOPE_STAGE);8485PBL_Bumper->hitbox.left = -14;86PBL_Bumper->hitbox.top = -14;87PBL_Bumper->hitbox.right = 14;88PBL_Bumper->hitbox.bottom = 14;8990PBL_Bumper->sfxBumper = RSDK.GetSfx("Stage/Bumper.wav");91}9293void PBL_Bumper_HandlePlayerInteractions(void)94{95RSDK_THIS(PBL_Bumper);9697foreach_active(PBL_Player, player)98{99if (RSDK.CheckObjectCollisionTouchBox(self, &PBL_Bumper->hitbox, player, &PBL_Player->outerBox)) {100if (self->state == PBL_Bumper_State_CheckBumps) {101self->scaleFactor = 0;102self->scaleVel = 0x8000;103self->active = ACTIVE_NORMAL;104self->state = PBL_Bumper_State_Bumped;105RSDK.PlaySfx(PBL_Bumper->sfxBumper, false, 255);106}107108int32 angle = RSDK.ATan2(player->position.x - self->position.x, player->position.y - self->position.y);109player->velocity.x >>= 1;110player->velocity.y >>= 1;111player->velocity.x += 0x700 * RSDK.Cos256(angle);112player->velocity.y += 0x700 * RSDK.Sin256(angle);113player->onGround = false;114PBL_Setup_GiveScore(250);115}116}117}118119void PBL_Bumper_State_CheckBumps(void) { PBL_Bumper_HandlePlayerInteractions(); }120121void PBL_Bumper_State_Bumped(void)122{123RSDK_THIS(PBL_Bumper);124125self->scaleVel += 0x1000;126self->scaleFactor += self->scaleVel;127128if (self->scaleFactor > 0x8000) {129self->scaleVel = -(self->scaleVel >> 1);130if (++self->timer > 6) {131self->timer = 0;132self->state = PBL_Bumper_State_FinishedBump;133}134}135136self->scale.x = (self->scaleFactor >> 8) + 0x100;137self->scale.y = (self->scaleFactor >> 8) + 0x100;138PBL_Bumper_HandlePlayerInteractions();139}140141void PBL_Bumper_State_FinishedBump(void)142{143RSDK_THIS(PBL_Bumper);144145self->scaleFactor -= self->scaleFactor >> 2;146if (self->scaleFactor < 0x100) {147self->scaleFactor = 0;148self->active = ACTIVE_BOUNDS;149self->state = PBL_Bumper_State_CheckBumps;150}151152self->scale.x = (self->scaleFactor >> 8) + 0x100;153self->scale.y = (self->scaleFactor >> 8) + 0x100;154155PBL_Bumper_HandlePlayerInteractions();156}157158#if GAME_INCLUDE_EDITOR159void PBL_Bumper_EditorDraw(void) {}160161void PBL_Bumper_EditorLoad(void) {}162#endif163164void PBL_Bumper_Serialize(void) {}165#endif166167168