Path: blob/master/SonicMania/Objects/GHZ/Fireball.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: Fireball Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectFireball *Fireball = NULL;1011void Fireball_Update(void)12{13RSDK_THIS(Fireball);14StateMachine_Run(self->state);15}1617void Fireball_LateUpdate(void) {}1819void Fireball_StaticUpdate(void) {}2021void Fireball_Draw(void)22{23RSDK_THIS(Fireball);24StateMachine_Run(self->stateDraw);25}2627void Fireball_Create(void *data)28{29RSDK_THIS(Fireball);3031self->drawFX |= FX_ROTATE | FX_FLIP;32self->active = ACTIVE_BOUNDS;33self->visible = true;34self->updateRange.x = 0x800000;35self->updateRange.y = 0x800000;36self->drawGroup = Zone->objectDrawGroup[0];37RSDK.SetSpriteAnimation(Fireball->aniFrames, 0, &self->animator, true, 0);3839if (!SceneInfo->inEditor)40self->interval *= 15;4142if (data) {43self->state = (Type_StateMachine)data;44self->active = ACTIVE_NORMAL;45self->stateDraw = Fireball_Draw_Simple;46}47else {48self->groundVel <<= 7;49switch (self->type) {50default: break;51case FIREBALL_SPAWNER: self->state = Fireball_State_Spawner; break;52case FIREBALL_LAUNCHER_STATIC: self->state = Fireball_State_LauncherStatic; break;53case FIREBALL_LAUNCHER_GRAVITY: self->state = Fireball_State_LauncherGravity; break;54}55}56}5758void Fireball_StageLoad(void)59{60if (RSDK.CheckSceneFolder("GHZ"))61Fireball->aniFrames = RSDK.LoadSpriteAnimation("GHZ/Fireball.bin", SCOPE_STAGE);6263Fireball->hitboxFireball.left = -6;64Fireball->hitboxFireball.top = -6;65Fireball->hitboxFireball.right = 6;66Fireball->hitboxFireball.bottom = 6;6768Fireball->sfxFireball = RSDK.GetSfx("Stage/Fireball.wav");69}7071void Fireball_HandlePlayerInteractions(void)72{73RSDK_THIS(Fireball);7475foreach_active(Player, player)76{77if (Player_CheckCollisionTouch(player, self, &Fireball->hitboxFireball)) {78Player_ElementHurt(player, self, SHIELD_FIRE);79}80}81}8283void Fireball_State_Spawner(void)84{85RSDK_THIS(Fireball);8687if (!((Zone->timer + self->intervalOffset) % self->interval)) {88EntityFireball *fireball = CREATE_ENTITY(Fireball, Fireball_StateFireball_Spawner, self->position.x, self->position.y);8990fireball->angle = self->rotation;91fireball->rotation = self->rotation;9293fireball->groundVel = -self->groundVel;94fireball->velocity.x = fireball->groundVel * RSDK.Sin512(0x100 - fireball->angle);95fireball->velocity.y = fireball->groundVel * RSDK.Cos512(0x100 - fireball->angle);9697RSDK.PlaySfx(Fireball->sfxFireball, false, 0xFF);98}99}100101void Fireball_State_LauncherStatic(void)102{103RSDK_THIS(Fireball);104105if (!((Zone->timer + self->intervalOffset) % self->interval)) {106EntityFireball *fireball = CREATE_ENTITY(Fireball, Fireball_StateFireball_LauncherStatic, self->position.x, self->position.y);107108fireball->angle = self->rotation;109fireball->rotation = self->rotation;110111fireball->groundVel = -self->groundVel;112fireball->velocity.x = fireball->groundVel * RSDK.Sin512(0x100 - fireball->angle);113fireball->velocity.y = fireball->groundVel * RSDK.Cos512(0x100 - fireball->angle);114115RSDK.PlaySfx(Fireball->sfxFireball, false, 0xFF);116}117}118119void Fireball_State_LauncherGravity(void)120{121RSDK_THIS(Fireball);122123if (!((Zone->timer + self->intervalOffset) % self->interval)) {124EntityFireball *fireball = CREATE_ENTITY(Fireball, Fireball_StateFireball_LauncherGravity, self->position.x, self->position.y);125126fireball->angle = self->rotation;127fireball->rotation = self->rotation;128129fireball->groundVel = -self->groundVel;130fireball->velocity.x = fireball->groundVel * RSDK.Sin512(0x100 - fireball->angle);131fireball->velocity.y = fireball->groundVel * RSDK.Cos512(0x100 - fireball->angle);132133RSDK.PlaySfx(Fireball->sfxFireball, false, 255);134}135}136137void Fireball_StateFireball_Spawner(void)138{139RSDK_THIS(Fireball);140141self->position.x += self->velocity.x;142self->position.y += self->velocity.y;143144self->groundVel += 0x18;145self->velocity.x = self->groundVel * RSDK.Sin512(0x100 - self->angle);146self->velocity.y = self->groundVel * RSDK.Cos512(0x100 - self->angle);147148if (self->groundVel > 0)149self->rotation = self->angle + 0x100;150151if (!RSDK.CheckOnScreen(self, &self->updateRange))152destroyEntity(self);153154RSDK.ProcessAnimation(&self->animator);155156Fireball_HandlePlayerInteractions();157}158159void Fireball_StateFireball_LauncherStatic(void)160{161RSDK_THIS(Fireball);162163self->position.x += self->velocity.x;164self->position.y += self->velocity.y;165166if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, RSDK.Sin512(0x200 - self->rotation) << 10,167RSDK.Cos512(0x200 - self->rotation) << 10, true)) {168self->state = Fireball_StateFireball_Dissipate;169RSDK.SetSpriteAnimation(Fireball->aniFrames, 1, &self->animator, true, 0);170}171else {172if (RSDK.CheckOnScreen(self, &self->updateRange)) {173RSDK.ProcessAnimation(&self->animator);174Fireball_HandlePlayerInteractions();175}176else {177destroyEntity(self);178}179}180}181182void Fireball_StateFireball_LauncherGravity(void)183{184RSDK_THIS(Fireball);185186self->rotation = 2 * RSDK.ATan2((self->velocity.x >> 16), (self->velocity.y >> 16)) + 0x180;187188self->position.x += self->velocity.x;189self->position.y += self->velocity.y;190self->velocity.y += 0x3800;191192if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, RSDK.Sin512(0x200 - self->rotation) << 10,193RSDK.Cos512(0x200 - self->rotation) << 10, true)) {194self->state = Fireball_StateFireball_Dissipate;195RSDK.SetSpriteAnimation(Fireball->aniFrames, 1, &self->animator, true, 0);196}197else {198if (RSDK.CheckOnScreen(self, &self->updateRange)) {199RSDK.ProcessAnimation(&self->animator);200Fireball_HandlePlayerInteractions();201}202else {203destroyEntity(self);204}205}206}207208void Fireball_StateFireball_Dissipate(void)209{210RSDK_THIS(Fireball);211212RSDK.ProcessAnimation(&self->animator);213Fireball_HandlePlayerInteractions();214215if (self->animator.frameID == 2)216destroyEntity(self);217}218219void Fireball_Draw_Simple(void)220{221RSDK_THIS(Fireball);222223RSDK.DrawSprite(&self->animator, NULL, false);224}225226#if GAME_INCLUDE_EDITOR227void Fireball_EditorDraw(void)228{229RSDK_THIS(Fireball);230RSDK.SetSpriteAnimation(Fireball->aniFrames, 0, &self->animator, true, 0);231232Fireball_Draw_Simple();233}234235void Fireball_EditorLoad(void)236{237Fireball->aniFrames = RSDK.LoadSpriteAnimation("GHZ/Fireball.bin", SCOPE_STAGE);238239RSDK_ACTIVE_VAR(Fireball, type);240RSDK_ENUM_VAR("Spawner", FIREBALL_SPAWNER);241RSDK_ENUM_VAR("Launcher (Static Movement)", FIREBALL_LAUNCHER_STATIC);242RSDK_ENUM_VAR("Launcher (Gravity-Applied Movement)", FIREBALL_LAUNCHER_GRAVITY);243}244#endif245246void Fireball_Serialize(void)247{248RSDK_EDITABLE_VAR(Fireball, VAR_UINT8, type);249RSDK_EDITABLE_VAR(Fireball, VAR_INT32, rotation);250RSDK_EDITABLE_VAR(Fireball, VAR_UINT8, interval);251RSDK_EDITABLE_VAR(Fireball, VAR_UINT8, intervalOffset);252RSDK_EDITABLE_VAR(Fireball, VAR_ENUM, groundVel);253}254255256