Path: blob/master/SonicMania/Objects/PGZ/Newspaper.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: Newspaper Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectNewspaper *Newspaper;1011void Newspaper_Update(void)12{13#if MANIA_USE_PLUS14RSDK_THIS(Newspaper);1516StateMachine_Run(self->state);17#else18Platform_Update();19#endif20}2122void Newspaper_LateUpdate(void) {}2324void Newspaper_StaticUpdate(void) {}2526void Newspaper_Draw(void)27{28RSDK_THIS(Newspaper);2930#if MANIA_USE_PLUS31RSDK.DrawSprite(&self->animator, NULL, false);32#else33RSDK.DrawSprite(&self->animator, &self->drawPos, false);34#endif35}3637void Newspaper_Create(void *data)38{39RSDK_THIS(Newspaper);4041#if MANIA_USE_PLUS42if (!SceneInfo->inEditor) {43self->visible = true;44self->active = ACTIVE_BOUNDS;45self->updateRange.x = 0x400000;46self->updateRange.y = 0x400000;47RSDK.SetSpriteAnimation(Newspaper->aniFrames, 1, &self->animator, true, self->type);48switch (self->type) {49case NEWSPAPER_WHITE_FG:50case NEWSPAPER_BLUE_FG:51self->state = Newspaper_HandleInteractions;52self->drawGroup = Zone->playerDrawGroup[0];53break;5455case NEWSPAPER_WHITE_BG:56case NEWSPAPER_BLUE_BG: self->drawGroup = Zone->objectDrawGroup[0]; break;5758default: break;59}6061self->hitbox.left = -16;62self->hitbox.top = -16;63self->hitbox.right = 16;64self->hitbox.bottom = 16;65}6667#else68self->collision = PLATFORM_C_SOLID;69self->type = PLATFORM_PATH;70Platform_Create(NULL);71RSDK.SetSpriteAnimation(Newspaper->aniFrames, 0, &self->animator, true, 0);72#endif73}7475void Newspaper_StageLoad(void)76{77#if MANIA_USE_PLUS78Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);7980Newspaper->sfxPaperStack = RSDK.GetSfx("PSZ/PaperStack.wav");81#else82if (RSDK.CheckSceneFolder("PSZ1"))83Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);84#endif85}8687#if MANIA_USE_PLUS88void Newspaper_HandleInteractions(void)89{90RSDK_THIS(Newspaper);9192if (self->timer <= 0) {93foreach_active(Player, player)94{95if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {96int32 x = self->position.x + RSDK.Rand(-0x80000, 0x80000);97int32 y = self->position.y + RSDK.Rand(-0x80000, 0x80000);98EntityDebris *debris = CREATE_ENTITY(Debris, NULL, x, y);99100debris->state = Debris_State_Fall;101debris->gravityStrength = 0x400;102debris->velocity.x = RSDK.Rand(0, 0x20000);103debris->timer = 240;104self->timer = 2;105if (debris->position.x < self->position.x)106debris->velocity.x = -debris->velocity.x;107debris->drawGroup = Zone->objectDrawGroup[0];108RSDK.SetSpriteAnimation(Newspaper->aniFrames, RSDK.Rand(0, 2) + 2, &debris->animator, true, RSDK.Rand(0, 6));109110if (Newspaper->sfxPaperStack) {111RSDK.PlaySfx(Newspaper->sfxPaperStack, false, 255);112Newspaper->sfxPaperStack = 0;113}114}115}116}117else {118self->timer--;119}120}121#endif122123#if GAME_INCLUDE_EDITOR124void Newspaper_EditorDraw(void)125{126RSDK_THIS(Newspaper);127128#if MANIA_USE_PLUS129self->active = ACTIVE_BOUNDS;130self->updateRange.x = 0x400000;131self->updateRange.y = 0x400000;132133RSDK.SetSpriteAnimation(Newspaper->aniFrames, 1, &self->animator, true, self->type);134135switch (self->type) {136case NEWSPAPER_WHITE_FG:137case NEWSPAPER_BLUE_FG:138self->state = Newspaper_HandleInteractions;139self->drawGroup = Zone->playerDrawGroup[0];140break;141142case NEWSPAPER_WHITE_BG:143case NEWSPAPER_BLUE_BG: self->drawGroup = Zone->objectDrawGroup[0]; break;144default: break;145}146147#else148RSDK.SetSpriteAnimation(Newspaper->aniFrames, 0, &self->animator, true, 0);149self->centerPos = self->position;150self->drawPos = self->position;151#endif152153Newspaper_Draw();154155#if !MANIA_USE_PLUS156if (showGizmos()) {157RSDK_DRAWING_OVERLAY(true);158159for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {160Entity *child = RSDK_GET_ENTITY_GEN(s + i);161if (!child)162continue;163164DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);165}166167Entity *targetNode = RSDK_GET_ENTITY_GEN(self->node);168if (targetNode)169DrawHelpers_DrawArrow(self->position.x, self->position.y, targetNode->position.x, targetNode->position.y, 0xFFFF00, INK_NONE, 0xFF);170171RSDK_DRAWING_OVERLAY(false);172}173#endif174}175176void Newspaper_EditorLoad(void)177{178#if MANIA_USE_PLUS179Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);180181RSDK_ACTIVE_VAR(Newspaper, type);182RSDK_ENUM_VAR("White (FG)", NEWSPAPER_WHITE_FG);183RSDK_ENUM_VAR("Blue (FG)", NEWSPAPER_WHITE_FG);184RSDK_ENUM_VAR("White (BG)", NEWSPAPER_WHITE_BG);185RSDK_ENUM_VAR("Blue (BG)", NEWSPAPER_WHITE_BG);186187#else188if (RSDK.CheckSceneFolder("PSZ1"))189Newspaper->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/Newspaper.bin", SCOPE_STAGE);190#endif191}192#endif193194void Newspaper_Serialize(void)195{196#if MANIA_USE_PLUS197RSDK_EDITABLE_VAR(Newspaper, VAR_UINT8, type);198#else199RSDK_EDITABLE_VAR(Newspaper, VAR_ENUM, node); // slotID of the target PlatformNode200RSDK_EDITABLE_VAR(Newspaper, VAR_ENUM, childCount);201#endif202}203204205