Path: blob/master/SonicMania/Objects/Pinball/PBL_TargetBumper.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PBL_TargetBumper Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectPBL_TargetBumper *PBL_TargetBumper;1112void PBL_TargetBumper_Update(void)13{14RSDK_THIS(PBL_TargetBumper);1516StateMachine_Run(self->state);17}1819void PBL_TargetBumper_LateUpdate(void)20{21RSDK_THIS(PBL_TargetBumper);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_TargetBumper_StaticUpdate(void) {}3839void PBL_TargetBumper_Draw(void)40{41RSDK_THIS(PBL_TargetBumper);4243if (self->zdepth >= 0x4000) {44uint32 color = RSDK.GetPaletteEntry(0, (self->color & 0xFF) - 80);45RSDK.SetDiffuseColor(PBL_TargetBumper->sceneIndex, (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);4647RSDK.Prepare3DScene(PBL_TargetBumper->sceneIndex);4849RSDK.MatrixScaleXYZ(&self->matTransform, self->scale.x, self->scale.y, 256);50RSDK.MatrixTranslateXYZ(&self->matTransform, self->position.x, self->height, self->position.y, false);51RSDK.MatrixRotateY(&self->matNormal, self->angle);5253RSDK.MatrixMultiply(&self->matWorld, &self->matNormal, &self->matTransform);54RSDK.MatrixMultiply(&self->matWorld, &self->matWorld, &PBL_Camera->matWorld);55RSDK.MatrixMultiply(&self->matNormal, &self->matNormal, &PBL_Camera->matNormal);5657RSDK.AddModelTo3DScene(PBL_TargetBumper->modelFrames, PBL_TargetBumper->sceneIndex, PBL_TargetBumper->drawType, &self->matWorld,58&self->matNormal, 0xFFFFFF);5960RSDK.Draw3DScene(PBL_TargetBumper->sceneIndex);61}62}6364void PBL_TargetBumper_Create(void *data)65{66RSDK_THIS(PBL_TargetBumper);6768if (!SceneInfo->inEditor) {69self->visible = true;70self->drawGroup = 4;71self->active = ACTIVE_BOUNDS;72self->updateRange.x = 0x400000;73self->updateRange.y = 0x400000;74self->scale.x = 0x100;75self->scale.y = 0x100;76self->state = PBL_TargetBumper_State_Active;77self->color = 2 * (RSDK.GetEntitySlot(self) % 3);7879RSDK.SetModelAnimation(PBL_TargetBumper->modelFrames, &self->animator, 96, 0, true, 0);80}81}8283void PBL_TargetBumper_StageLoad(void)84{85PBL_TargetBumper->modelFrames = RSDK.LoadMesh("Pinball/TargetBumper.bin", SCOPE_STAGE);8687PBL_TargetBumper->sceneIndex = RSDK.Create3DScene("View:TargetBumper", 256, SCOPE_STAGE);8889RSDK.SetDiffuseIntensity(PBL_TargetBumper->sceneIndex, 9, 9, 9);90RSDK.SetSpecularIntensity(PBL_TargetBumper->sceneIndex, 15, 15, 15);9192PBL_TargetBumper->drawType = S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN;9394PBL_TargetBumper->hitbox.left = -16;95PBL_TargetBumper->hitbox.top = -6;96PBL_TargetBumper->hitbox.right = 12;97PBL_TargetBumper->hitbox.bottom = 6;9899PBL_TargetBumper->sfxTargetBumper = RSDK.GetSfx("Pinball/TargetBumper.wav");100PBL_TargetBumper->sfxFlipper = RSDK.GetSfx("Pinball/Flipper.wav");101}102103void PBL_TargetBumper_HandlePlayerInteractions(void)104{105RSDK_THIS(PBL_TargetBumper);106107if (self->scale.y >= 0x80) {108int32 angle = self->angle >> 2;109int32 negAngle = -angle;110111Vector2 originVel = { 0, 0 };112foreach_active(PBL_Player, player)113{114int32 posX = player->position.x;115int32 posY = player->position.y;116int32 velStoreX = player->velocity.x;117int32 velStoreY = player->velocity.y;118119120Zone_RotateOnPivot(&player->position, &self->position, angle);121Zone_RotateOnPivot(&player->velocity, &originVel, angle);122123int32 velX = player->velocity.x;124int32 velY = player->velocity.y;125switch (RSDK.CheckObjectCollisionBox(self, &PBL_TargetBumper->hitbox, player, &PBL_Player->outerBox, true)) {126case C_NONE:127player->position.x = posX;128player->position.y = posY;129player->velocity.x = velStoreX;130player->velocity.y = velStoreY;131break;132133case C_TOP:134case C_BOTTOM:135player->onGround = false;136if (abs(velY) < 0x40000)137velY <<= 1;138139player->velocity.y = -velY;140Zone_RotateOnPivot(&player->position, &self->position, negAngle);141Zone_RotateOnPivot(&player->velocity, &originVel, negAngle);142143self->state = PBL_TargetBumper_State_Reced;144self->velocity.y = -8;145PBL_Setup_GiveScore(1000);146147RSDK.PlaySfx(PBL_TargetBumper->sfxTargetBumper, false, 255);148break;149150case C_LEFT:151if (velX < 0) {152player->velocity.x = velX;153}154else {155player->velocity.x = -(velX >> 1);156157if (player->velocity.x <= -0x10000) {158if (player->velocity.x < -0x80000)159player->velocity.x = -0x80000;160161player->velocity.y -= 0x20000;162}163else {164player->velocity.x = -0x10000;165player->velocity.y -= 0x20000;166}167168Zone_RotateOnPivot(&player->position, &self->position, negAngle);169Zone_RotateOnPivot(&player->velocity, &originVel, negAngle);170player->onGround = false;171}172break;173174case C_RIGHT:175if (velX > 0) {176player->velocity.x = velX;177}178else {179player->velocity.x = -(velX >> 1);180181if (player->velocity.x >= 0x10000) {182if (player->velocity.x > 0x80000)183player->velocity.x = 0x80000;184185player->velocity.y -= 0x20000;186}187else {188player->velocity.x = 0x10000;189player->velocity.y -= 0x20000;190}191}192193Zone_RotateOnPivot(&player->position, &self->position, negAngle);194Zone_RotateOnPivot(&player->velocity, &originVel, negAngle);195player->onGround = false;196break;197198default: break;199}200}201}202}203204void PBL_TargetBumper_State_Active(void) { PBL_TargetBumper_HandlePlayerInteractions(); }205206void PBL_TargetBumper_State_Reced(void)207{208RSDK_THIS(PBL_TargetBumper);209210self->velocity.y += 2;211self->scale.y -= self->velocity.y;212213if (self->scale.y <= 0) {214self->velocity.y = 0;215self->scale.y = 0;216self->state = StateMachine_None;217}218}219220void PBL_TargetBumper_State_Rise(void)221{222RSDK_THIS(PBL_TargetBumper);223224self->velocity.y -= 2;225self->scale.y += self->velocity.y;226227if (self->velocity.y < 0 && self->scale.y <= 0x100) {228self->active = ACTIVE_BOUNDS;229self->velocity.y = 0;230self->scale.y = 256;231self->state = PBL_TargetBumper_State_Active;232}233}234235#if GAME_INCLUDE_EDITOR236void PBL_TargetBumper_EditorDraw(void) {}237238void PBL_TargetBumper_EditorLoad(void) {}239#endif240241void PBL_TargetBumper_Serialize(void) { RSDK_EDITABLE_VAR(PBL_TargetBumper, VAR_ENUM, angle); }242#endif243244245