Path: blob/master/SonicMania/Objects/SSZ/MSBomb.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: MSBomb Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectMSBomb *MSBomb;1112void MSBomb_Update(void)13{14RSDK_THIS(MSBomb);1516RSDK.ProcessAnimation(&self->animator);1718StateMachine_Run(self->state);19}2021void MSBomb_LateUpdate(void) {}2223void MSBomb_StaticUpdate(void) {}2425void MSBomb_Draw(void)26{27RSDK_THIS(MSBomb);2829RSDK.DrawSprite(&self->animator, NULL, false);30}3132void MSBomb_Create(void *data)33{34RSDK_THIS(MSBomb);3536self->active = ACTIVE_NORMAL;37self->visible = true;38self->drawGroup = Zone->objectDrawGroup[0];3940if (data) {41RSDK.SetSpriteAnimation(MSBomb->aniFrames, 1, &self->animator, true, 0);4243self->hitbox.left = -4;44self->hitbox.top = -4;45self->hitbox.right = 4;46self->hitbox.bottom = 4;4748self->state = MSBomb_State_Projectile;49}50else {51RSDK.SetSpriteAnimation(MSBomb->aniFrames, 0, &self->animator, true, 0);5253self->hitbox.left = -8;54self->hitbox.top = -8;55self->hitbox.right = 8;56self->hitbox.bottom = 8;5758self->drawFX = FX_SCALE;59self->scale.x = 0xC0;60self->scale.y = 0xC0;61self->state = MSBomb_State_EnterBomb;62}63}6465void MSBomb_StageLoad(void)66{67MSBomb->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSBomb.bin", SCOPE_STAGE);6869MSBomb->sfxExplosion = RSDK.GetSfx("Stage/Explosion4.wav");70}7172void MSBomb_State_EnterBomb(void)73{74RSDK_THIS(MSBomb);7576self->position.x += self->velocity.x;77self->position.y += self->velocity.y;78self->velocity.y += 0x3800;7980if (self->scale.x >= 0x200) {81self->drawFX = FX_NONE;82self->state = MSBomb_State_Bouncing;83}84else {85self->scale.x += 0x40;86self->scale.y = self->scale.x;87}88}8990// Not sure why this is part of MSBomb but alright91void MSBomb_State_SilverSonicExplode(void)92{93RSDK_THIS(SilverSonic);9495self->position.x += self->velocity.x;96self->position.y += self->velocity.y;97self->velocity.y += 0x3800;9899if (self->scale.x >= 0x200) {100int32 yVel = 0x18000;101int32 xVel = 0x30000;102103foreach_active(MetalSonic, metal)104{105xVel = MAX(abs(self->position.x - metal->position.x) >> 6, 0x20000);106yVel = abs(self->position.y - metal->position.y) >> 6;107}108109EntityMSBomb *bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);110bomb->velocity.x = -xVel;111bomb->velocity.y = -yVel;112113bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);114bomb->velocity.x = xVel;115bomb->velocity.y = -yVel;116117bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);118yVel = -(yVel >> 1);119bomb->velocity.x = -xVel;120bomb->velocity.y = yVel;121122bomb = CREATE_ENTITY(MSBomb, INT_TO_VOID(true), self->position.x, self->position.y);123bomb->velocity.x = xVel;124bomb->velocity.y = yVel;125126RSDK.PlaySfx(MSBomb->sfxExplosion, false, 0xFF);127RSDK.ResetEntity(self, Explosion->classID, INT_TO_VOID(EXPLOSION_BOSS));128self->position.x = bomb->position.x;129self->position.y = bomb->position.y;130}131else {132self->scale.x += 0x40;133self->scale.y = self->scale.x;134}135}136137void MSBomb_State_Bouncing(void)138{139RSDK_THIS(MSBomb);140141self->position.x += self->velocity.x;142self->position.y += self->velocity.y;143self->velocity.y += 0x3800;144145if (RSDK.ObjectTileCollision(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, 0xA0000, true)) {146// Bounce147self->velocity.y = -0x40000;148149if (self->timer > 0) {150if (!--self->timer) {151int32 storeX = self->position.x;152int32 storeY = self->position.y;153RSDK.ResetEntity(self, Explosion->classID, INT_TO_VOID(EXPLOSION_BOSS));154self->position.x = storeX;155self->position.y = storeY;156RSDK.PlaySfx(MSBomb->sfxExplosion, false, 255);157}158}159}160else if (!self->timer && !RSDK.CheckOnScreen(self, NULL)) {161destroyEntity(self);162}163164if (self->classID == MSBomb->classID) {165foreach_active(Player, player)166{167if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {168if (Player_Hurt(player, self))169player->velocity.x = abs(player->velocity.x) + Zone->autoScrollSpeed;170171CREATE_ENTITY(Explosion, INT_TO_VOID(EXPLOSION_ENEMY), self->position.x, self->position.y);172RSDK.PlaySfx(MSBomb->sfxExplosion, false, 255);173destroyEntity(self);174}175}176}177}178179void MSBomb_State_Projectile(void)180{181RSDK_THIS(MSBomb);182183self->position.x += self->velocity.x;184self->position.y += self->velocity.y;185186foreach_active(Player, player)187{188if (Player_CheckCollisionTouch(player, self, &self->hitbox)) {189Player_Hurt(player, self);190}191}192193foreach_active(MetalSonic, metal)194{195if (RSDK.CheckObjectCollisionTouchBox(metal, metal->outerBox, self, &self->hitbox)) {196MetalSonic->invincibilityTimerPanel = 16;197198if (--metal->health <= 0) {199metal->timer = 0;200metal->state = MetalSonic_State_PanelExplosion;201}202203RSDK.PlaySfx(MetalSonic->sfxHit, false, 255);204destroyEntity(self);205foreach_break;206}207}208209if (!RSDK.CheckOnScreen(self, NULL))210destroyEntity(self);211}212213#if GAME_INCLUDE_EDITOR214void MSBomb_EditorDraw(void)215{216RSDK_THIS(MSBomb);217RSDK.SetSpriteAnimation(MSBomb->aniFrames, 0, &self->animator, true, 0);218219MSBomb_Draw();220}221222void MSBomb_EditorLoad(void) { MSBomb->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSBomb.bin", SCOPE_STAGE); }223#endif224225void MSBomb_Serialize(void) {}226#endif227228229