Path: blob/master/SonicMania/Objects/HCZ/Blastoid.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: Blastoid Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectBlastoid *Blastoid;1011void Blastoid_Update(void)12{13RSDK_THIS(Blastoid);1415StateMachine_Run(self->state);16}1718void Blastoid_LateUpdate(void) {}1920void Blastoid_StaticUpdate(void) {}2122void Blastoid_Draw(void)23{24RSDK_THIS(Blastoid);2526RSDK.DrawSprite(&self->animator, NULL, false);27}2829void Blastoid_Create(void *data)30{31RSDK_THIS(Blastoid);3233self->visible = true;34self->drawGroup = Zone->objectDrawGroup[0];35self->drawFX |= FX_FLIP;3637if (!SceneInfo->inEditor) {38if (data) {39self->active = ACTIVE_NORMAL;40self->updateRange.x = 0x200000;41self->updateRange.y = 0x200000;42RSDK.SetSpriteAnimation(Blastoid->aniFrames, 1, &self->animator, true, 0);43self->state = Blastoid_State_Projectile;44}45else {46self->active = ACTIVE_BOUNDS;47self->updateRange.x = 0x800000;48self->updateRange.y = 0x800000;49RSDK.SetSpriteAnimation(Blastoid->aniFrames, 0, &self->animator, true, 1);50self->state = Blastoid_State_Init;51}52}53}5455void Blastoid_StageLoad(void)56{57if (RSDK.CheckSceneFolder("HCZ"))58Blastoid->aniFrames = RSDK.LoadSpriteAnimation("HCZ/Blastoid.bin", SCOPE_STAGE);5960Blastoid->hitboxBody.left = -12;61Blastoid->hitboxBody.top = -9;62Blastoid->hitboxBody.right = 12;63Blastoid->hitboxBody.bottom = 12;6465Blastoid->hitboxProjectile.left = -3;66Blastoid->hitboxProjectile.top = -3;67Blastoid->hitboxProjectile.right = 3;68Blastoid->hitboxProjectile.bottom = 3;6970Blastoid->sfxShot = RSDK.GetSfx("Stage/Shot.wav");7172DEBUGMODE_ADD_OBJ(Blastoid);73}7475void Blastoid_DebugSpawn(void)76{77RSDK_THIS(Blastoid);7879CREATE_ENTITY(Blastoid, NULL, self->position.x, self->position.y);80}8182void Blastoid_DebugDraw(void)83{84RSDK.SetSpriteAnimation(Blastoid->aniFrames, 0, &DebugMode->animator, true, 0);85RSDK.DrawSprite(&DebugMode->animator, NULL, false);86}8788void Blastoid_CheckPlayerCollisions(void)89{90RSDK_THIS(Blastoid);9192foreach_active(Player, player)93{94if (Player_CheckBadnikTouch(player, self, &Blastoid->hitboxBody) && Player_CheckBadnikBreak(player, self, false)) {95EntityCollapsingPlatform *platform = RSDK_GET_ENTITY(SceneInfo->entitySlot - 1, CollapsingPlatform);96if (platform->classID == CollapsingPlatform->classID) {97platform->active = ACTIVE_NORMAL;98platform->collapseDelay = 30;99platform->stoodPos.x = self->position.x;100}101destroyEntity(self);102}103}104}105106void Blastoid_State_Init(void)107{108RSDK_THIS(Blastoid);109110self->active = ACTIVE_NORMAL;111112EntityCollapsingPlatform *platform = RSDK_GET_ENTITY(SceneInfo->entitySlot - 1, CollapsingPlatform);113if (platform->classID == CollapsingPlatform->classID)114platform->active = ACTIVE_NEVER;115116self->state = Blastoid_State_Body;117}118119void Blastoid_State_Body(void)120{121RSDK_THIS(Blastoid);122123RSDK.ProcessAnimation(&self->animator);124125switch (++self->timer) {126case 1:127case 16:128case 31: {129EntityBlastoid *projectile = CREATE_ENTITY(Blastoid, INT_TO_VOID(true), self->position.x, self->position.y);130131if (self->direction & FLIP_X) {132projectile->position.x += 0x100000;133projectile->velocity.x = 0x20000;134}135else {136projectile->position.x -= 0x100000;137projectile->velocity.x = -0x20000;138}139140if (self->direction & FLIP_Y) {141projectile->position.y += 0x60000;142projectile->velocity.y = 0x10000;143}144else {145projectile->position.y -= 0x60000;146projectile->velocity.y = -0x10000;147}148149RSDK.SetSpriteAnimation(Blastoid->aniFrames, 0, &self->animator, true, 0);150RSDK.PlaySfx(Blastoid->sfxShot, false, 0xFF);151break;152}153154case 121: self->timer = 0; break;155156default: break;157}158159Blastoid_CheckPlayerCollisions();160161if (!RSDK.CheckOnScreen(self, NULL)) {162self->timer = 0;163self->active = ACTIVE_BOUNDS;164}165}166167void Blastoid_State_Projectile(void)168{169RSDK_THIS(Blastoid);170171if (!RSDK.CheckOnScreen(self, NULL)) {172destroyEntity(self);173}174else {175self->position.x += self->velocity.x;176self->position.y += self->velocity.y;177178RSDK.ProcessAnimation(&self->animator);179180// Bug(?): setPos value is 4??????181// This implies these used to be "ObjectTileGrip" at some point, and were then changed to "ObjectTileCollision" without changing the last182// parameter Not that it *really* matters, since 4 will evaluate to true since it's non-zero183184if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, Blastoid->hitboxProjectile.top << 13, 4)185|| RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_LWALL, 0, Blastoid->hitboxProjectile.left << 13, 0, 4)186|| RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_ROOF, 0, 0, Blastoid->hitboxProjectile.bottom << 13, 4)187|| RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_RWALL, 0, Blastoid->hitboxProjectile.right << 13, 0, 4)) {188destroyEntity(self);189}190else {191foreach_active(Player, player)192{193int32 shield = player->shield;194// HCZBubble overrides active shields for collision195if (Water_GetPlayerBubble(player))196player->shield = SHIELD_BUBBLE;197198if (Player_CheckCollisionTouch(player, self, &Blastoid->hitboxProjectile))199Player_ProjectileHurt(player, self);200player->shield = shield;201}202}203}204}205206#if GAME_INCLUDE_EDITOR207void Blastoid_EditorDraw(void)208{209RSDK_THIS(Blastoid);210211RSDK.SetSpriteAnimation(Blastoid->aniFrames, 0, &self->animator, false, 0);212213Blastoid_Draw();214215if (showGizmos()) {216RSDK_DRAWING_OVERLAY(true);217218EntityCollapsingPlatform *platform = RSDK_GET_ENTITY(SceneInfo->entitySlot - 1, CollapsingPlatform);219if (CollapsingPlatform && platform->classID == CollapsingPlatform->classID)220DrawHelpers_DrawArrow(self->position.x, self->position.y, platform->position.x, platform->position.y, 0xFFFF00, INK_NONE, 0xFF);221222RSDK_DRAWING_OVERLAY(false);223}224}225226void Blastoid_EditorLoad(void)227{228Blastoid->aniFrames = RSDK.LoadSpriteAnimation("HCZ/Blastoid.bin", SCOPE_STAGE);229230RSDK_ACTIVE_VAR(Blastoid, direction);231RSDK_ENUM_VAR("Left", FLIP_NONE);232RSDK_ENUM_VAR("Right", FLIP_X);233RSDK_ENUM_VAR("Left (Flipped)", FLIP_Y);234RSDK_ENUM_VAR("Right (Flipped)", FLIP_XY);235}236#endif237238void Blastoid_Serialize(void) { RSDK_EDITABLE_VAR(Blastoid, VAR_UINT8, direction); }239240241