Path: blob/master/SonicMania/Objects/Unused/Wisp.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: Wisp Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectWisp *Wisp = NULL;1011void Wisp_Update(void)12{13RSDK_THIS(Wisp);14StateMachine_Run(self->state);15}1617void Wisp_LateUpdate(void) {}1819void Wisp_StaticUpdate(void) {}2021void Wisp_Draw(void)22{23RSDK_THIS(Wisp);2425RSDK.DrawSprite(&self->bodyAnimator, NULL, false);2627self->inkEffect = INK_ALPHA;28RSDK.DrawSprite(&self->wingAnimator, NULL, false);2930self->inkEffect = INK_NONE;31}3233void Wisp_Create(void *data)34{35RSDK_THIS(Wisp);3637self->visible = true;38self->drawGroup = Zone->objectDrawGroup[0];39self->drawFX |= FX_FLIP;40self->startPos = self->position;41self->active = ACTIVE_BOUNDS;42self->updateRange.x = 0x800000;43self->updateRange.y = 0x800000;44self->direction = FLIP_NONE;45self->target = NULL;46self->alpha = 0xC0;47self->timer = 16;48self->buzzCount = 4;49RSDK.SetSpriteAnimation(Wisp->aniFrames, 0, &self->bodyAnimator, true, 0);50RSDK.SetSpriteAnimation(Wisp->aniFrames, 1, &self->wingAnimator, true, 0);5152self->state = Wisp_State_Init;53}5455void Wisp_StageLoad(void)56{57Wisp->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/Wisp.bin", SCOPE_STAGE);5859Wisp->hitboxBadnik.left = -8;60Wisp->hitboxBadnik.top = -8;61Wisp->hitboxBadnik.right = 8;62Wisp->hitboxBadnik.bottom = 8;6364DEBUGMODE_ADD_OBJ(Wisp);65}6667void Wisp_DebugSpawn(void)68{69RSDK_THIS(DebugMode);7071CREATE_ENTITY(Wisp, NULL, self->position.x, self->position.y);72}7374void Wisp_DebugDraw(void)75{76RSDK.SetSpriteAnimation(Wisp->aniFrames, 0, &DebugMode->animator, true, 0);77RSDK.DrawSprite(&DebugMode->animator, NULL, false);78}7980void Wisp_HandlePlayerInteractions(void)81{82RSDK_THIS(Wisp);8384foreach_active(Player, player)85{86EntityPlayer *target = self->target;87if (target) {88if (abs(player->position.x - self->position.x) < abs(target->position.x - self->position.x))89self->target = player;90}91else {92self->target = player;93}9495if (Player_CheckBadnikTouch(player, self, &Wisp->hitboxBadnik))96Player_CheckBadnikBreak(player, self, true);97}98}99100void Wisp_CheckOffScreen(void)101{102RSDK_THIS(Wisp);103104if (!RSDK.CheckOnScreen(self, NULL) && !RSDK.CheckPosOnScreen(&self->startPos, &self->updateRange)) {105self->position.x = self->startPos.x;106self->position.y = self->startPos.y;107Wisp_Create(NULL);108}109}110111void Wisp_State_Init(void)112{113RSDK_THIS(Wisp);114115self->active = ACTIVE_NORMAL;116self->velocity.x = 0;117self->velocity.y = 0;118119self->state = Wisp_State_Idle;120Wisp_State_Idle();121}122123void Wisp_State_Idle(void)124{125RSDK_THIS(Wisp);126127if (!--self->timer) {128if (--self->buzzCount) {129self->velocity.y = -0x10000;130self->timer = 96;131self->state = Wisp_State_FlyTowardTarget;132}133else {134self->velocity.x = -0x20000;135self->velocity.y = -0x20000;136self->state = Wisp_State_FlyAway;137}138}139140RSDK.ProcessAnimation(&self->wingAnimator);141142Wisp_HandlePlayerInteractions();143Wisp_CheckOffScreen();144}145146void Wisp_State_FlyTowardTarget(void)147{148RSDK_THIS(Wisp);149150self->position.x += self->velocity.x;151self->position.y += self->velocity.y;152153EntityPlayer *target = self->target;154if (target) {155if (target->position.x >= self->position.x) {156self->velocity.x += 0x1000;157self->direction = FLIP_X;158if (self->velocity.x > 0x20000)159self->velocity.x = 0x20000;160}161else {162self->velocity.x -= 0x1000;163self->direction = FLIP_NONE;164if (self->velocity.x < -0x20000)165self->velocity.x = -0x20000;166}167168if (target->position.y >= self->position.y) {169self->velocity.y += 0x1000;170if (self->velocity.y > 0x20000)171self->velocity.y = 0x20000;172}173else {174self->velocity.y -= 0x1000;175if (self->velocity.y < -0x20000)176self->velocity.y = -0x20000;177}178}179180if (!--self->timer) {181self->timer = RSDK.Rand(0, 32);182self->state = Wisp_State_Idle;183self->velocity.x = 0;184self->velocity.y = 0;185self->direction = FLIP_NONE;186}187RSDK.ProcessAnimation(&self->wingAnimator);188189Wisp_HandlePlayerInteractions();190Wisp_CheckOffScreen();191}192193void Wisp_State_FlyAway(void)194{195RSDK_THIS(Wisp);196197self->position.x += self->velocity.x;198self->position.y += self->velocity.y;199RSDK.ProcessAnimation(&self->wingAnimator);200201Wisp_HandlePlayerInteractions();202Wisp_CheckOffScreen();203}204205#if GAME_INCLUDE_EDITOR206void Wisp_EditorDraw(void) { Wisp_Draw(); }207208void Wisp_EditorLoad(void)209{210Wisp->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/Wisp.bin", SCOPE_STAGE);211212// despite being editable, this variable is set to FLIP_NONE on create, thereby making the editable var's value unused213RSDK_ACTIVE_VAR(Wisp, direction);214RSDK_ENUM_VAR("(Unused)", FLIP_NONE);215// RSDK_ENUM_VAR("No Flip", FLIP_NONE);216// RSDK_ENUM_VAR("Flip X", FLIP_X);217}218#endif219220void Wisp_Serialize(void) { RSDK_EDITABLE_VAR(Wisp, VAR_UINT8, direction); }221222223