Path: blob/master/SonicMania/Objects/Pinball/PBL_Player.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PBL_Player Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectPBL_Player *PBL_Player;1112void PBL_Player_Update(void)13{14RSDK_THIS(PBL_Player);1516StateMachine_Run(self->stateInput);17StateMachine_Run(self->state);1819self->angleX = ((uint16)self->angleX - (uint16)((abs(self->velocity.y) + abs(self->velocity.x)) >> 12)) & 0x3FF;20self->rotation = 4 * RSDK.ATan2(-self->velocity.y, self->velocity.x);2122if (!(self->angleX & 0x100))23self->animator.animationID = PBL_Player->jumpFrames;24else25self->animator.animationID = PBL_Player->ballFrames;2627RSDK.ProcessAnimation(&self->animator);28}2930void PBL_Player_LateUpdate(void)31{32RSDK_THIS(PBL_Player);3334Matrix *mat = &PBL_Camera->matWorld;3536self->zdepth = mat->values[2][3] + mat->values[2][0] * FROM_FIXED(self->position.x) + mat->values[2][2] * FROM_FIXED(self->position.y)37+ mat->values[2][1] * FROM_FIXED(self->height);38}3940void PBL_Player_StaticUpdate(void) {}4142void PBL_Player_Draw(void)43{44RSDK_THIS(PBL_Player);4546if (self->zdepth >= 0x4000) {47RSDK.Prepare3DScene(PBL_Player->sceneIndex);4849RSDK.MatrixTranslateXYZ(&self->matTranslate, self->position.x, self->height + 0x100000, self->position.y, true);50RSDK.MatrixRotateX(&self->matRotate, self->angleX);51RSDK.MatrixRotateY(&self->matWorld, self->rotation);5253RSDK.MatrixMultiply(&self->matNormal, &self->matRotate, &self->matWorld);54RSDK.MatrixMultiply(&self->matWorld, &self->matNormal, &self->matTranslate);55RSDK.MatrixMultiply(&self->matWorld, &self->matWorld, &PBL_Camera->matWorld);56RSDK.MatrixMultiply(&self->matNormal, &self->matNormal, &PBL_Camera->matNormalItem);5758RSDK.AddModelTo3DScene(self->animator.animationID, PBL_Player->sceneIndex, S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN, &self->matWorld,59&self->matNormal, 0xFFFFFF);6061RSDK.Draw3DScene(PBL_Player->sceneIndex);62}63}6465void PBL_Player_Create(void *data)66{67RSDK_THIS(PBL_Player);6869if (!SceneInfo->inEditor) {70self->active = ACTIVE_NORMAL;71self->visible = true;72self->updateRange.x = 0x800000;73self->updateRange.y = 0x800000;74self->drawGroup = 4;7576self->stateInput = PBL_Player_Input_P1;77self->state = PBL_Player_State_Launcher;78self->controllerID = 1;7980self->onGround = false;81self->tileCollisions = TILECOLLISION_DOWN;82self->collisionLayers = 1 << PBL_Setup->tableHigh;8384RSDK.SetModelAnimation(PBL_Player->jumpFrames, &self->animator, 128, 0, true, 0);8586foreach_all(PBL_Camera, camera) { camera->target = (Entity *)self; }87}88}8990void PBL_Player_StageLoad(void)91{92if (globals->playerID == ID_NONE) {93globals->playerID = ID_DEFAULT_PLAYER;94globals->characterFlags = ID_SONIC;95}9697switch (GET_CHARACTER_ID(1)) {98default:99case ID_SONIC:100PBL_Player->jumpFrames = RSDK.LoadMesh("Special/SonicJump.bin", SCOPE_STAGE);101PBL_Player->ballFrames = RSDK.LoadMesh("Special/SonicBall.bin", SCOPE_STAGE);102103PBL_Player->outerBox.top = -12;104PBL_Player->outerBox.bottom = 12;105PBL_Player->innerBox.top = -12;106PBL_Player->innerBox.bottom = 12;107break;108109case ID_TAILS:110PBL_Player->jumpFrames = RSDK.LoadMesh("Special/TailsJump.bin", SCOPE_STAGE);111PBL_Player->ballFrames = RSDK.LoadMesh("Special/TailsBall.bin", SCOPE_STAGE);112113PBL_Player->outerBox.top = -10;114PBL_Player->outerBox.bottom = 10;115PBL_Player->innerBox.top = -10;116PBL_Player->innerBox.bottom = 10;117break;118119case ID_KNUCKLES:120PBL_Player->jumpFrames = RSDK.LoadMesh("Special/KnuxJump.bin", SCOPE_STAGE);121PBL_Player->ballFrames = RSDK.LoadMesh("Special/KnuxBall.bin", SCOPE_STAGE);122123PBL_Player->outerBox.top = -12;124PBL_Player->outerBox.bottom = 12;125PBL_Player->innerBox.top = -12;126PBL_Player->innerBox.bottom = 12;127break;128129case ID_MIGHTY:130PBL_Player->jumpFrames = RSDK.LoadMesh("Special/MightyJump.bin", SCOPE_STAGE);131PBL_Player->ballFrames = RSDK.LoadMesh("Special/MightyBall.bin", SCOPE_STAGE);132133PBL_Player->outerBox.top = -12;134PBL_Player->outerBox.bottom = 12;135PBL_Player->innerBox.top = -12;136PBL_Player->innerBox.bottom = 12;137break;138139case ID_RAY:140PBL_Player->jumpFrames = RSDK.LoadMesh("Special/RayJump.bin", SCOPE_STAGE);141PBL_Player->ballFrames = RSDK.LoadMesh("Special/RayBall.bin", SCOPE_STAGE);142143PBL_Player->outerBox.top = -10;144PBL_Player->outerBox.bottom = 10;145PBL_Player->innerBox.top = -10;146PBL_Player->innerBox.bottom = 10;147break;148}149150PBL_Player->outerBox.left = -10;151PBL_Player->outerBox.right = 10;152PBL_Player->innerBox.left = -10;153PBL_Player->innerBox.right = 10;154155PBL_Player->sceneIndex = RSDK.Create3DScene("View:Pinball", 4096, SCOPE_STAGE);156157RSDK.SetDiffuseColor(PBL_Player->sceneIndex, 0xA0, 0xA0, 0xA0);158RSDK.SetDiffuseIntensity(PBL_Player->sceneIndex, 8, 8, 8);159RSDK.SetSpecularIntensity(PBL_Player->sceneIndex, 15, 15, 15);160161PBL_Player->sfxPlunger = RSDK.GetSfx("Pinball/Plunger.wav");162}163164void PBL_Player_Input_P1(void)165{166RSDK_THIS(PBL_Player);167168if (self->controllerID < PLAYER_COUNT) {169RSDKControllerState *controller = &ControllerInfo[self->controllerID];170RSDKAnalogState *stick = &AnalogStickInfoL[self->controllerID];171172self->up = controller->keyUp.down;173self->down = controller->keyDown.down;174self->left = controller->keyLeft.down;175self->right = controller->keyRight.down;176177self->up |= stick->keyUp.down;178self->down |= stick->keyDown.down;179self->left |= stick->keyLeft.down;180self->right |= stick->keyRight.down;181182self->up |= stick->vDelta > 0.3;183self->down |= stick->vDelta < -0.3;184self->left |= stick->hDelta < -0.3;185self->right |= stick->hDelta > 0.3;186187if (self->left && self->right) {188self->left = false;189self->right = false;190}191192// I don't think this is used, ever LOL193self->jumpPress = controller->keyA.press || controller->keyB.press || controller->keyC.press || controller->keyX.press;194195if (controller->keyStart.press || Unknown_pausePress) {196if (SceneInfo->state == ENGINESTATE_REGULAR) {197EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);198if (!pauseMenu->classID) {199RSDK.ResetEntitySlot(SLOT_PAUSEMENU, PauseMenu->classID, NULL);200pauseMenu->triggerPlayer = RSDK.GetEntitySlot(self);201pauseMenu->disableRestart = true;202}203}204}205}206}207208void PBL_Player_State_Launcher(void)209{210RSDK_THIS(PBL_Player);211212if (!self->onGround)213self->velocity.y += 0x3800;214215RSDK.ProcessObjectMovement(self, &PBL_Player->outerBox, &PBL_Player->innerBox);216217if (++self->timer == 60) {218self->velocity.y = -0xE0000;219self->timer = 0;220self->collisionPlane = 1;221self->onGround = false;222self->state = PBL_Player_State_Air;223RSDK.PlaySfx(PBL_Player->sfxPlunger, false, 255);224}225}226227void PBL_Player_State_Ground(void)228{229RSDK_THIS(PBL_Player);230231if (!self->angle && abs(self->groundVel) < 0x10000) {232self->groundVel = RSDK.Rand(-0x20000, 0x20000);233}234235self->groundVel += 0x2800 * RSDK.Sin256(self->angle) >> 8;236237if (self->collisionMode) {238if (self->angle >= 0x40 && self->angle <= 0xC0 && abs(self->groundVel) < 0x20000) {239self->velocity.x = (self->groundVel * RSDK.Cos256(self->angle)) >> 8;240self->velocity.y = (self->groundVel * RSDK.Sin256(self->angle)) >> 8;241self->onGround = false;242self->angle = 0;243self->collisionMode = CMODE_FLOOR;244}245}246247if (!self->onGround)248self->state = PBL_Player_State_Air;249250RSDK.ProcessObjectMovement(self, &PBL_Player->outerBox, &PBL_Player->innerBox);251}252253void PBL_Player_State_Air(void)254{255RSDK_THIS(PBL_Player);256257self->velocity.y += 0x2800;258259if (abs(self->velocity.x) > abs(self->velocity.y)) {260if (RSDK.ObjectTileCollision(self, self->collisionLayers, CMODE_LWALL, self->collisionPlane, self->velocity.x + 0x100000, 0, false))261self->velocity.x = -(self->velocity.x >> 1);262263if (RSDK.ObjectTileCollision(self, self->collisionLayers, CMODE_RWALL, self->collisionPlane, self->velocity.x - 0x100000, 0, false))264self->velocity.x = -(self->velocity.x >> 1);265}266267RSDK.ProcessObjectMovement(self, &PBL_Player->outerBox, &PBL_Player->innerBox);268269if (self->left)270self->velocity.x -= 0x800;271else if (self->right)272self->velocity.x += 0x800;273274if (self->onGround) {275if (!self->collisionMode)276self->collisionPlane = 0;277278self->state = PBL_Player_State_Ground;279}280}281282#if GAME_INCLUDE_EDITOR283void PBL_Player_EditorDraw(void)284{285RSDK_THIS(PBL_Player);286287RSDK.SetSpriteAnimation(PBL_Player->aniFrames, 0, &self->animator, true, 7);288RSDK.DrawSprite(&self->animator, NULL, false);289}290291void PBL_Player_EditorLoad(void) { PBL_Player->aniFrames = RSDK.LoadSpriteAnimation("Editor/PlayerIcons.bin", SCOPE_STAGE); }292#endif293294void PBL_Player_Serialize(void) {}295#endif296297298