Path: blob/master/SonicMania/Objects/PGZ/PSZLauncher.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: PSZLauncher Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectPSZLauncher *PSZLauncher;1011void PSZLauncher_Update(void)12{13RSDK_THIS(PSZLauncher);1415StateMachine_Run(self->state);16}1718void PSZLauncher_LateUpdate(void) {}1920void PSZLauncher_StaticUpdate(void) {}2122void PSZLauncher_Draw(void)23{24RSDK_THIS(PSZLauncher);2526RSDK.DrawSprite(&self->animator, NULL, false);27}2829void PSZLauncher_Create(void *data)30{31RSDK_THIS(PSZLauncher);3233self->visible = true;34self->drawGroup = Zone->objectDrawGroup[1] - 1;35self->drawFX = FX_FLIP;3637if (SceneInfo->inEditor && !self->power)38self->power = 10;3940self->active = ACTIVE_BOUNDS;41self->updateRange.x = 0x800000;42self->updateRange.y = 0x800000;43self->state = PSZLauncher_State_Init;44}4546void PSZLauncher_StageLoad(void)47{48PSZLauncher->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PSZLauncher.bin", SCOPE_STAGE);4950PSZLauncher->hitboxLaunch.left = -32;51PSZLauncher->hitboxLaunch.top = 0;52PSZLauncher->hitboxLaunch.right = 32;53PSZLauncher->hitboxLaunch.bottom = 1;5455DEBUGMODE_ADD_OBJ(PSZLauncher);56}5758void PSZLauncher_DebugSpawn(void)59{60RSDK_THIS(PSZLauncher);6162EntityPSZLauncher *launcher = CREATE_ENTITY(PSZLauncher, NULL, self->position.x, self->position.y);63launcher->direction = self->direction;64}6566void PSZLauncher_DebugDraw(void)67{68RSDK.SetSpriteAnimation(PSZLauncher->aniFrames, 0, &DebugMode->animator, true, 0);69RSDK.DrawSprite(&DebugMode->animator, NULL, false);70}7172void PSZLauncher_State_Init(void)73{74RSDK_THIS(PSZLauncher);7576RSDK.SetSpriteAnimation(PSZLauncher->aniFrames, 0, &self->animator, true, 0);77self->stoodPlayers = 0;78self->activePlayers = 0;7980self->state = PSZLauncher_State_Active;8182PSZLauncher_HandlePlayerCollisions();83PSZLauncher_HandlePlayerInteractions();84}8586void PSZLauncher_HandlePlayerCollisions(void)87{88RSDK_THIS(PSZLauncher);8990Hitbox hitboxStand;91hitboxStand.left = -32;92hitboxStand.right = 0;93hitboxStand.bottom = 0;94foreach_active(Player, player)95{96int32 playerID = RSDK.GetEntitySlot(player);9798int32 standPos = 31 - CLAMP(abs(player->position.x - self->position.x) >> 16, 0, 31);99if ((self->direction == FLIP_NONE && player->position.x > self->position.x)100|| (self->direction == FLIP_X && player->position.x < self->position.x))101standPos = 31;102103hitboxStand.top = -PSZLauncher->heightTable[standPos];104if ((1 << playerID) & self->stoodPlayers)105player->position.y += 0x10000;106107if (Player_CheckCollisionPlatform(player, self, &hitboxStand)) {108self->stoodPlayers |= 1 << playerID;109player->position.y &= 0xFFFF0000;110}111else {112self->stoodPlayers &= ~(1 << playerID);113}114}115}116117void PSZLauncher_HandlePlayerInteractions(void)118{119RSDK_THIS(PSZLauncher);120121foreach_active(Player, player)122{123int32 playerID = RSDK.GetEntitySlot(player);124125if (Player_CheckCollisionTouch(player, self, &PSZLauncher->hitboxLaunch)) {126if (!((1 << playerID) & self->activePlayers) && !((1 << playerID) & self->stoodPlayers) && player->velocity.y <= 0) {127self->activePlayers |= 1 << playerID;128player->velocity.y = -0x10000 * self->power;129player->velocity.x = 0;130131if (self->direction)132player->position.x = self->position.x - 0x100000;133else134player->position.x = self->position.x + 0x100000;135136player->applyJumpCap = false;137player->jumpAbilityState = 0;138player->collisionMode = 0;139player->groundVel = 0;140player->state = Player_State_Air;141player->onGround = false;142143RSDK.PlaySfx(Player->sfxRelease, false, 255);144RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);145}146}147else {148self->activePlayers &= ~(1 << playerID);149}150}151}152153void PSZLauncher_State_Active(void)154{155PSZLauncher_HandlePlayerCollisions();156PSZLauncher_HandlePlayerInteractions();157}158159#if GAME_INCLUDE_EDITOR160void PSZLauncher_EditorDraw(void)161{162RSDK_THIS(PSZLauncher);163RSDK.SetSpriteAnimation(PSZLauncher->aniFrames, 0, &self->animator, true, 0);164165PSZLauncher_Draw();166}167168void PSZLauncher_EditorLoad(void)169{170PSZLauncher->aniFrames = RSDK.LoadSpriteAnimation("PSZ1/PSZLauncher.bin", SCOPE_STAGE);171172RSDK_ACTIVE_VAR(PSZLauncher, direction);173RSDK_ENUM_VAR("Left", FLIP_NONE);174RSDK_ENUM_VAR("Right", FLIP_X);175}176#endif177178void PSZLauncher_Serialize(void)179{180RSDK_EDITABLE_VAR(PSZLauncher, VAR_UINT8, direction);181RSDK_EDITABLE_VAR(PSZLauncher, VAR_UINT8, power);182}183184185