Path: blob/master/SonicMania/Objects/MSZ/GiantPistol.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: GiantPistol Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectGiantPistol *GiantPistol;1011void GiantPistol_Update(void)12{13RSDK_THIS(GiantPistol);1415StateMachine_Run(self->state);16}1718void GiantPistol_LateUpdate(void) {}1920void GiantPistol_StaticUpdate(void) {}2122void GiantPistol_Draw(void)23{24RSDK_THIS(GiantPistol);2526if (SceneInfo->currentDrawGroup == Zone->objectDrawGroup[0]) {27RSDK.DrawSprite(&self->pistolEntryAnimator, NULL, false);28RSDK.DrawSprite(&self->handLowAnimator, NULL, false);2930RSDK.AddDrawListRef(Zone->objectDrawGroup[1], SceneInfo->entitySlot);31}32else {33RSDK.DrawSprite(&self->triggerAnimator, NULL, false);34RSDK.DrawSprite(&self->hammerAnimator, NULL, false);35RSDK.DrawSprite(&self->chamberAnimator, NULL, false);36RSDK.DrawSprite(&self->pistolAnimator, NULL, false);37RSDK.DrawSprite(&self->handHighAnimator, NULL, false);38RSDK.DrawSprite(&self->triggerFingerAnimator, NULL, false);39}40}4142void GiantPistol_Create(void *data)43{44RSDK_THIS(GiantPistol);4546self->drawFX = FX_FLIP;47if (!SceneInfo->inEditor) {48RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 0, &self->pistolAnimator, true, 0);49RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 0, &self->pistolEntryAnimator, true, 1);50RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 5, &self->chamberAnimator, true, 0);51RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 6, &self->hammerAnimator, true, 0);52RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 4, &self->triggerAnimator, true, 0);53RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 1, &self->handLowAnimator, true, 0);54RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 2, &self->handHighAnimator, true, 0);55RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 3, &self->triggerFingerAnimator, true, 0);5657self->active = ACTIVE_BOUNDS;58self->updateRange.x = 0x800000;59self->updateRange.y = 0x800000;60self->visible = true;61self->drawGroup = Zone->objectDrawGroup[0];62self->startPos = self->position;6364self->pivot.x = self->position.x + (self->direction == FLIP_NONE ? 0x300000 : -0x300000);65self->pivot.y = self->position.y + 0x180000;66self->state = GiantPistol_State_AwaitPlayerEntry;67}68}6970void GiantPistol_StageLoad(void)71{72GiantPistol->aniFrames = RSDK.LoadSpriteAnimation("MSZ/Pistol.bin", SCOPE_STAGE);7374GiantPistol->hitboxFront.left = -80;75GiantPistol->hitboxFront.top = -58;76GiantPistol->hitboxFront.right = 4;77GiantPistol->hitboxFront.bottom = -16;7879GiantPistol->hitboxEntry.left = 4;80GiantPistol->hitboxEntry.top = -26;81GiantPistol->hitboxEntry.right = 44;82GiantPistol->hitboxEntry.bottom = -16;8384GiantPistol->hitboxRear.left = 44;85GiantPistol->hitboxRear.top = -58;86GiantPistol->hitboxRear.right = 64;87GiantPistol->hitboxRear.bottom = -16;8889GiantPistol->sfxClack = RSDK.GetSfx("Stage/Clack.wav");90GiantPistol->sfxCannonFire = RSDK.GetSfx("Stage/CannonFire.wav");91}9293void GiantPistol_State_AwaitPlayerEntry(void)94{95RSDK_THIS(GiantPistol);9697foreach_active(Player, player)98{99int32 side = Player_CheckCollisionBox(player, self, &GiantPistol->hitboxEntry);100101if (side == C_TOP && (!player->sidekick || self->state == GiantPistol_State_CloseChamber)) {102player->state = Player_State_Static;103player->nextAirState = StateMachine_None;104player->nextGroundState = StateMachine_None;105player->velocity.x = 0;106player->velocity.y = 0;107108RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);109self->activePlayers |= 1 << player->playerID;110self->state = GiantPistol_State_CloseChamber;111self->playerPos = self->direction == FLIP_NONE ? 0x180000 : -0x180000;112RSDK.PlaySfx(GiantPistol->sfxClack, false, 255);113}114115Player_CheckCollisionBox(player, self, &GiantPistol->hitboxFront);116Player_CheckCollisionBox(player, self, &GiantPistol->hitboxRear);117}118}119120void GiantPistol_State_CloseChamber(void)121{122RSDK_THIS(GiantPistol);123124RSDK.ProcessAnimation(&self->chamberAnimator);125126foreach_active(Player, player)127{128if (((1 << (player->playerID)) & self->activePlayers) > 0) {129player->position.x += (self->position.x + self->playerPos - player->position.x) >> 3;130player->position.y += (self->position.y - player->position.y - 0x200000) >> 3;131player->velocity.x = 0;132player->velocity.y = 0;133}134}135136if (self->chamberAnimator.frameID >= self->chamberAnimator.frameCount - 1) {137self->state = GiantPistol_State_SpinGun;138self->drawFX = FX_ROTATE | FX_FLIP;139self->handLowAnimator.frameID = 1;140self->handHighAnimator.frameID = 1;141self->velocity.y = -0x20000;142self->rotationVel = 6;143144foreach_active(Player, playerPtr)145{146if (((1 << (playerPtr->playerID)) & self->activePlayers) > 0) {147playerPtr->blinkTimer = 0;148playerPtr->visible = false;149if (playerPtr->camera)150playerPtr->camera->state = StateMachine_None;151}152}153}154}155156void GiantPistol_State_SpinGun(void)157{158RSDK_THIS(GiantPistol);159160self->position.y += self->velocity.y;161self->velocity.y += 0x1800;162163if (self->position.y >= self->startPos.y) {164self->position.y = self->startPos.y;165self->velocity.y = 0;166}167168if (self->rotationVel > -64)169self->rotationVel--;170171self->angle += self->direction ? -self->rotationVel : self->rotationVel;172173self->rotation = self->angle & 0x1FF;174int32 angle = 0x100 - (self->rotation >> 1);175176foreach_active(Player, player)177{178if (((1 << (player->playerID)) & self->activePlayers) > 0) {179player->position.x = self->position.x + self->playerPos;180player->position.y = self->position.y - 0x200000;181182Zone_RotateOnPivot(&player->position, &self->position, angle);183}184}185186if (self->angle <= -0x1FC || self->angle >= 0x1FC) {187self->angle = 0;188self->rotationVel = -(self->rotationVel >> 1);189self->rotation = 0;190RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 7, &self->handLowAnimator, true, 0);191RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 7, &self->handHighAnimator, true, 1);192self->state = GiantPistol_State_Aiming;193self->active = ACTIVE_NORMAL;194195foreach_active(Player, playerPtr)196{197if (((1 << (playerPtr->playerID)) & self->activePlayers) > 0) {198if (playerPtr->camera)199playerPtr->camera->state = Camera_State_FollowXY;200}201}202}203}204205void GiantPistol_State_Aiming(void)206{207RSDK_THIS(GiantPistol);208209if (self->timer) {210self->timer--;211}212else {213if (self->rotationVel > 4)214self->rotationVel--;215216self->angle += self->direction ? -self->rotationVel : self->rotationVel;217self->angle &= 0x1FF;218}219220self->position = self->startPos;221self->rotation = (-RSDK.Sin512(self->angle) >> 3) & 0x1FF;222int32 angle = 0x100 - (self->rotation >> 1);223Zone_RotateOnPivot(&self->position, &self->pivot, angle);224225self->position.x -= RSDK.Sin512(self->rotation) << 10;226self->position.y -= RSDK.Sin512(self->rotation) << 10;227228if (self->direction) {229if (self->playerPos <= 0x500000)230self->playerPos += 0x40000;231}232else {233if (self->playerPos > -0x500000)234self->playerPos -= 0x40000;235}236237uint8 jumpPressed = 0;238#if MANIA_USE_PLUS239if (GiantPistol->inCutscene) {240#else241if (!Zone->actID && !CHECK_CHARACTER_ID(ID_KNUCKLES, 1)) {242#endif243if (self->angle == 0x76 && self->activePlayers > 0) {244#if MANIA_USE_PLUS245if (SceneInfo->filter & FILTER_ENCORE) {246MSZSetup_ReloadBGParallax();247MSZSetup_ReloadBGParallax_Multiply(0x000);248}249else250#endif251MSZSetup_ReloadBGParallax_Multiply(0x400);252253jumpPressed = true;254}255}256else {257foreach_active(Player, player)258{259if (((1 << (player->playerID)) & self->activePlayers) > 0)260jumpPressed |= player->jumpPress;261}262}263264foreach_active(Player, player)265{266if (((1 << (player->playerID)) & self->activePlayers) > 0) {267player->position.x = self->position.x + self->playerPos;268player->position.y = self->position.y - 0x200000;269270Zone_RotateOnPivot(&player->position, &self->position, angle);271if (jumpPressed) {272player->state = Player_State_Air;273player->onGround = false;274player->jumpAbilityState = 0;275player->applyJumpCap = false;276player->jumpPress = false;277player->jumpHold = false;278279if (self->direction) {280player->velocity.x = 0xC00 * RSDK.Cos512(self->rotation);281player->velocity.y = 0xC00 * RSDK.Sin512(self->rotation);282}283else {284player->velocity.x = -0xC00 * RSDK.Cos512(self->rotation);285player->velocity.y = -0xC00 * RSDK.Sin512(self->rotation);286}287288#if MANIA_USE_PLUS289if (SceneInfo->filter == (FILTER_BOTH | FILTER_ENCORE) && GiantPistol->inCutscene) {290player->velocity.x += 0x18000;291player->state = GiantPistol_PlayerState_PistolAir;292player->nextGroundState = GiantPistol_PlayerState_PistolGround;293}294else if (!Zone->actID && !CHECK_CHARACTER_ID(ID_KNUCKLES, 1)) {295player->jumpAbilityState = 0;296}297#else298if (!Zone->actID && !CHECK_CHARACTER_ID(ID_KNUCKLES, 1))299player->jumpAbilityState = 0;300#endif301302self->activePlayers &= ~(1 << player->playerID);303self->timer = 16;304305player->velocity.x = CLAMP(player->velocity.x, -0x120000, 0x120000);306player->visible = true;307Camera_ShakeScreen(player->playerID, -8, -8);308RSDK.PlaySfx(GiantPistol->sfxCannonFire, false, 255);309}310}311}312313if (!self->activePlayers && !self->timer) {314if (self->rotation > 0x100)315self->rotation -= 0x200;316317self->state = GiantPistol_State_FiredPlayers;318}319}320321void GiantPistol_State_FiredPlayers(void)322{323RSDK_THIS(GiantPistol);324325if (self->rotation <= 0) {326self->rotation += 4;327328if (self->rotation > 0)329self->rotation = 0;330}331else {332self->rotation -= 4;333334if (self->rotation < 0)335self->rotation = 0;336}337338if (self->chamberAnimator.frameID > 0)339self->chamberAnimator.frameID--;340341self->position.x += (self->startPos.x - self->position.x) >> 3;342self->position.y += (self->startPos.y - self->position.y) >> 3;343344if (++self->timer == 60) {345self->position = self->startPos;346self->timer = 0;347self->angle = 0;348self->drawFX = FX_FLIP;349self->active = ACTIVE_BOUNDS;350self->state = GiantPistol_State_AwaitPlayerEntry;351352RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 5, &self->chamberAnimator, true, 0);353RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 1, &self->handLowAnimator, true, 0);354RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 2, &self->handHighAnimator, true, 0);355}356}357358#if MANIA_USE_PLUS359void GiantPistol_PlayerState_PistolAir(void)360{361RSDK_THIS(Player);362363self->left = false;364self->right = true;365self->up = false;366self->down = false;367self->jumpPress = false;368self->jumpHold = false;369370Player_State_Air();371372self->nextGroundState = GiantPistol_PlayerState_PistolGround;373}374375void GiantPistol_PlayerState_PistolGround(void)376{377RSDK_THIS(Player);378379self->left = true;380self->right = false;381self->up = false;382self->down = false;383self->jumpPress = false;384self->jumpHold = false;385386Player_State_Ground();387388self->state = GiantPistol_PlayerState_PistolGround;389self->nextGroundState = GiantPistol_PlayerState_PistolGround;390391if (self->groundVel <= 0) {392RSDK.SetSpriteAnimation(self->aniFrames, ANI_IDLE, &self->animator, true, 0);393self->left = false;394self->skidding = 0;395self->groundVel = 0;396self->velocity.x = 0;397self->direction = FLIP_NONE;398self->state = Player_State_Ground;399self->nextGroundState = Player_State_Ground;400}401}402#endif403404#if GAME_INCLUDE_EDITOR405void GiantPistol_EditorDraw(void)406{407RSDK_THIS(GiantPistol);408409RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 0, &self->pistolAnimator, true, 0);410RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 0, &self->pistolEntryAnimator, true, 1);411RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 5, &self->chamberAnimator, true, 0);412RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 6, &self->hammerAnimator, true, 0);413RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 4, &self->triggerAnimator, true, 0);414RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 1, &self->handLowAnimator, true, 0);415RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 2, &self->handHighAnimator, true, 0);416RSDK.SetSpriteAnimation(GiantPistol->aniFrames, 3, &self->triggerFingerAnimator, true, 0);417418RSDK.DrawSprite(&self->pistolEntryAnimator, NULL, false);419RSDK.DrawSprite(&self->handLowAnimator, NULL, false);420RSDK.DrawSprite(&self->triggerAnimator, NULL, false);421RSDK.DrawSprite(&self->hammerAnimator, NULL, false);422RSDK.DrawSprite(&self->chamberAnimator, NULL, false);423RSDK.DrawSprite(&self->pistolAnimator, NULL, false);424RSDK.DrawSprite(&self->handHighAnimator, NULL, false);425RSDK.DrawSprite(&self->triggerFingerAnimator, NULL, false);426}427428void GiantPistol_EditorLoad(void)429{430GiantPistol->aniFrames = RSDK.LoadSpriteAnimation("MSZ/Pistol.bin", SCOPE_STAGE);431432RSDK_ACTIVE_VAR(GiantPistol, direction);433RSDK_ENUM_VAR("Left", FLIP_NONE);434RSDK_ENUM_VAR("Right", FLIP_X);435}436#endif437438void GiantPistol_Serialize(void) { RSDK_EDITABLE_VAR(GiantPistol, VAR_UINT8, direction); }439440441