Path: blob/master/SonicMania/Objects/LRZ/DashLift.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: DashLift Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectDashLift *DashLift;1011void DashLift_Update(void) { Platform_Update(); }1213void DashLift_LateUpdate(void) {}1415void DashLift_StaticUpdate(void) {}1617void DashLift_Draw(void)18{19RSDK_THIS(DashLift);2021RSDK.DrawSprite(&self->animator, &self->drawPos, false);22}2324void DashLift_Create(void *data)25{26RSDK_THIS(DashLift);2728self->collision = PLATFORM_C_SOLID;29Platform_Create(NULL);3031if (!SceneInfo->inEditor) {32self->drawGroup = Zone->playerDrawGroup[1];33RSDK.SetSpriteAnimation(Platform->aniFrames, 2, &self->animator, true, 4);3435self->drawPos.y += self->startOff << 15;36self->updateRange.y = self->length << 15;3738self->amplitude.x = self->position.y - (self->length << 15);39self->amplitude.y = self->position.y + (self->length << 15);4041self->updateRange.x = 0x800000;42self->state = DashLift_State_Init;43}44}4546void DashLift_StageLoad(void) { DashLift->sfxPulley = RSDK.GetSfx("Stage/Pulley.wav"); }4748void DashLift_CheckOffScreen(void)49{50RSDK_THIS(DashLift);5152if (!RSDK.CheckPosOnScreen(&self->drawPos, &self->updateRange) && !RSDK.CheckPosOnScreen(&self->centerPos, &self->updateRange)) {53self->drawPos = self->centerPos;54self->position = self->centerPos;55self->activePlayers = 0;56self->active = ACTIVE_BOUNDS;57DashLift_Create(NULL);58}59}6061void DashLift_State_Init(void)62{63RSDK_THIS(DashLift);6465self->active = ACTIVE_NORMAL;66self->state = DashLift_State_HandleDash;67}6869void DashLift_State_HandleDash(void)70{71RSDK_THIS(DashLift);7273int32 totalSpeed = 0;74foreach_active(Player, player)75{76int32 playerID = RSDK.GetEntitySlot(player);7778if (!((1 << playerID) & self->stoodPlayers)) {79if (((1 << playerID) & self->activePlayers)) {80player->position.x = self->position.x;81self->activePlayers &= ~(1 << playerID);82if (player->animator.animationID == ANI_JUMP)83player->velocity.x = 0;84}85}86else {87int32 anim = player->animator.animationID;88if (anim == ANI_SPINDASH || (anim == ANI_JUMP && ((1 << playerID) & self->activePlayers))) {89self->activePlayers |= (1 << playerID);9091foreach_active(Dust, dust)92{93if (dust->parent == (Entity *)player)94destroyEntity(dust);95}9697player->velocity.x -= player->velocity.x >> 5;98player->position.x = self->position.x;99if (player->direction == FLIP_X) {100if ((player->sidekick && totalSpeed < 0) || self->drawPos.y >= self->amplitude.y)101continue;102103int32 speed = 0;104if (player->state == Player_State_Spindash) {105if (player->superState == SUPERSTATE_SUPER)106speed = ((player->abilityTimer >> 1) & 0x7FFF8000) + 0xB0000;107else108speed = ((player->abilityTimer >> 1) & 0x7FFF8000) + 0x80000;109}110else {111speed = -player->groundVel;112}113114speed -= 0x40000;115if (speed < 0) {116speed = 0;117player->groundVel = 0;118player->velocity.x = 0;119}120121self->drawPos.y += speed >> 2;122totalSpeed += speed >> 2;123self->animator.timer += abs((speed >> 2) >> 16);124125if (self->animator.timer >= 4) {126self->animator.timer = 0;127if (++self->animator.frameID > 4)128self->animator.frameID = 0;129}130131if (!(Zone->timer & 0xF))132RSDK.PlaySfx(DashLift->sfxPulley, false, 255);133}134else {135if ((player->sidekick && totalSpeed > 0) || self->drawPos.y <= self->amplitude.x)136continue;137138int32 speed = 0;139if (player->state == Player_State_Spindash) {140if (player->superState == SUPERSTATE_SUPER)141speed = -((player->abilityTimer >> 1) & 0x7FFF8000) - 0xB0000;142else143speed = -((player->abilityTimer >> 1) & 0x7FFF8000) - 0x80000;144}145else {146speed = -player->groundVel;147}148149speed += 0x40000;150if (speed > 0) {151speed = 0;152player->groundVel = 0;153player->velocity.x = 0;154}155156self->drawPos.y += speed >> 2;157totalSpeed += speed >> 2;158self->animator.timer -= abs((speed >> 2) >> 16);159160if (self->animator.timer <= 0) {161self->animator.timer = 3;162if (--self->animator.frameID < 0)163self->animator.frameID = 4;164}165166if (!(Zone->timer & 0xF))167RSDK.PlaySfx(DashLift->sfxPulley, false, 255);168}169}170else {171self->activePlayers &= ~(1 << playerID);172}173}174}175176DashLift_CheckOffScreen();177}178179#if GAME_INCLUDE_EDITOR180void DashLift_EditorDraw(void)181{182RSDK_THIS(DashLift);183184self->drawPos = self->position;185RSDK.SetSpriteAnimation(Platform->aniFrames, 2, &self->animator, true, 4);186187DashLift_Draw();188189if (showGizmos()) {190RSDK_DRAWING_OVERLAY(true);191self->drawPos.y += self->startOff << 15;192self->updateRange.y = self->length << 15;193194self->amplitude.x = self->position.y - (self->length << 15);195self->amplitude.y = self->position.y + (self->length << 15);196197self->inkEffect = INK_BLEND;198199// Offset Preview200DashLift_Draw();201202self->drawPos = self->position;203self->drawPos.y += self->length << 15;204205// Length Preview206DashLift_Draw();207208DrawHelpers_DrawArrow(self->position.x, self->position.y, self->drawPos.x, self->drawPos.y, 0x00FF00, INK_NONE, 0xFF);209210self->inkEffect = INK_NONE;211212for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {213Entity *child = RSDK_GET_ENTITY_GEN(s + i);214if (!child)215continue;216217DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);218}219220RSDK_DRAWING_OVERLAY(false);221}222}223224void DashLift_EditorLoad(void) {}225#endif226227void DashLift_Serialize(void)228{229RSDK_EDITABLE_VAR(DashLift, VAR_ENUM, length);230RSDK_EDITABLE_VAR(DashLift, VAR_ENUM, childCount);231RSDK_EDITABLE_VAR(DashLift, VAR_ENUM, startOff);232}233234235