Path: blob/master/SonicMania/Objects/ERZ/RingField.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: RingField Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectRingField *RingField;1011void RingField_Update(void)12{13RSDK_THIS(RingField);1415if (self->running) {16bool32 inRange = false;17foreach_active(Player, player)18{19if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {20inRange = true;21}22}2324if (inRange) {25if (self->timer <= 0) {26Vector2 pos;27RingField_GetRingSpawnPos(&pos);2829EntityRing *ring = CREATE_ENTITY(Ring, &pos, pos.x, pos.y);30ring->animator.speed = 512;31ring->state = Ring_State_Normal;32ring->drawGroup = Zone->objectDrawGroup[0];33ring->stateDraw = Ring_Draw_Normal;34ring->moveType = RING_MOVE_FIXED;35RSDK.SetSpriteAnimation(RingField->aniFrames, 0, &ring->animator, true, 0);3637int32 sx = (ScreenInfo->center.x + ScreenInfo->position.x) << 16;38int32 sy = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;39int32 x = sx + (RSDK.Rand(-ScreenInfo->center.x, ScreenInfo->center.x) << 15);40int32 y = sy + (RSDK.Rand(-ScreenInfo->center.y, ScreenInfo->center.y) << 15);4142int32 angle = RSDK.ATan2(x - pos.x, y - pos.y);43ring->velocity.x = RSDK.Cos256(angle) << 9;44ring->velocity.y = RSDK.Sin256(angle) << 9;45self->timer = (self->fluctuation * RSDK.Sin256(Zone->timer) >> 8) + self->frequency;46}47else {48self->timer--;49}50}51}52}5354void RingField_LateUpdate(void) {}5556void RingField_StaticUpdate(void)57{58Vector2 range = { 0x400000, 0x400000 };5960foreach_all(Ring, ring)61{62if (ring->velocity.x || ring->velocity.y) {63ring->position.x += ring->velocity.x;64ring->position.y += ring->velocity.y;65}6667if (!RSDK.CheckOnScreen(ring, &range))68destroyEntity(ring);69}70}7172void RingField_Draw(void) {}7374void RingField_Create(void *data)75{76RSDK_THIS(RingField);7778self->active = ACTIVE_NORMAL;79self->drawGroup = Zone->objectDrawGroup[0];80self->startPos = self->position;81self->visible = false;82self->drawFX = FX_FLIP;83self->updateRange.x = 0x800000;84self->updateRange.y = 0x800000;8586if (!self->size.x)87self->size.x = 1600 << 16;8889if (!self->size.y)90self->size.y = 480 << 16;9192if (!self->frequency)93self->frequency = 60;9495if (!self->fluctuation)96self->fluctuation = 20;9798self->hitbox.left = -self->size.x >> 17;99self->hitbox.top = -self->size.y >> 17;100self->hitbox.right = self->size.x >> 17;101self->hitbox.bottom = self->size.y >> 17;102}103104void RingField_StageLoad(void) { RingField->aniFrames = RSDK.LoadSpriteAnimation("Global/Ring.bin", SCOPE_STAGE); }105106void RingField_GetRingSpawnPos(Vector2 *pos)107{108int32 rand = RSDK.Rand(0, 16) % 4;109int32 x = 0;110int32 y = 0;111112switch (rand) {113case 0:114case 1:115y = RSDK.Rand(-ScreenInfo->size.y, ScreenInfo->size.y) << 15;116117switch (rand) {118case 0: x += -0x100000 - (ScreenInfo->center.x << 16); break;119case 1: x += (ScreenInfo->center.x + 16) << 16; break;120case 2: y += -0x100000 - (ScreenInfo->center.y << 16); break;121case 3: y += (ScreenInfo->center.y + 16) << 16; break;122default: break;123}124break;125126case 2:127case 3:128x = RSDK.Rand(-ScreenInfo->size.x, ScreenInfo->size.x) << 15;129130switch (rand) {131case 0: x += -0x100000 - (ScreenInfo->center.x << 16); break;132case 1: x += (ScreenInfo->center.x + 16) << 16; break;133case 2: y += -0x100000 - (ScreenInfo->center.y << 16); break;134case 3: y += (ScreenInfo->center.y + 16) << 16; break;135default: break;136}137break;138139default: break;140}141142pos->x = x + ((ScreenInfo->position.x + ScreenInfo->center.x) << 16);143pos->y = y + ((ScreenInfo->position.y + ScreenInfo->center.y) << 16);144}145146#if GAME_INCLUDE_EDITOR147void RingField_EditorDraw(void)148{149RSDK_THIS(RingField);150151if (showGizmos()) {152RSDK_DRAWING_OVERLAY(true);153154if (!self->size.x)155self->size.x = 1600 << 16;156157if (!self->size.y)158self->size.y = 480 << 16;159160DrawHelpers_DrawRectOutline(self->position.x, self->position.y, self->size.x, self->size.y, 0xFFFF00);161162RSDK_DRAWING_OVERLAY(false);163}164}165166void RingField_EditorLoad(void) {}167#endif168169void RingField_Serialize(void)170{171RSDK_EDITABLE_VAR(RingField, VAR_VECTOR2, size);172RSDK_EDITABLE_VAR(RingField, VAR_ENUM, frequency);173RSDK_EDITABLE_VAR(RingField, VAR_ENUM, fluctuation);174RSDK_EDITABLE_VAR(RingField, VAR_BOOL, running);175}176177178