Path: blob/master/SonicMania/Objects/PGZ/PrintBlock.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PrintBlock Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPrintBlock *PrintBlock;1011void PrintBlock_Update(void)12{13RSDK_THIS(PrintBlock);1415if (self->state == Platform_State_Fixed) {16if (self->interval != (uint16)-1) {17int32 timer = (Zone->timer + self->intervalOffset) % self->interval;1819if (timer >= self->duration) {20if (timer >= self->duration + 12) {21self->animator.frameID = 1;22self->animator.timer = 0;23}24else {25self->active = ACTIVE_NORMAL;26self->state = PrintBlock_State_Disappear;27self->timer = timer - self->duration;28self->animator.frameID = 4 - self->timer / 3;29self->animator.timer = self->timer % 3;30}31}32else {33self->active = ACTIVE_NORMAL;34self->timer = timer;35if (self->timer > 12) {36self->animator.frameID = 4;37self->animator.timer = 0;38}39else {40self->animator.timer = self->timer % 3;41self->animator.frameID = self->timer / 3 + 1;42}4344Vector2 pos;45pos.x = 0x200000;46pos.y = 0x200000;47if (RSDK.CheckOnScreen(self, &pos)) {48int32 channel = RSDK.PlaySfx(PrintBlock->sfxLetter, false, 255);49RSDK.SetChannelAttributes(channel, 1.0, 0.0, 1.0);50}5152self->state = PrintBlock_State_Appear;53}54}55}5657if (self->animator.frameID <= 2) {58self->stateCollide = Platform_Collision_None;59self->collision = PLATFORM_C_NONE;60}61else {62self->stateCollide = Platform_Collision_Solid;63self->collision = PLATFORM_C_SOLID;64}6566Platform_Update();67}6869void PrintBlock_LateUpdate(void) {}7071void PrintBlock_StaticUpdate(void) {}7273void PrintBlock_Draw(void)74{75RSDK_THIS(PrintBlock);7677RSDK.DrawSprite(&self->animator, &self->drawPos, false);7879self->inkEffect = INK_SUB;80PrintBlock->animator.frameID = self->animator.frameID;81RSDK.DrawSprite(&PrintBlock->animator, &self->drawPos, false);8283self->inkEffect = INK_NONE;84}8586void PrintBlock_Create(void *data)87{88RSDK_THIS(PrintBlock);8990self->collision = PLATFORM_C_SOLID;91Platform_Create(NULL);9293RSDK.SetSpriteAnimation(PrintBlock->aniFrames, self->letter, &self->animator, true, 0);9495self->alpha = 128;96self->drawGroup = Zone->objectDrawGroup[0];97self->state = Platform_State_Fixed;98}99100void PrintBlock_StageLoad(void)101{102if (RSDK.CheckSceneFolder("PSZ1"))103PrintBlock->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PrintBlock.bin", SCOPE_STAGE);104105RSDK.SetSpriteAnimation(PrintBlock->aniFrames, 12, &PrintBlock->animator, true, 0);106107PrintBlock->sfxLetter = RSDK.GetSfx("PSZ/Letter.wav");108}109110void PrintBlock_State_Appear(void)111{112RSDK_THIS(PrintBlock);113114++self->timer;115if (++self->animator.timer == 3) {116self->animator.timer = 0;117if (self->animator.frameID < 4)118self->animator.frameID++;119}120121if (self->timer == self->duration)122self->state = PrintBlock_State_Disappear;123}124125void PrintBlock_State_Disappear(void)126{127RSDK_THIS(PrintBlock);128129if (++self->animator.timer == 3) {130self->animator.timer = 0;131132if (self->animator.frameID <= 1) {133self->active = ACTIVE_BOUNDS;134self->state = Platform_State_Fixed;135}136else {137self->animator.frameID--;138}139}140}141142#if GAME_INCLUDE_EDITOR143void PrintBlock_EditorDraw(void)144{145RSDK_THIS(PrintBlock);146147RSDK.SetSpriteAnimation(PrintBlock->aniFrames, self->letter, &self->animator, true, self->interval == (uint16)-1 ? 0 : 4);148self->alpha = 0x80;149self->drawPos = self->position;150151PrintBlock_Draw();152153if (showGizmos()) {154RSDK_DRAWING_OVERLAY(true);155156for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {157Entity *child = RSDK_GET_ENTITY_GEN(s + i);158if (!child)159continue;160161DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);162}163164RSDK_DRAWING_OVERLAY(false);165}166}167168void PrintBlock_EditorLoad(void)169{170PrintBlock->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PrintBlock.bin", SCOPE_STAGE);171172RSDK.SetSpriteAnimation(-1, 12, &PrintBlock->animator, true, 0);173174RSDK_ACTIVE_VAR(PrintBlock, letter);175RSDK_ENUM_VAR("E", PRINTBLOCK_LETTER_E);176RSDK_ENUM_VAR("T", PRINTBLOCK_LETTER_T);177RSDK_ENUM_VAR("A", PRINTBLOCK_LETTER_A);178RSDK_ENUM_VAR("O", PRINTBLOCK_LETTER_O);179RSDK_ENUM_VAR("I", PRINTBLOCK_LETTER_I);180RSDK_ENUM_VAR("N", PRINTBLOCK_LETTER_N);181RSDK_ENUM_VAR("S", PRINTBLOCK_LETTER_S);182RSDK_ENUM_VAR("H", PRINTBLOCK_LETTER_H);183RSDK_ENUM_VAR("R", PRINTBLOCK_LETTER_R);184RSDK_ENUM_VAR("D", PRINTBLOCK_LETTER_D);185RSDK_ENUM_VAR("L", PRINTBLOCK_LETTER_L);186RSDK_ENUM_VAR("U", PRINTBLOCK_LETTER_U);187}188#endif189190void PrintBlock_Serialize(void)191{192RSDK_EDITABLE_VAR(PrintBlock, VAR_ENUM, childCount);193RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT16, interval);194RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT16, intervalOffset);195RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT16, duration);196RSDK_EDITABLE_VAR(PrintBlock, VAR_UINT8, letter);197}198199200