Path: blob/master/SonicMania/Objects/CPZ/ChemicalBall.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: ChemicalBall Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectChemicalBall *ChemicalBall;1011void ChemicalBall_Update(void)12{13RSDK_THIS(ChemicalBall);1415if (globals->gameMode == MODE_TIMEATTACK && TimeAttackGate && TimeAttackGate->isFinished)16destroyEntity(self);1718StateMachine_Run(self->state);19}2021void ChemicalBall_LateUpdate(void) {}2223void ChemicalBall_StaticUpdate(void) {}2425void ChemicalBall_Draw(void)26{27RSDK_THIS(ChemicalBall);2829RSDK.DrawSprite(&self->animator, &self->drawPos, false);30}3132void ChemicalBall_Create(void *data)33{34RSDK_THIS(ChemicalBall);3536self->visible = true;37self->drawGroup = Zone->objectDrawGroup[0];38self->startPos = self->position;39self->active = ACTIVE_BOUNDS;40self->updateRange.x = 0x1000000;41self->updateRange.y = 0x1000000;4243if (!self->interval)44self->interval = 128;4546self->drawPos = self->position;4748if (self->direction == FLIP_NONE)49self->position.x += 0x320000;50else51self->position.x -= 0x320000;5253if (self->type == CHEMICALBALL_VERTICAL)54self->position.y -= 0x480000;5556RSDK.SetSpriteAnimation(ChemicalBall->aniFrames, 0, &self->animator, true, 0);5758if (!self->type)59self->state = ChemicalBall_State_MoveArc;60else61self->state = ChemicalBall_State_MoveVertical;62}6364void ChemicalBall_StageLoad(void)65{66ChemicalBall->aniFrames = RSDK.LoadSpriteAnimation("CPZ/ChemicalBall.bin", SCOPE_STAGE);6768ChemicalBall->hitboxBall.left = -8;69ChemicalBall->hitboxBall.top = -8;70ChemicalBall->hitboxBall.right = 8;71ChemicalBall->hitboxBall.bottom = 8;7273ChemicalBall->sfxBloop = RSDK.GetSfx("Stage/Bloop.wav");74}7576void ChemicalBall_CheckHit(void)77{78RSDK_THIS(ChemicalBall);7980foreach_active(Player, player)81{82Vector2 posStore = self->position;83self->position = self->drawPos;84if (Player_CheckCollisionTouch(player, self, &ChemicalBall->hitboxBall)) {85self->position = posStore;86Player_Hurt(player, self);87}88else {89self->position = posStore;90}91}92}9394void ChemicalBall_State_MoveArc(void)95{96RSDK_THIS(ChemicalBall);9798int32 timer = (Zone->timer + self->intervalOffset) % (2 * self->interval);99if (timer < self->interval == (self->direction != FLIP_NONE)) {100if (!self->direction)101timer -= self->interval;102103if (timer >= 96) {104self->drawPos.x = ChemicalBall->arcOffsets[0];105self->drawPos.y = ChemicalBall->arcOffsets[1];106}107else {108self->drawPos.x = ChemicalBall->arcOffsets[2 * (97 - timer)];109self->drawPos.y = ChemicalBall->arcOffsets[2 * (97 - timer) + 1];110}111}112else {113if (self->direction == FLIP_X)114timer -= self->interval;115116if (timer >= 97) {117self->drawPos.x = ChemicalBall->arcOffsets[194];118self->drawPos.y = ChemicalBall->arcOffsets[195];119}120else {121self->drawPos.x = ChemicalBall->arcOffsets[2 * timer];122self->drawPos.y = ChemicalBall->arcOffsets[2 * timer + 1];123}124}125126self->drawPos.x += self->position.x;127self->drawPos.y += self->position.y;128129if (!timer || timer == self->interval)130RSDK.PlaySfx(ChemicalBall->sfxBloop, false, 255);131132ChemicalBall_CheckHit();133}134135void ChemicalBall_State_MoveVertical(void)136{137RSDK_THIS(ChemicalBall);138139int32 timer = (Zone->timer + self->intervalOffset) % self->interval;140if (timer < 98) {141if (timer >= 49) {142if (!self->direction)143self->drawPos.x = -0x320000;144else145self->drawPos.x = 0x2E0000;146self->drawPos.y = ChemicalBall->moveOffsets[97 - timer];147}148else {149if (!self->direction)150self->drawPos.x = 0x2E0000;151else152self->drawPos.x = -0x320000;153self->drawPos.y = ChemicalBall->moveOffsets[timer];154}155}156self->drawPos.x += self->position.x;157self->drawPos.y += self->position.y;158159if (timer == 27 || timer == 48)160RSDK.PlaySfx(ChemicalBall->sfxBloop, false, 255);161162ChemicalBall_CheckHit();163}164165#if GAME_INCLUDE_EDITOR166void ChemicalBall_EditorDraw(void)167{168RSDK_THIS(ChemicalBall);169170RSDK.SetSpriteAnimation(ChemicalBall->aniFrames, 0, &self->animator, true, 0);171172self->drawPos = self->position;173if (self->direction == FLIP_NONE)174self->drawPos.x += 0x320000;175else176self->drawPos.x -= 0x320000;177178if (self->type == CHEMICALBALL_VERTICAL)179self->drawPos.y -= 0x480000;180181ChemicalBall_Draw();182183if (showGizmos()) {184RSDK_DRAWING_OVERLAY(true);185186self->drawPos = self->position;187self->inkEffect = INK_BLEND;188ChemicalBall_Draw();189self->inkEffect = INK_NONE;190191RSDK_DRAWING_OVERLAY(false);192}193}194195void ChemicalBall_EditorLoad(void)196{197ChemicalBall->aniFrames = RSDK.LoadSpriteAnimation("CPZ/ChemicalBall.bin", SCOPE_STAGE);198199RSDK_ACTIVE_VAR(ChemicalBall, type);200RSDK_ENUM_VAR("Arc", CHEMICALBALL_ARC);201RSDK_ENUM_VAR("Vertical", CHEMICALBALL_VERTICAL);202203RSDK_ACTIVE_VAR(ChemicalBall, direction);204RSDK_ENUM_VAR("No Flip", FLIP_NONE);205RSDK_ENUM_VAR("Flipped", FLIP_X);206}207#endif208209void ChemicalBall_Serialize(void)210{211RSDK_EDITABLE_VAR(ChemicalBall, VAR_UINT8, type);212RSDK_EDITABLE_VAR(ChemicalBall, VAR_UINT8, direction);213RSDK_EDITABLE_VAR(ChemicalBall, VAR_UINT8, interval);214RSDK_EDITABLE_VAR(ChemicalBall, VAR_UINT8, intervalOffset);215RSDK_EDITABLE_VAR(ChemicalBall, VAR_BOOL, master); // unused, (looks to be set on the first instance of arc types)216}217218219