Path: blob/master/SonicMania/Objects/Unused/WallCrawl.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: WallCrawl Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectWallCrawl *WallCrawl = NULL;1011void WallCrawl_Update(void)12{13RSDK_THIS(WallCrawl);14StateMachine_Run(self->state);15}1617void WallCrawl_LateUpdate(void) {}1819void WallCrawl_StaticUpdate(void) {}2021void WallCrawl_Draw(void)22{23RSDK_THIS(WallCrawl);24RSDK.DrawSprite(&self->animator, NULL, false);25}2627void WallCrawl_Create(void *data)28{29RSDK_THIS(WallCrawl);3031self->drawFX |= FX_FLIP;32self->startPos.x = self->position.x;33self->startPos.y = self->position.y;34self->startDir = self->direction;35self->visible = true;36self->active = ACTIVE_BOUNDS;37self->updateRange.x = 0x800000;38self->updateRange.y = 0x800000;39self->playerPtr = NULL;40if (data) {41self->drawGroup = Zone->objectDrawGroup[0];42RSDK.SetSpriteAnimation(WallCrawl->aniFrames, 3, &self->animator, true, 0);43self->state = WallCrawl_State_Projectile;44}45else {46self->drawGroup = Zone->objectDrawGroup[0] + 1;47RSDK.SetSpriteAnimation(WallCrawl->aniFrames, 2, &self->animator, true, 0);48self->state = WallCrawl_State_Init;49}50}5152void WallCrawl_StageLoad(void)53{54WallCrawl->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/WallCrawl.bin", SCOPE_STAGE);5556WallCrawl->hitboxBadnik.left = -14;57WallCrawl->hitboxBadnik.top = -14;58WallCrawl->hitboxBadnik.right = 14;59WallCrawl->hitboxBadnik.bottom = 14;6061WallCrawl->hitboxRange.left = -128;62WallCrawl->hitboxRange.top = -128;63WallCrawl->hitboxRange.right = 128;64WallCrawl->hitboxRange.bottom = 128;6566WallCrawl->hitboxLaser.left = -132;67WallCrawl->hitboxLaser.top = 8;68WallCrawl->hitboxLaser.right = 132;69WallCrawl->hitboxLaser.bottom = -8;7071WallCrawl->hitboxProjectile.left = -24;72WallCrawl->hitboxProjectile.top = -1;73WallCrawl->hitboxProjectile.right = 24;74WallCrawl->hitboxProjectile.bottom = 9;7576DEBUGMODE_ADD_OBJ(WallCrawl);77}7879void WallCrawl_DebugSpawn(void)80{81RSDK_THIS(WallCrawl);82EntityWallCrawl *wallCrawl = CREATE_ENTITY(WallCrawl, NULL, self->position.x, self->position.y);83wallCrawl->direction = self->direction;84wallCrawl->startDir = self->direction;85}8687void WallCrawl_DebugDraw(void)88{89RSDK.SetSpriteAnimation(WallCrawl->aniFrames, 2, &DebugMode->animator, true, 0);90RSDK.DrawSprite(&DebugMode->animator, NULL, false);91}9293void WallCrawl_HandlePlayerInteractions(void)94{95RSDK_THIS(WallCrawl);96foreach_active(Player, player)97{98if (!self->timer) {99if (Player_CheckCollisionTouch(player, self, &WallCrawl->hitboxRange)) {100if (self->playerPtr) {101if (abs(player->position.x - self->position.x) < abs(self->playerPtr->position.x - self->position.x))102self->playerPtr = player;103}104else {105self->playerPtr = player;106}107}108}109if (Player_CheckBadnikTouch(player, self, &WallCrawl->hitboxBadnik))110Player_CheckBadnikBreak(player, self, true);111}112}113114void WallCrawl_CheckOffScreen(void)115{116RSDK_THIS(WallCrawl);117if (!RSDK.CheckOnScreen(self, NULL) && !RSDK.CheckPosOnScreen(&self->startPos, &self->updateRange)) {118self->position = self->startPos;119self->direction = self->startDir;120WallCrawl_Create(NULL);121}122}123124void WallCrawl_State_Init(void)125{126RSDK_THIS(WallCrawl);127128int32 offsetY = -0xC0000;129self->active = ACTIVE_NORMAL;130if (self->direction & FLIP_Y)131offsetY = 0xC0000;132133int32 offsetX = -0xD0000;134if (!(self->direction & FLIP_X))135offsetX = 0xC0000;136137RSDK.ObjectTileGrip(self, Zone->collisionLayers, (2 * ((self->direction & FLIP_X) != 0) + 1), 0, offsetX, offsetY, 8);138self->state = WallCrawl_State_Moving;139WallCrawl_State_Moving();140}141142void WallCrawl_State_Moving(void)143{144RSDK_THIS(WallCrawl);145146if (self->timer)147self->timer--;148149EntityPlayer *playerPtr = self->playerPtr;150if (playerPtr) {151if (Player_CheckCollisionTouch(playerPtr, self, &WallCrawl->hitboxRange)) {152if (!Player_CheckCollisionTouch(playerPtr, self, &WallCrawl->hitboxLaser)) {153self->animator.speed = 48;154if (playerPtr->position.y <= self->position.y) {155self->direction &= ~FX_ROTATE;156self->velocity.y = -0x10000;157}158else {159self->direction |= FX_ROTATE;160self->velocity.y = 0x10000;161}162}163else {164int32 offsetX = -0x180000;165self->state = WallCrawl_State_Idle;166if (!(self->direction & FLIP_X))167offsetX = 0x180000;168self->idleTimer = 30;169CREATE_ENTITY(WallCrawl, INT_TO_VOID(true), self->position.x + offsetX, self->position.y)->direction = self->direction;170self->timer = 180;171self->playerPtr = NULL;172}173}174else {175self->playerPtr = NULL;176}177}178else {179self->animator.speed = 24;180if (!(self->direction & FLIP_Y))181self->velocity.y = -0x8000;182else183self->velocity.y = 0x8000;184}185186self->position.y += self->velocity.y;187int32 offsetY = -0xC0000;188self->active = ACTIVE_NORMAL;189if (self->direction & FLIP_Y)190offsetY = 0xC0000;191192int32 offsetX = -0xD0000;193if (!(self->direction & FLIP_X))194offsetX = 0xC0000;195if (!RSDK.ObjectTileGrip(self, Zone->collisionLayers, (2 * ((self->direction & 1) != 0) + 1), 0, offsetX, offsetY, 0)) {196self->state = WallCrawl_State_Idle;197self->idleTimer = 30;198if (self->playerPtr) {199self->playerPtr = 0;200self->timer = 180;201}202}203RSDK.ProcessAnimation(&self->animator);204WallCrawl_HandlePlayerInteractions();205WallCrawl_CheckOffScreen();206}207208void WallCrawl_State_Idle(void)209{210RSDK_THIS(WallCrawl);211if (!--self->idleTimer) {212if (abs(self->velocity.y) == 0x8000)213self->direction ^= FLIP_Y;214self->state = WallCrawl_State_Moving;215WallCrawl_State_Moving();216}217else {218WallCrawl_HandlePlayerInteractions();219}220WallCrawl_CheckOffScreen();221}222223void WallCrawl_State_Projectile(void)224{225RSDK_THIS(WallCrawl);226227RSDK.ProcessAnimation(&self->animator);228if (self->direction & FLIP_X)229self->position.x += 0x40000;230else231self->position.x -= 0x40000;232233foreach_active(Player, player)234{235if (Player_CheckCollisionTouch(player, self, &WallCrawl->hitboxProjectile)) {236Player_Hurt(player, self);237}238}239}240241#if GAME_INCLUDE_EDITOR242void WallCrawl_EditorDraw(void)243{244RSDK_THIS(WallCrawl);245RSDK.SetSpriteAnimation(WallCrawl->aniFrames, 2, &self->animator, true, 0);246RSDK.DrawSprite(&self->animator, NULL, false);247}248249void WallCrawl_EditorLoad(void)250{251WallCrawl->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/WallCrawl.bin", SCOPE_STAGE);252253RSDK_ACTIVE_VAR(WallCrawl, direction);254RSDK_ENUM_VAR("No Flip", FLIP_NONE);255RSDK_ENUM_VAR("Flip X", FLIP_X);256RSDK_ENUM_VAR("Flip Y", FLIP_Y);257RSDK_ENUM_VAR("Flip XY", FLIP_XY);258}259#endif260261void WallCrawl_Serialize(void) { RSDK_EDITABLE_VAR(WallCrawl, VAR_UINT8, direction); }262263264