Path: blob/master/SonicMania/Objects/Pinball/PBL_HUD.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PBL_HUD Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectPBL_HUD *PBL_HUD;1112void PBL_HUD_Update(void)13{14RSDK_THIS(PBL_HUD);1516StateMachine_Run(self->state);17}1819void PBL_HUD_LateUpdate(void) {}2021void PBL_HUD_StaticUpdate(void) {}2223void PBL_HUD_Draw(void)24{25RSDK_THIS(PBL_HUD);2627self->position.x = ScreenInfo->center.x << 16;2829if (self->stateDraw) {30StateMachine_Run(self->stateDraw);31}32else {33RSDK.DrawSprite(&self->displayAnimator, NULL, true);34RSDK.DrawSprite(&self->baseAnimator, NULL, true);35}36}3738void PBL_HUD_Create(void *data)39{40RSDK_THIS(PBL_HUD);4142if (!SceneInfo->inEditor) {43self->visible = true;44self->drawGroup = 12;45self->active = ACTIVE_NORMAL;46self->position.y = 0;47self->scale.x = 0x200;48self->scale.y = 0x200;4950RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->displayAnimator, true, 0);51RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->baseAnimator, true, 1);52RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 1, &self->textAnimator, true, 0);5354RSDK.InitString(&self->text, "", 64);5556if (globals->gameMode == MODE_ENCORE)57PBL_HUD_DisplayMessage(self, "BONUS STAGE! RESCUE YOUR BUDDIES!", PBL_HUD_MSG_SCROLL_LEFT);58else59PBL_HUD_DisplayMessage(self, "BONUS STAGE!", PBL_HUD_MSG_SCROLL_LEFT);60}61}6263void PBL_HUD_StageLoad(void) { PBL_HUD->aniFrames = RSDK.LoadSpriteAnimation("Pinball/Backglass.bin", SCOPE_STAGE); }6465void PBL_HUD_DisplayMessage(EntityPBL_HUD *entity, const char *message, int32 type)66{67if (entity->state != PBL_HUD_StateMessage_FlashThenCrane && entity->state != PBL_HUD_State_RevealCrane68&& entity->state != PBL_HUD_State_HideCrane) {69RSDK.SetString(&entity->text, message);70RSDK.SetSpriteString(PBL_HUD->aniFrames, 1, &entity->text);7172entity->stateDraw = PBL_HUD_Draw_Message;7374switch (type) {75case PBL_HUD_MSG_SCROLL_LEFT_SLOW:76entity->offset.x = 0x410000;77entity->state = PBL_HUD_StateMessage_ScrollLeftSlow;78entity->timer = 12 * entity->text.length + 128;79break;8081case PBL_HUD_MSG_SCROLL_LEFT:82entity->offset.x = 0x410000;83entity->state = PBL_HUD_StateMessage_ScrollLeftFast;84entity->timer = 6 * entity->text.length + 64;85break;8687case PBL_HUD_MSG_SCROLL_RIGHT_SLOW:88entity->state = PBL_HUD_StateMessage_ScrollRightSlow;89entity->timer = 12 * entity->text.length + 128;90entity->offset.x = -0x410000 - 0xC0000 * entity->text.length;91break;9293case PBL_HUD_MSG_SCROLL_RIGHT:94entity->state = PBL_HUD_StateMessage_ScrollRightFast;95entity->timer = 6 * entity->text.length + 64;96entity->offset.x = -0x410000 - 0xC0000 * entity->text.length;97break;9899case PBL_HUD_MSG_SHOW_RISE:100entity->offset.y = 0x120000;101entity->timer = -9;102entity->velocity.y = -0x20000;103entity->state = PBL_HUD_StateMessage_ShowMove;104entity->offset.x = -0x60000 * entity->text.length;105break;106107case PBL_HUD_MSG_SHOW_FALL:108entity->offset.y = -0x120000;109entity->timer = -9;110entity->velocity.y = 0x20000;111entity->state = PBL_HUD_StateMessage_ShowMove;112entity->offset.x = -0x60000 * entity->text.length;113break;114115case PBL_HUD_MSG_FLASH:116entity->state = PBL_HUD_StateMessage_Flash;117entity->timer = 60;118entity->offset.x = -0x60000 * entity->text.length;119break;120121case PBL_HUD_MSG_FLASH_CRANE:122entity->state = PBL_HUD_StateMessage_FlashThenCrane;123entity->timer = 60;124entity->offset.x = -0x60000 * entity->text.length;125break;126127default: break;128}129}130}131132void PBL_HUD_StateMessage_ScrollLeftSlow(void)133{134RSDK_THIS(PBL_HUD);135136if (self->timer <= 0) {137self->state = StateMachine_None;138self->stateDraw = PBL_HUD_Draw_Score;139}140else {141self->timer--;142if (!(self->timer & 1))143self->offset.x -= 0x20000;144}145}146147void PBL_HUD_StateMessage_ScrollLeftFast(void)148{149RSDK_THIS(PBL_HUD);150151if (self->timer <= 0) {152self->state = StateMachine_None;153self->stateDraw = PBL_HUD_Draw_Score;154}155else {156self->offset.x -= 0x20000;157self->timer--;158}159}160void PBL_HUD_StateMessage_ScrollRightSlow(void)161{162RSDK_THIS(PBL_HUD);163164if (self->timer <= 0) {165self->state = StateMachine_None;166self->stateDraw = PBL_HUD_Draw_Score;167}168else {169self->timer--;170171if (!(self->timer & 1))172self->offset.x += 0x20000;173}174}175176void PBL_HUD_StateMessage_ScrollRightFast(void)177{178RSDK_THIS(PBL_HUD);179180if (self->timer <= 0) {181self->state = StateMachine_None;182self->stateDraw = PBL_HUD_Draw_Score;183}184else {185self->offset.x += 0x20000;186self->timer--;187}188}189190void PBL_HUD_StateMessage_ShowMove(void)191{192RSDK_THIS(PBL_HUD);193194if (self->timer < 0 || self->timer > 60)195self->offset.y += self->velocity.y;196197if (++self->timer > 90) {198self->timer = 0;199self->offset.y = 0;200self->state = StateMachine_None;201self->stateDraw = PBL_HUD_Draw_Score;202}203}204205void PBL_HUD_StateMessage_Flash(void)206{207RSDK_THIS(PBL_HUD);208209if (self->timer <= 0) {210self->state = StateMachine_None;211self->stateDraw = PBL_HUD_Draw_Score;212}213else {214self->timer--;215216if ((self->timer & 7) < 4)217self->stateDraw = StateMachine_None;218else219self->stateDraw = PBL_HUD_Draw_Message;220}221}222223void PBL_HUD_StateMessage_FlashThenCrane(void)224{225RSDK_THIS(PBL_HUD);226227if (self->timer <= 0) {228self->state = PBL_HUD_State_RevealCrane;229self->stateDraw = PBL_HUD_Draw_Basic;230self->drawFX = FX_SCALE;231232foreach_active(PBL_Crane, crane) { crane->state = PBL_Crane_State_CreatePrizes; }233}234else {235self->timer--;236237if ((self->timer & 7) < 4)238self->stateDraw = StateMachine_None;239else240self->stateDraw = PBL_HUD_Draw_Message;241}242}243244void PBL_HUD_Draw_Basic(void)245{246RSDK_THIS(PBL_HUD);247248RSDK.DrawSprite(&self->displayAnimator, NULL, true);249}250251void PBL_HUD_Draw_Message(void)252{253RSDK_THIS(PBL_HUD);254255RSDK.DrawSprite(&self->displayAnimator, NULL, true);256RSDK.DrawSprite(&self->baseAnimator, NULL, true);257258Vector2 position;259position.x = self->position.x + self->offset.x;260position.y = self->position.y + self->offset.y;261262RSDK.SetClipBounds(SceneInfo->currentScreenID, ScreenInfo->center.x - 55, 40, ScreenInfo->center.x + 56, 58);263264RSDK.DrawText(&self->textAnimator, &position, &self->text, 0, 0, 0, 1, 0, 0, true);265266RSDK.SetClipBounds(SceneInfo->currentScreenID, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);267}268269void PBL_HUD_Draw_Score(void)270{271RSDK_THIS(PBL_HUD);272273int32 score = PBL_Setup->score;274int32 count = 0;275int32 mult = 1;276277while (score > 0) {278++count;279score /= 10;280}281282Vector2 drawPos;283drawPos.x = self->position.x + 0x320000;284drawPos.y = self->position.y;285RSDK.DrawSprite(&self->displayAnimator, NULL, true);286RSDK.DrawSprite(&self->baseAnimator, NULL, true);287288int32 div = 10;289while (count > 0) {290self->textAnimator.frameID = PBL_Setup->score / mult % div;291RSDK.DrawSprite(&self->textAnimator, &drawPos, true);292293drawPos.x -= 0xC0000;294mult *= 10;295--count;296}297298self->textAnimator.frameID = 0;299}300301void PBL_HUD_State_RevealCrane(void)302{303RSDK_THIS(PBL_HUD);304305self->scale.x += 4;306self->position.y -= 0x40000;307308if (self->position.y < -0x480000) {309self->state = StateMachine_None;310self->visible = false;311}312}313314void PBL_HUD_State_HideCrane(void)315{316RSDK_THIS(PBL_HUD);317318self->scale.x -= 4;319self->position.y += 0x40000;320321if (self->position.y >= 0) {322self->position.y = 0;323self->scale.x = 0x200;324self->scale.y = 0x200;325self->drawFX = FX_NONE;326self->state = StateMachine_None;327self->stateDraw = PBL_HUD_Draw_Score;328329foreach_all(PBL_Player, player)330{331player->active = ACTIVE_NORMAL;332player->velocity.y = 0;333}334}335}336337#if GAME_INCLUDE_EDITOR338void PBL_HUD_EditorDraw(void)339{340RSDK_THIS(PBL_HUD);341342RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->displayAnimator, true, 0);343RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->baseAnimator, true, 1);344345RSDK.DrawSprite(&self->displayAnimator, NULL, false);346}347348void PBL_HUD_EditorLoad(void) { PBL_HUD->aniFrames = RSDK.LoadSpriteAnimation("Pinball/Backglass.bin", SCOPE_STAGE); }349#endif350351void PBL_HUD_Serialize(void) {}352#endif353354355