Path: blob/master/SonicMania/Objects/SPZ/PopcornKernel.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PopcornKernel Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPopcornKernel *PopcornKernel;1011void PopcornKernel_Update(void)12{13RSDK_THIS(PopcornKernel);1415StateMachine_Run(self->state);1617self->angle += self->angleVel;18self->rotation = (self->angle >> 15) & 0x1FF;19}2021void PopcornKernel_LateUpdate(void) {}2223void PopcornKernel_StaticUpdate(void) {}2425void PopcornKernel_Draw(void)26{27RSDK_THIS(PopcornKernel);2829RSDK.DrawSprite(&self->animator, NULL, false);30}3132void PopcornKernel_Create(void *data)33{34RSDK_THIS(PopcornKernel);3536if (!SceneInfo->inEditor) {37self->drawFX = FX_ROTATE;38self->state = PopcornKernel_State_BounceAround;3940RSDK.SetSpriteAnimation(PopcornKernel->aniFrames, 1, &self->animator, true, RSDK.Rand(0, 7));41if (self->animator.frameID >= 0 && (self->animator.frameID <= 1 || self->animator.frameID == 5))42self->drawGroup = Zone->objectDrawGroup[0] - 1;43else44self->drawGroup = Zone->objectDrawGroup[0];4546self->active = ACTIVE_NORMAL;47self->updateRange.x = 0x800000;48self->updateRange.y = 0x2000000;49self->gravityStrength = 0x4000;50self->scale.x = 0x200;51self->scale.y = 0x200;52self->visible = true;53}54}5556void PopcornKernel_StageLoad(void) { PopcornKernel->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/PopcornMachine.bin", SCOPE_STAGE); }5758void PopcornKernel_State_BounceAround(void)59{60RSDK_THIS(PopcornKernel);6162self->velocity.y += self->gravityStrength;63self->position.x += self->velocity.x;64self->position.y += self->velocity.y;6566if (self->velocity.y >= 0) {67foreach_active(PopcornKernel, kernel)68{69if (kernel != self) {70int32 rx = (self->position.x - kernel->position.x) >> 16;71int32 ry = (self->position.y - kernel->position.y) >> 16;72if (rx * rx + ry * ry < 0x100) {73int32 angle = RSDK.ATan2(rx, ry);74self->velocity.x = RSDK.Cos256(angle) << 17 >> 8;75self->velocity.y = RSDK.Sin256(angle) << 17 >> 8;76}77}78}79}8081if (self->position.x < self->bounds.x - 0x680000) {82self->position.x = self->bounds.x - 0x680000;83self->velocity.x = -self->velocity.x;84}85else if (self->position.x > self->bounds.x + 0x680000) {86self->position.x = self->bounds.x + 0x680000;87self->velocity.x = -self->velocity.x;88}8990if (self->position.y > self->bounds.y - 0x380000) {91self->position.y = self->bounds.y - 0x380000;92self->velocity.y = -self->velocity.y >> 1;93}94}9596void PopcornKernel_State_RiseUp(void)97{98RSDK_THIS(PopcornKernel);99100self->velocity.y += 0x800;101self->position.x += self->velocity.x;102self->position.y += self->velocity.y;103104if (self->position.y < self->maxY) {105self->state = PopcornKernel_State_FallDown;106//???107// Dunno why this is here but removing it would change the internal randSeed108RSDK.Rand(-0x80000, 0x80000);109}110}111112void PopcornKernel_State_FallDown(void)113{114RSDK_THIS(PopcornKernel);115116self->velocity.y += 0x3800;117self->position.x += self->velocity.x;118self->position.y += self->velocity.y;119120if (!RSDK.CheckOnScreen(self, NULL))121destroyEntity(self);122}123124#if GAME_INCLUDE_EDITOR125void PopcornKernel_EditorDraw(void)126{127RSDK_THIS(PopcornKernel);128RSDK.SetSpriteAnimation(PopcornKernel->aniFrames, 1, &self->animator, true, 0);129130PopcornKernel_Draw();131}132133void PopcornKernel_EditorLoad(void) { PopcornKernel->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/PopcornMachine.bin", SCOPE_STAGE); }134#endif135136void PopcornKernel_Serialize(void) {}137138139