Path: blob/master/SonicMania/Objects/Unused/TargetBumper.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: TargetBumper Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectTargetBumper *TargetBumper = NULL;1011void TargetBumper_Update(void)12{13RSDK_THIS(TargetBumper);14StateMachine_Run(self->state);15}1617void TargetBumper_LateUpdate(void) {}1819void TargetBumper_StaticUpdate(void) {}2021void TargetBumper_Draw(void)22{23RSDK_THIS(TargetBumper);24RSDK.DrawSprite(&self->animator, NULL, false);25}2627void TargetBumper_Create(void *data)28{29RSDK_THIS(TargetBumper);30self->visible = true;31self->drawFX |= FX_FLIP;32self->drawGroup = Zone->objectDrawGroup[0];33self->startPos = self->position;34self->active = ACTIVE_BOUNDS;35self->updateRange.x = 0x400000;36self->updateRange.y = 0x400000;37RSDK.SetSpriteAnimation(TargetBumper->aniFrames, self->type, &self->animator, true, 0);38self->animator.frameID = self->hitCount;39self->state = TargetBumper_State_Idle;40}4142void TargetBumper_StageLoad(void)43{44TargetBumper->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/TargetBumper.bin", SCOPE_STAGE);4546DEBUGMODE_ADD_OBJ(TargetBumper);47}4849void TargetBumper_DebugSpawn(void)50{51RSDK_THIS(TargetBumper);52CREATE_ENTITY(TargetBumper, NULL, self->position.x, self->position.y);53}5455void TargetBumper_DebugDraw(void)56{57RSDK.SetSpriteAnimation(TargetBumper->aniFrames, 0, &DebugMode->animator, true, 0);58RSDK.DrawSprite(&DebugMode->animator, NULL, false);59}6061void TargetBumper_CheckPlayerCollisions(void)62{63RSDK_THIS(TargetBumper);6465Hitbox hitboxBumper;66switch (self->type) {67case TARGETBUMP_HORIZONTAL:68hitboxBumper.left = -14;69hitboxBumper.top = -4;70hitboxBumper.right = 14;71hitboxBumper.bottom = 4;72break;7374case TARGETBUMP_VERTICAL:75hitboxBumper.left = -4;76hitboxBumper.top = -14;77hitboxBumper.right = 4;78hitboxBumper.bottom = 14;79break;8081case TARGETBUMP_DIAGONAL:82hitboxBumper.left = -8;83hitboxBumper.top = -8;84hitboxBumper.right = 8;85hitboxBumper.bottom = 8;86break;87}8889foreach_active(Player, player)90{91if (Player_CheckCollisionTouch(player, self, &hitboxBumper) && player->animator.animationID != ANI_HURT) {92self->curPos = self->startPos;93self->state = TargetBumper_State_Hit;94self->active = ACTIVE_NORMAL;9596switch (self->type) {97case TARGETBUMP_HORIZONTAL:98if (player->position.y <= self->position.y) {99player->velocity.y = -0x70000;100self->curPos.y += 0x20000;101}102else {103player->velocity.y = 0x70000;104self->curPos.y -= 0x20000;105}106break;107108case TARGETBUMP_VERTICAL:109if (player->position.x <= self->position.x) {110player->velocity.x = -0x70000;111self->curPos.x += 0x20000;112}113else {114player->velocity.x = 0x70000;115self->curPos.x -= 0x20000;116}117break;118119case TARGETBUMP_DIAGONAL: {120int32 angle = 96;121if (self->direction)122angle = 32;123124int32 ang2 = 0;125uint8 atan = RSDK.ATan2(player->velocity.x, player->velocity.y);126int32 ang = atan - angle;127if (atan - angle >= 0)128ang2 = ang;129else130ang2 = -ang;131132if (ang2 < 0x40) {133if (ang2 < 0x38) {134angle -= ang;135angle &= 0xFF;136}137138if ((self->direction & FLIP_X))139self->curPos.x += 0x20000;140else141self->curPos.x -= 0x20000;142143self->curPos.y += 0x20000;144}145else {146angle += 0x80;147if ((0x80 - ang2) < 0x38) {148angle -= ang;149angle &= 0xFF;150}151152if ((self->direction & FLIP_X))153self->curPos.x -= 0x20000;154else155self->curPos.x += 0x20000;156157self->curPos.y -= 0x20000;158}159player->velocity.x = -0x700 * RSDK.Cos256(angle);160player->velocity.y = -0x700 * RSDK.Sin256(angle);161break;162}163}164165if (player->state == Player_State_FlyCarried)166RSDK_GET_ENTITY(SLOT_PLAYER2, Player)->flyCarryTimer = 30;167168int32 anim = player->animator.animationID;169if (anim != ANI_FLY && anim != ANI_FLY_LIFT_TIRED && player->state != Player_State_TailsFlight) {170player->state = Player_State_Air;171if (anim != ANI_JUMP && anim != ANI_JOG && anim != ANI_RUN && anim != ANI_DASH)172player->animator.animationID = ANI_WALK;173}174175if (player->animator.animationID != ANI_FLY)176player->groundVel = player->velocity.x;177178player->onGround = false;179player->tileCollisions = TILECOLLISION_DOWN;180if (self->hitCount < 3) {181self->hitTimer = 0;182183EntityScoreBonus *bonus = CREATE_ENTITY(ScoreBonus, NULL, self->position.x, self->position.y);184bonus->animator.frameID = 16;185Player_GiveScore(player, 10);186if (++self->hitCount < 3)187self->animator.frameID = self->hitCount;188}189}190}191}192193void TargetBumper_State_Idle(void) { TargetBumper_CheckPlayerCollisions(); }194195void TargetBumper_State_Hit(void)196{197RSDK_THIS(TargetBumper);198TargetBumper_CheckPlayerCollisions();199200if ((self->hitTimer & 4)) {201self->position.x = self->startPos.x;202self->position.y = self->startPos.y;203}204else {205self->position.x = self->curPos.x;206self->position.y = self->curPos.y;207}208209if (++self->hitTimer == 12) {210if (self->hitCount < 3) {211self->position.x = self->startPos.x;212self->position.y = self->startPos.y;213self->hitTimer = 0;214self->state = TargetBumper_State_Idle;215}216else {217destroyEntity(self);218}219}220}221222#if GAME_INCLUDE_EDITOR223void TargetBumper_EditorDraw(void)224{225RSDK_THIS(TargetBumper);226RSDK.SetSpriteAnimation(TargetBumper->aniFrames, self->type, &self->animator, true, 0);227self->animator.frameID = self->hitCount;228229RSDK.DrawSprite(&self->animator, NULL, false);230}231232void TargetBumper_EditorLoad(void)233{234TargetBumper->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/TargetBumper.bin", SCOPE_STAGE);235236RSDK_ACTIVE_VAR(TargetBumper, type);237RSDK_ENUM_VAR("Horizontal", TARGETBUMP_HORIZONTAL);238RSDK_ENUM_VAR("Vertical", TARGETBUMP_VERTICAL);239RSDK_ENUM_VAR("Diagonal", TARGETBUMP_DIAGONAL);240241RSDK_ACTIVE_VAR(TargetBumper, hitCount);242RSDK_ENUM_VAR("Three Hits", TARGETBUMP_THREE_HIT);243RSDK_ENUM_VAR("Two Hits", TARGETBUMP_TWO_HIT);244RSDK_ENUM_VAR("One Hit", TARGETBUMP_ONE_HIT);245246RSDK_ACTIVE_VAR(TargetBumper, direction);247RSDK_ENUM_VAR("No Flip", FLIP_NONE);248RSDK_ENUM_VAR("Flipped", FLIP_X);249}250#endif251252void TargetBumper_Serialize(void)253{254RSDK_EDITABLE_VAR(TargetBumper, VAR_ENUM, type);255RSDK_EDITABLE_VAR(TargetBumper, VAR_ENUM, hitCount);256RSDK_EDITABLE_VAR(TargetBumper, VAR_UINT8, direction);257}258259260