Path: blob/master/SonicMania/Objects/GHZ/BuzzBomber.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: BuzzBomber Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectBuzzBomber *BuzzBomber;1011void BuzzBomber_Update(void)12{13RSDK_THIS(BuzzBomber);14StateMachine_Run(self->state);15}1617void BuzzBomber_LateUpdate(void) {}1819void BuzzBomber_StaticUpdate(void) {}2021void BuzzBomber_Draw(void)22{23RSDK_THIS(BuzzBomber);2425if (self->inkEffect == INK_ADD) {26RSDK.DrawSprite(&self->animator, NULL, false);27}28else {29RSDK.DrawSprite(&self->animator, NULL, false);3031self->inkEffect = INK_ALPHA;32RSDK.DrawSprite(&self->wingAnimator, NULL, false);3334self->inkEffect = INK_NONE;35RSDK.DrawSprite(&self->thrustAnimator, NULL, false);36}37}3839void BuzzBomber_Create(void *data)40{41RSDK_THIS(BuzzBomber);42self->visible = true;43self->drawFX |= FX_FLIP;44self->drawGroup = Zone->objectDrawGroup[0];45self->startPos.x = self->position.x;46self->startPos.y = self->position.y;47self->startDir = self->direction;48self->timer = 128;49self->detectedPlayer = false;50self->projectile = NULL;5152if (!self->shotRange)53self->shotRange = 96;5455self->hitboxRange.right = self->shotRange;56self->hitboxRange.left = -self->shotRange;57self->hitboxRange.top = -256;58self->hitboxRange.bottom = 256;5960if (data) {61self->inkEffect = INK_ADD;62self->alpha = 0xC0;63self->active = ACTIVE_NORMAL;64self->updateRange.x = 0x200000;65self->updateRange.y = 0x200000;66RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 4, &self->animator, true, 0);67RSDK.SetSpriteAnimation(-1, 0, &self->wingAnimator, true, 0);68RSDK.SetSpriteAnimation(-1, 0, &self->thrustAnimator, true, 0);69self->state = BuzzBomber_State_ProjectileCharge;70}71else {72self->active = ACTIVE_BOUNDS;73self->updateRange.x = 0x800000;74self->updateRange.y = 0x800000;75RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 0, &self->animator, true, 0);76RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 2, &self->wingAnimator, true, 0);77RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 3, &self->thrustAnimator, true, 0);78self->state = BuzzBomber_State_Init;79self->alpha = 0xC0;80}81}8283void BuzzBomber_StageLoad(void)84{85if (RSDK.CheckSceneFolder("GHZ"))86BuzzBomber->aniFrames = RSDK.LoadSpriteAnimation("GHZ/BuzzBomber.bin", SCOPE_STAGE);87else if (RSDK.CheckSceneFolder("Blueprint"))88BuzzBomber->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/BuzzBomber.bin", SCOPE_STAGE);8990BuzzBomber->hitboxBadnik.left = -24;91BuzzBomber->hitboxBadnik.top = -12;92BuzzBomber->hitboxBadnik.right = 24;93BuzzBomber->hitboxBadnik.bottom = 12;9495BuzzBomber->hitboxProjectile.left = -6;96BuzzBomber->hitboxProjectile.top = -6;97BuzzBomber->hitboxProjectile.right = 6;98BuzzBomber->hitboxProjectile.bottom = 6;99100DEBUGMODE_ADD_OBJ(BuzzBomber);101}102103void BuzzBomber_DebugDraw(void)104{105RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 0, &DebugMode->animator, true, 0);106RSDK.DrawSprite(&DebugMode->animator, NULL, false);107}108109void BuzzBomber_DebugSpawn(void)110{111RSDK_THIS(DebugMode);112113EntityBuzzBomber *buzzBomber = CREATE_ENTITY(BuzzBomber, NULL, self->position.x, self->position.y);114115buzzBomber->direction = self->direction;116buzzBomber->startDir = self->direction;117}118119void BuzzBomber_CheckOffScreen(void)120{121RSDK_THIS(BuzzBomber);122123if (!RSDK.CheckOnScreen(self, NULL) && !RSDK.CheckPosOnScreen(&self->startPos, &self->updateRange)) {124self->position.x = self->startPos.x;125self->position.y = self->startPos.y;126self->direction = self->startDir;127BuzzBomber_Create(NULL);128}129}130131void BuzzBomber_CheckPlayerCollisions(void)132{133RSDK_THIS(BuzzBomber);134135foreach_active(Player, player)136{137if (Player_CheckBadnikTouch(player, self, &BuzzBomber->hitboxBadnik)) {138if (Player_CheckBadnikBreak(player, self, true)) {139if (self->projectile)140destroyEntity(self->projectile);141}142}143else if (self->state == BuzzBomber_State_Flying && !self->detectedPlayer) {144if (Player_CheckCollisionTouch(player, self, &self->hitboxRange)) {145self->detectedPlayer = true;146self->timer = 90;147RSDK.SetSpriteAnimation(-1, 0, &self->thrustAnimator, true, 0);148self->state = BuzzBomber_State_DetectedPlayer;149}150}151}152}153154void BuzzBomber_State_Init(void)155{156RSDK_THIS(BuzzBomber);157158self->active = ACTIVE_NORMAL;159if (!(self->direction & FLIP_X))160self->velocity.x = -0x40000;161else162self->velocity.x = 0x40000;163164self->state = BuzzBomber_State_Flying;165BuzzBomber_State_Flying();166}167168void BuzzBomber_State_Flying(void)169{170RSDK_THIS(BuzzBomber);171172self->position.x += self->velocity.x;173self->position.y += self->velocity.y;174175if (!--self->timer) {176self->direction ^= FLIP_X;177self->timer = 60;178self->velocity.x = -self->velocity.x;179self->detectedPlayer = false;180RSDK.SetSpriteAnimation(-1, 0, &self->thrustAnimator, true, 0);181self->state = BuzzBomber_State_Idle;182}183184RSDK.ProcessAnimation(&self->animator);185RSDK.ProcessAnimation(&self->wingAnimator);186RSDK.ProcessAnimation(&self->thrustAnimator);187BuzzBomber_CheckPlayerCollisions();188BuzzBomber_CheckOffScreen();189}190191void BuzzBomber_State_Idle(void)192{193RSDK_THIS(BuzzBomber);194195if (!--self->timer) {196self->timer = 128;197RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 3, &self->thrustAnimator, true, 0);198self->state = BuzzBomber_State_Flying;199}200201RSDK.ProcessAnimation(&self->animator);202RSDK.ProcessAnimation(&self->wingAnimator);203204BuzzBomber_CheckPlayerCollisions();205BuzzBomber_CheckOffScreen();206}207208void BuzzBomber_State_DetectedPlayer(void)209{210RSDK_THIS(BuzzBomber);211212RSDK.ProcessAnimation(&self->animator);213RSDK.ProcessAnimation(&self->wingAnimator);214BuzzBomber_CheckPlayerCollisions();215BuzzBomber_CheckOffScreen();216217self->timer--;218if (self->timer == 82) {219RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 1, &self->animator, true, 0);220}221else if (self->timer == 45) {222EntityBuzzBomber *projectile = CREATE_ENTITY(BuzzBomber, INT_TO_VOID(true), self->position.x, self->position.y);223if (self->direction) {224projectile->position.x += 0x180000;225projectile->velocity.x = 0x20000;226}227else {228projectile->position.x -= 0x180000;229projectile->velocity.x = -0x20000;230}231projectile->position.y += 0x1C0000;232projectile->velocity.y = 0x20000;233projectile->groundVel = 0;234projectile->projectile = (Entity *)self;235projectile->direction = self->direction;236projectile->active = ACTIVE_NORMAL;237238self->projectile = (Entity *)projectile;239}240else if (!self->timer) {241RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 0, &self->animator, true, 0);242self->timer = 128;243RSDK.SetSpriteAnimation(BuzzBomber->aniFrames, 3, &self->thrustAnimator, true, 0);244self->state = BuzzBomber_State_Flying;245}246}247248void BuzzBomber_State_ProjectileCharge(void)249{250RSDK_THIS(BuzzBomber);251RSDK.ProcessAnimation(&self->animator);252253if (self->animator.frameID == 6) {254self->state = BuzzBomber_State_ProjectileShot;255EntityBuzzBomber *shot = (EntityBuzzBomber *)self->projectile;256shot->projectile = NULL;257}258}259260void BuzzBomber_State_ProjectileShot(void)261{262RSDK_THIS(BuzzBomber);263264self->position.x += self->velocity.x;265self->position.y += self->velocity.y;266267if (RSDK.CheckOnScreen(self, NULL)) {268RSDK.ProcessAnimation(&self->animator);269270foreach_active(Player, player)271{272if (Player_CheckCollisionTouch(player, self, &BuzzBomber->hitboxProjectile))273Player_ProjectileHurt(player, self);274}275}276else {277destroyEntity(self);278}279}280281#if GAME_INCLUDE_EDITOR282void BuzzBomber_EditorDraw(void)283{284RSDK_THIS(BuzzBomber);285286BuzzBomber_Draw();287288if (showGizmos()) {289RSDK_DRAWING_OVERLAY(true);290291self->hitboxRange.right = self->shotRange;292self->hitboxRange.left = -self->shotRange;293self->hitboxRange.top = -256;294self->hitboxRange.bottom = 256;295296DrawHelpers_DrawHitboxOutline(self->position.x, self->position.y, &self->hitboxRange, FLIP_NONE, 0xFF0000);297298RSDK_DRAWING_OVERLAY(false);299}300}301302void BuzzBomber_EditorLoad(void)303{304if (RSDK.CheckSceneFolder("GHZ"))305BuzzBomber->aniFrames = RSDK.LoadSpriteAnimation("GHZ/BuzzBomber.bin", SCOPE_STAGE);306else if (RSDK.CheckSceneFolder("Blueprint"))307BuzzBomber->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/BuzzBomber.bin", SCOPE_STAGE);308309RSDK_ACTIVE_VAR(BuzzBomber, direction);310RSDK_ENUM_VAR("Left", FLIP_NONE);311RSDK_ENUM_VAR("Right", FLIP_X);312}313#endif314315void BuzzBomber_Serialize(void)316{317RSDK_EDITABLE_VAR(BuzzBomber, VAR_UINT8, direction);318RSDK_EDITABLE_VAR(BuzzBomber, VAR_UINT8, shotRange);319}320321322