Path: blob/master/SonicMania/Objects/Unused/SpearBlock.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: SpearBlock Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectSpearBlock *SpearBlock = NULL;1011void SpearBlock_Update(void)12{13RSDK_THIS(SpearBlock);14StateMachine_Run(self->state);15SpearBlock_CheckPlayerCollisions();1617if (!RSDK.CheckOnScreen(self, &self->updateRange)) {18self->state = SpearBlock_State_SetupSpears;19SpearBlock_Create(NULL);20}21}2223void SpearBlock_LateUpdate(void) {}2425void SpearBlock_StaticUpdate(void) {}2627void SpearBlock_Draw(void)28{29RSDK_THIS(SpearBlock);30RSDK.DrawSprite(&self->animator, &self->spearPos, false);31RSDK.DrawSprite(&SpearBlock->animator, NULL, false);32}3334void SpearBlock_Create(void *data)35{36RSDK_THIS(SpearBlock);37self->visible = true;38self->drawGroup = Zone->objectDrawGroup[0];39self->spearPos.x = self->position.x;40self->spearPos.y = self->position.y;41self->active = ACTIVE_BOUNDS;42self->updateRange.x = 0x400000;43self->updateRange.y = 0x400000;44RSDK.SetSpriteAnimation(SpearBlock->aniFrames, 1, &self->animator, true, 0);45RSDK.SetSpriteAnimation(SpearBlock->aniFrames, 0, &SpearBlock->animator, true, 0);46self->state = SpearBlock_State_SetupSpears;47}4849void SpearBlock_StageLoad(void)50{51SpearBlock->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/SpearBlock.bin", SCOPE_STAGE);5253SpearBlock->blockHitbox.left = -16;54SpearBlock->blockHitbox.top = -16;55SpearBlock->blockHitbox.right = 16;56SpearBlock->blockHitbox.bottom = 16;5758SpearBlock->spearHitboxes[0].left = -4;59SpearBlock->spearHitboxes[0].top = -16;60SpearBlock->spearHitboxes[0].right = 4;61SpearBlock->spearHitboxes[0].bottom = 16;6263SpearBlock->spearHitboxes[1].left = -16;64SpearBlock->spearHitboxes[1].top = -4;65SpearBlock->spearHitboxes[1].right = 16;66SpearBlock->spearHitboxes[1].bottom = 4;6768SpearBlock->spearHitboxes[2].left = -4;69SpearBlock->spearHitboxes[2].top = -16;70SpearBlock->spearHitboxes[2].right = 4;71SpearBlock->spearHitboxes[2].bottom = 16;7273SpearBlock->spearHitboxes[3].left = -16;74SpearBlock->spearHitboxes[3].top = -4;75SpearBlock->spearHitboxes[3].right = 16;76SpearBlock->spearHitboxes[3].bottom = 4;7778DEBUGMODE_ADD_OBJ(SpearBlock);79}8081void SpearBlock_DebugDraw(void)82{83RSDK.SetSpriteAnimation(SpearBlock->aniFrames, 0, &DebugMode->animator, true, 0);84RSDK.DrawSprite(&DebugMode->animator, NULL, false);85}86void SpearBlock_DebugSpawn(void)87{88RSDK_THIS(DebugMode);8990CREATE_ENTITY(SpearBlock, NULL, self->position.x, self->position.y);91}9293void SpearBlock_CheckPlayerCollisions(void)94{95RSDK_THIS(SpearBlock);9697foreach_active(Player, player)98{99Player_CheckCollisionBox(player, self, &SpearBlock->blockHitbox);100Vector2 storePos = self->position;101self->position.x = self->spearPos.x;102self->position.y = self->spearPos.y;103104if (Player_CheckCollisionTouch(player, self, &SpearBlock->spearHitboxes[self->animator.frameID])) {105self->position = storePos;106Player_HurtFlip(player);107}108self->position = storePos;109}110}111112void SpearBlock_State_SetupSpears(void)113{114RSDK_THIS(SpearBlock);115116self->active = ACTIVE_NORMAL;117self->state = SpearBlock_State_SpearRetracted;118if (!(Zone->timer & 0x7F)) {119int32 frameTimer = (Zone->timer >> 7) + self->spearDir;120self->timer = 4;121self->state = SpearBlock_State_ExtendSpears;122self->animator.frameID = (frameTimer & 3);123}124}125126void SpearBlock_State_SpearRetracted(void)127{128RSDK_THIS(SpearBlock);129if (!(Zone->timer & 0x7F)) {130int32 frameTimer = (Zone->timer >> 7) + self->spearDir;131self->timer = 4;132self->state = SpearBlock_State_ExtendSpears;133self->animator.frameID = frameTimer & 3;134// Spear Sfx should be played here, it's prolly not here in the code since this is just a test object, nothing more.135}136}137138void SpearBlock_State_ExtendSpears(void)139{140RSDK_THIS(SpearBlock);141switch (self->animator.frameID) {142case 0: self->spearPos.y -= 0x80000; break;143case 1: self->spearPos.x += 0x80000; break;144case 2: self->spearPos.y += 0x80000; break;145case 3: self->spearPos.x -= 0x80000; break;146default: break;147}148149self->timer--;150if (!self->timer)151self->state = SpearBlock_State_SpearExtended;152}153154void SpearBlock_State_SpearExtended(void)155{156RSDK_THIS(SpearBlock);157if (!(Zone->timer & 0x3F)) {158self->timer = 4;159self->state = SpearBlock_State_RetractSpears;160// Spear Sfx should be played here, it's prolly not here in the code since this is just a test object, nothing more.161}162}163164void SpearBlock_State_RetractSpears(void)165{166RSDK_THIS(SpearBlock);167switch (self->animator.frameID) {168case 0: self->spearPos.y += 0x80000; break;169case 1: self->spearPos.x -= 0x80000; break;170case 2: self->spearPos.y -= 0x80000; break;171case 3: self->spearPos.x += 0x80000; break;172default: break;173}174175self->timer--;176if (!self->timer)177self->state = SpearBlock_State_SpearRetracted;178}179180#if GAME_INCLUDE_EDITOR181void SpearBlock_EditorDraw(void)182{183RSDK_THIS(SpearBlock);184self->spearPos.x = self->position.x;185self->spearPos.y = self->position.y;186187RSDK.SetSpriteAnimation(SpearBlock->aniFrames, 1, &self->animator, true, self->spearDir & 3);188RSDK.SetSpriteAnimation(SpearBlock->aniFrames, 0, &SpearBlock->animator, true, 0);189190switch (self->animator.frameID) {191case 0: self->spearPos.y -= 0x200000; break;192case 1: self->spearPos.x += 0x200000; break;193case 2: self->spearPos.y += 0x200000; break;194case 3: self->spearPos.x -= 0x200000; break;195default: break;196}197198RSDK.DrawSprite(&self->animator, &self->spearPos, false);199RSDK.DrawSprite(&SpearBlock->animator, NULL, false);200}201202void SpearBlock_EditorLoad(void)203{204SpearBlock->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/SpearBlock.bin", SCOPE_STAGE);205206RSDK_ACTIVE_VAR(SpearBlock, spearDir);207RSDK_ENUM_VAR("Up", FLIP_NONE);208RSDK_ENUM_VAR("Left", FLIP_X);209RSDK_ENUM_VAR("Down", FLIP_Y);210RSDK_ENUM_VAR("Right", FLIP_XY);211}212#endif213214void SpearBlock_Serialize(void) { RSDK_EDITABLE_VAR(SpearBlock, VAR_UINT8, spearDir); }215216217