Path: blob/master/SonicMania/Objects/LRZ/LRZConvDropper.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: LRZConvDropper Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectLRZConvDropper *LRZConvDropper;1011void LRZConvDropper_Update(void)12{13RSDK_THIS(LRZConvDropper);1415self->visible = DebugMode->debugActive;1617switch (self->triggerMode) {18case LRZCONVDROP_TRIGGER_BUTTON:19if (!((Zone->timer + self->intervalOffset) % self->interval))20LRZConvDropper_HandleButtonDrop(self);21break;2223case LRZCONVDROP_TRIGGER_PLAYER: {24bool32 shouldDrop = false;25bool32 playerEntered = false;2627self->position.x += self->detectOffset.x;28self->position.y += self->detectOffset.y;29foreach_active(Player, player)30{31int32 playerID = RSDK.GetEntitySlot(player);3233bool32 triggered = false;34if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {35triggered = true;36}3738if (!((1 << playerID) & self->activePlayers) && triggered) {39if (!player->sidekick)40playerEntered = true;41self->activePlayers |= 1 << playerID;42}4344if ((1 << playerID) & self->activePlayers) {45if (!player->sidekick)46shouldDrop = true;4748if (!triggered)49self->activePlayers &= ~(1 << playerID);50}51}52self->position.x -= self->detectOffset.x;53self->position.y -= self->detectOffset.y;5455if (playerEntered) {56if (!self->timerStore || Zone->timer - self->timerStore > self->interval)57self->timerStore = Zone->timer;58}5960if (shouldDrop) {61int32 timer = Zone->timer - self->timerStore;62if (!((timer + self->intervalOffset) % self->interval))63LRZConvDropper_HandleButtonDrop(self);64}65break;66}67}68}6970void LRZConvDropper_LateUpdate(void) {}7172void LRZConvDropper_StaticUpdate(void) {}7374void LRZConvDropper_Draw(void)75{76RSDK_THIS(LRZConvDropper);7778RSDK.DrawSprite(&self->animator, NULL, false);7980if (self->triggerMode == LRZCONVDROP_TRIGGER_PLAYER) {81int32 x = self->detectOffset.x + self->position.x;82int32 y = self->detectOffset.y + self->position.y;83RSDK.DrawLine(self->position.x, self->position.y, x, y, 0xFFFFFF, 0x7F, INK_NONE, false);84DrawHelpers_DrawHitboxOutline(x, y, &self->hitbox, 0, 0xFFFFFF);85}86}8788void LRZConvDropper_Create(void *data)89{90RSDK_THIS(LRZConvDropper);9192self->active = ACTIVE_BOUNDS;93self->drawGroup = Zone->objectDrawGroup[0];94self->visible = true;95self->drawFX = FX_FLIP;96self->updateRange.x = 0x800000;97self->updateRange.y = 0x800000;9899if (self->triggerMode == LRZCONVDROP_TRIGGER_PLAYER) {100self->updateRange.x = (self->detectSize.x >> 1) + 0x1000000;101self->updateRange.y = (self->detectSize.y >> 1) + 0x1000000;102}103104self->hitbox.left = -(self->detectSize.x >> 17);105self->hitbox.top = -(self->detectSize.y >> 17);106self->hitbox.right = self->detectSize.x >> 17;107self->hitbox.bottom = self->detectSize.y >> 17;108109LRZConvDropper_SetupDropperChildren();110111RSDK.SetSpriteAnimation(LRZConvDropper->aniFrames, 0, &self->animator, true, 0);112}113114void LRZConvDropper_StageLoad(void) { LRZConvDropper->aniFrames = RSDK.LoadSpriteAnimation("LRZ2/LRZConvDropper.bin", SCOPE_STAGE); }115116void LRZConvDropper_SetupDropperChildren(void)117{118RSDK_THIS(LRZConvDropper);119120int32 slot = RSDK.GetEntitySlot(self) - self->seqCount;121for (int32 i = 0; i < self->seqCount; ++i) {122EntityLRZConvItem *child = RSDK_GET_ENTITY(slot++, LRZConvItem);123child->active = ACTIVE_NEVER;124child->visible = false;125}126}127128void LRZConvDropper_HandleButtonDrop(EntityLRZConvDropper *entity)129{130if (entity->seqCount && entity->seqPos < entity->seqCount) {131int32 slot = RSDK.GetEntitySlot(entity);132int32 seqPos = entity->seqPos - entity->seqCount;133EntityLRZConvItem *seqEnt = RSDK_GET_ENTITY(slot + seqPos, LRZConvItem);134135if (seqEnt->classID == LRZConvItem->classID) {136EntityLRZConvItem *item = CREATE_ENTITY(LRZConvItem, INT_TO_VOID(seqEnt->type), entity->position.x, entity->position.y);137item->active = ACTIVE_NORMAL;138item->velocity.x = 0;139item->velocity.y = 0;140}141else if (seqEnt->classID == Iwamodoki->classID) {142EntityIwamodoki *iwamadoki = CREATE_ENTITY(Iwamodoki, NULL, entity->position.x, entity->position.y);143iwamadoki->active = ACTIVE_NORMAL;144iwamadoki->state = Iwamodoki_State_AwaitPlayer;145iwamadoki->velocity.x = 0;146iwamadoki->velocity.y = 0;147iwamadoki->lrzConvPhys = true;148}149else if (seqEnt->classID == ItemBox->classID) {150EntityItemBox *seqBox = (EntityItemBox *)seqEnt;151152EntityItemBox *itembox = CREATE_ENTITY(ItemBox, INT_TO_VOID(seqBox->type), entity->position.x, entity->position.y);153itembox->active = ACTIVE_NORMAL;154itembox->velocity.x = 0;155itembox->velocity.y = 0;156itembox->lrzConvPhys = true;157itembox->direction = seqEnt->direction;158itembox->state = ItemBox_State_Conveyor;159}160161if (++entity->seqPos >= entity->seqCount) {162if (entity->seqLoop)163entity->seqPos %= entity->seqCount;164}165}166}167168#if GAME_INCLUDE_EDITOR169void LRZConvDropper_EditorDraw(void)170{171RSDK_THIS(LRZConvDropper);172173RSDK.DrawSprite(&self->animator, NULL, false);174175if (self->triggerMode == LRZCONVDROP_TRIGGER_PLAYER && showGizmos()) {176RSDK_DRAWING_OVERLAY(true);177178int32 x = self->detectOffset.x + self->position.x;179int32 y = self->detectOffset.y + self->position.y;180181RSDK.DrawLine(self->position.x, self->position.y, x, y, 0xFFFFFF, 0x7F, INK_NONE, false);182DrawHelpers_DrawHitboxOutline(x, y, &self->hitbox, 0, 0xFFFFFF);183184int32 slot = RSDK.GetEntitySlot(self) - self->seqCount;185for (int32 i = 0; i < self->seqCount; ++i) {186EntityLRZConvItem *child = RSDK_GET_ENTITY(slot++, LRZConvItem);187188if (child)189DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xFFFF00, INK_NONE, 0xFF);190}191192RSDK_DRAWING_OVERLAY(false);193}194}195196void LRZConvDropper_EditorLoad(void)197{198LRZConvDropper->aniFrames = RSDK.LoadSpriteAnimation("LRZ2/LRZConvDropper.bin", SCOPE_STAGE);199200RSDK_ACTIVE_VAR(LRZConvDropper, triggerMode);201RSDK_ENUM_VAR("Button", LRZCONVDROP_TRIGGER_BUTTON);202RSDK_ENUM_VAR("Player", LRZCONVDROP_TRIGGER_PLAYER);203}204#endif205206void LRZConvDropper_Serialize(void)207{208RSDK_EDITABLE_VAR(LRZConvDropper, VAR_UINT8, triggerMode);209RSDK_EDITABLE_VAR(LRZConvDropper, VAR_ENUM, interval);210RSDK_EDITABLE_VAR(LRZConvDropper, VAR_ENUM, intervalOffset);211RSDK_EDITABLE_VAR(LRZConvDropper, VAR_VECTOR2, detectOffset);212RSDK_EDITABLE_VAR(LRZConvDropper, VAR_VECTOR2, detectSize);213RSDK_EDITABLE_VAR(LRZConvDropper, VAR_UINT8, seqCount);214RSDK_EDITABLE_VAR(LRZConvDropper, VAR_BOOL, seqLoop);215}216217218