Path: blob/master/SonicMania/Objects/Global/BoundsMarker.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: BoundsMarker Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectBoundsMarker *BoundsMarker;1011void BoundsMarker_Update(void)12{13RSDK_THIS(BoundsMarker);1415for (int32 p = 0; p < Player->playerCount; ++p) {16EntityPlayer *player = RSDK_GET_ENTITY(p, Player);17BoundsMarker_ApplyBounds(player, self, false);18}19}2021void BoundsMarker_LateUpdate(void) {}2223void BoundsMarker_StaticUpdate(void) {}2425void BoundsMarker_Draw(void) {}2627void BoundsMarker_Create(void *data)28{29RSDK_THIS(BoundsMarker);3031if (!SceneInfo->inEditor) {32if (self->vsDisable && globals->gameMode == MODE_COMPETITION) {33destroyEntity(self);34}35else {36self->active = ACTIVE_XBOUNDS;37self->width = self->width ? (self->width << 15) : (48 << 15);38self->updateRange.x += self->width << 15;3940for (int32 p = 0; p < Player->playerCount; ++p) {41EntityPlayer *player = RSDK_GET_ENTITY(p, Player);42BoundsMarker_ApplyBounds(player, self, true);43}44}45}46}4748void BoundsMarker_StageLoad(void) {}4950void BoundsMarker_ApplyBounds(EntityPlayer *player, EntityBoundsMarker *marker, bool32 setPos)51{52uint16 playerID = RSDK.GetEntitySlot(player);5354if (Player_CheckValidState(player) || player->classID == DebugMode->classID) {55if (abs(marker->position.x - player->position.x) < marker->width) {56switch (marker->type) {57case BOUNDSMARKER_ANY_Y:58Zone->playerBoundsB[playerID] = marker->position.y;59Zone->cameraBoundsB[playerID] = FROM_FIXED(Zone->playerBoundsB[playerID]);60Zone->deathBoundary[playerID] = marker->position.y;61break;6263case BOUNDSMARKER_ABOVE_Y:64if (player->position.y < marker->position.y - (marker->offset << 16)) {65Zone->playerBoundsB[playerID] = marker->position.y;66Zone->cameraBoundsB[playerID] = FROM_FIXED(Zone->playerBoundsB[playerID]);67Zone->deathBoundary[playerID] = marker->position.y;68}69break;7071case BOUNDSMARKER_BELOW_Y:72if (player->position.y > marker->position.y + (marker->offset << 16)) {73Zone->playerBoundsT[playerID] = marker->position.y;74Zone->cameraBoundsT[playerID] = FROM_FIXED(Zone->playerBoundsT[playerID]);75}76break;7778case BOUNDSMARKER_BELOW_Y_ANY:79Zone->playerBoundsT[playerID] = marker->position.y;80Zone->cameraBoundsT[playerID] = FROM_FIXED(Zone->playerBoundsT[playerID]);81break;8283default: break;84}85}8687if (setPos) {88EntityCamera *camera = player->camera;89if (camera) {90camera->boundsL = Zone->cameraBoundsL[playerID];91camera->boundsR = Zone->cameraBoundsR[playerID];92camera->boundsT = Zone->cameraBoundsT[playerID];93camera->boundsB = Zone->cameraBoundsB[playerID];94}95}96}97}98void BoundsMarker_ApplyAllBounds(EntityPlayer *player, bool32 setPos)99{100if (Player_CheckValidState(player) || player->classID == DebugMode->classID) {101foreach_all(BoundsMarker, entity) { BoundsMarker_ApplyBounds(player, entity, setPos); }102}103}104105#if GAME_INCLUDE_EDITOR106void BoundsMarker_EditorDraw(void)107{108RSDK_THIS(BoundsMarker);109110Animator animator;111RSDK.SetSpriteAnimation(BoundsMarker->aniFrames, 0, &animator, true, 2);112RSDK.DrawSprite(&animator, NULL, false);113114int32 w = self->width ? (self->width << 15) : (48 << 15);115self->updateRange.x = w;116117// Bounds118RSDK_DRAWING_OVERLAY(true);119120RSDK.DrawLine(self->position.x - w, self->position.y, self->position.x + w, self->position.y, 0xFFFF00, 0xFF, INK_NONE, false);121if (self->type == BOUNDSMARKER_ABOVE_Y) {122RSDK.DrawLine(self->position.x + w, self->position.y - (self->offset << 16), self->position.x + w, self->position.y - (self->offset << 16),1230xFFFF00, 0x80, INK_BLEND, false);124}125else if (self->type == BOUNDSMARKER_BELOW_Y) {126RSDK.DrawLine(self->position.x + w, self->position.y + (self->offset << 16), self->position.x + w, self->position.y + (self->offset << 16),1270xFFFF00, 0x80, INK_BLEND, false);128}129130RSDK_DRAWING_OVERLAY(false);131}132133void BoundsMarker_EditorLoad(void)134{135BoundsMarker->aniFrames = RSDK.LoadSpriteAnimation("Editor/EditorIcons.bin", SCOPE_STAGE);136137RSDK_ACTIVE_VAR(BoundsMarker, type);138RSDK_ENUM_VAR("Any Y", BOUNDSMARKER_ANY_Y);139RSDK_ENUM_VAR("Above Y", BOUNDSMARKER_ABOVE_Y);140RSDK_ENUM_VAR("Below Y", BOUNDSMARKER_BELOW_Y);141RSDK_ENUM_VAR("Below Y Any", BOUNDSMARKER_BELOW_Y_ANY);142}143#endif144145void BoundsMarker_Serialize(void)146{147RSDK_EDITABLE_VAR(BoundsMarker, VAR_UINT8, type);148RSDK_EDITABLE_VAR(BoundsMarker, VAR_ENUM, width);149RSDK_EDITABLE_VAR(BoundsMarker, VAR_BOOL, vsDisable);150RSDK_EDITABLE_VAR(BoundsMarker, VAR_ENUM, offset);151}152153154