Path: blob/master/SonicMania/Objects/SSZ/FlowerPod.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: FlowerPod Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectFlowerPod *FlowerPod;1011void FlowerPod_Update(void)12{13RSDK_THIS(FlowerPod);1415StateMachine_Run(self->state);16}1718void FlowerPod_LateUpdate(void) {}1920void FlowerPod_StaticUpdate(void) {}2122void FlowerPod_Draw(void)23{24RSDK_THIS(FlowerPod);2526RSDK.DrawSprite(&self->podAnimator, NULL, false);27RSDK.DrawSprite(&self->stemAnimator, NULL, false);28}2930void FlowerPod_Create(void *data)31{32RSDK_THIS(FlowerPod);3334if (!SceneInfo->inEditor) {35self->active = ACTIVE_BOUNDS;36self->visible = true;37self->drawFX = FX_FLIP;38self->drawGroup = Zone->objectDrawGroup[0];39self->updateRange.x = 0x800000;40self->updateRange.y = 0x800000;4142if (data) {43self->drawFX = FX_ROTATE | FX_FLIP;44RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 3, &self->stemAnimator, true, 0);45self->active = ACTIVE_NORMAL;46self->state = FlowerPod_State_SeedFall;47}48else {49RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 0, &self->stemAnimator, true, 0);50RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 1, &self->podAnimator, true, 0);51self->state = FlowerPod_State_Pod;52}53}54}5556void FlowerPod_StageLoad(void)57{58if (RSDK.CheckSceneFolder("SSZ1"))59FlowerPod->aniFrames = RSDK.LoadSpriteAnimation("SSZ1/FlowerPod.bin", SCOPE_STAGE);6061FlowerPod->hitboxPod.top = -36;62FlowerPod->hitboxPod.left = -32;63FlowerPod->hitboxPod.right = 32;64FlowerPod->hitboxPod.bottom = 0;6566FlowerPod->sfxExplosion = RSDK.GetSfx("Stage/Explosion2.wav");67FlowerPod->sfxTwinkle = RSDK.GetSfx("Global/Twinkle.wav");68}6970void FlowerPod_SpawnSeeds(void)71{72RSDK_THIS(FlowerPod);7374for (int32 v = -0x10000; v < 0x18000; v += 0x8000) {75EntityFlowerPod *seed = CREATE_ENTITY(FlowerPod, INT_TO_VOID(true), self->position.x, self->position.y);76seed->isPermanent = true;77seed->velocity.x = v;78seed->velocity.y = -0x30000;79seed->drawGroup = Zone->objectDrawGroup[0];80}81}8283void FlowerPod_State_Pod(void)84{85RSDK_THIS(FlowerPod);8687RSDK.ProcessAnimation(&self->podAnimator);8889foreach_active(Player, player)90{91if (Player_CheckAttackingNoInvTimer(player, self) && Player_CheckBadnikTouch(player, self, &FlowerPod->hitboxPod))92self->state = FlowerPod_State_Exploding;93}94}9596void FlowerPod_State_Exploding(void)97{98RSDK_THIS(FlowerPod);99100if (!(Zone->timer % 3)) {101RSDK.PlaySfx(FlowerPod->sfxExplosion, false, 255);102103if ((Zone->timer & 4)) {104int32 x = self->position.x + (RSDK.Rand(-32, 32) << 16);105int32 y = self->position.y + (RSDK.Rand(-32, 0) << 16);106EntityExplosion *explosion = CREATE_ENTITY(Explosion, INT_TO_VOID((RSDK.Rand(0, 256) > 192) + 2), x, y);107explosion->drawGroup = Zone->objectDrawGroup[1];108}109}110111if (++self->timer == 30) {112RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 2, &self->podAnimator, true, 0);113self->state = 0;114RSDK.PlaySfx(FlowerPod->sfxTwinkle, false, 255);115116FlowerPod_SpawnSeeds();117self->timer = 48;118self->state = FlowerPod_State_Destroyed;119}120}121122void FlowerPod_State_Destroyed(void)123{124RSDK_THIS(FlowerPod);125126if (self->timer > 0) {127self->visible = (self->timer & 4) != 0;128self->timer--;129}130else {131destroyEntity(self);132}133}134135void FlowerPod_State_SeedFall(void)136{137RSDK_THIS(FlowerPod);138139self->velocity.y += 0x1C00;140self->position.x += self->velocity.x;141self->position.y += self->velocity.y;142143self->rotation = 2 * RSDK.ATan2(self->velocity.x, self->velocity.y);144145if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, 0, true)) {146self->rotation = 0;147self->timer = 30;148RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 4, &self->stemAnimator, true, 0);149self->state = FlowerPod_State_SpawnBeanstalk;150}151152RSDK.ProcessAnimation(&self->stemAnimator);153}154155void FlowerPod_State_SpawnBeanstalk(void)156{157RSDK_THIS(FlowerPod);158159if (self->timer <= 15) {160Hitbox hitboxSeed;161hitboxSeed.left = -4;162hitboxSeed.top = -4;163hitboxSeed.right = 4;164hitboxSeed.bottom = 4;165foreach_active(Beanstalk, beanstalk)166{167if (!beanstalk->type && RSDK.CheckObjectCollisionTouchBox(beanstalk, &Beanstalk->hitboxSeed, self, &hitboxSeed))168beanstalk->startGrowth = true;169}170171RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 5, &self->podAnimator, true, 0);172RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 6, &self->stemAnimator, true, 0);173174self->startPos = self->position;175self->state = FlowerPod_State_FlowerGrow;176}177else {178self->timer--;179}180181RSDK.ProcessAnimation(&self->stemAnimator);182}183184void FlowerPod_State_FlowerGrow(void)185{186RSDK_THIS(FlowerPod);187188if (self->position.y <= self->startPos.y - 0x200000) {189self->active = ACTIVE_BOUNDS;190self->state = FlowerPod_State_Flower;191}192else {193self->position.y -= 0x40000;194}195196FlowerPod_State_Flower();197}198199void FlowerPod_State_Flower(void)200{201RSDK_THIS(FlowerPod);202203RSDK.ProcessAnimation(&self->stemAnimator);204RSDK.ProcessAnimation(&self->podAnimator);205}206207#if GAME_INCLUDE_EDITOR208void FlowerPod_EditorDraw(void)209{210RSDK_THIS(FlowerPod);211212RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 0, &self->stemAnimator, false, 0);213RSDK.SetSpriteAnimation(FlowerPod->aniFrames, 1, &self->podAnimator, false, 0);214215FlowerPod_Draw();216}217218void FlowerPod_EditorLoad(void) { FlowerPod->aniFrames = RSDK.LoadSpriteAnimation("SSZ1/FlowerPod.bin", SCOPE_STAGE); }219#endif220221void FlowerPod_Serialize(void) {}222223224