Path: blob/master/SonicMania/Objects/TMZ/LargeGear.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: LargeGear Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectLargeGear *LargeGear;1011void LargeGear_Update(void)12{13RSDK_THIS(LargeGear);1415self->angle = self->rotOffset + self->rotSpeed * Zone->timer;1617int32 storeX = self->position.x;18int32 storeY = self->position.y;1920foreach_active(Player, player)21{22int32 playerID = RSDK.GetEntitySlot(player);2324int32 id = 0;25int32 storedID = -1;26bool32 collided = false;2728for (int32 angle = 0x180; angle < 0x380; angle += 0x40) {29int32 ang = angle + self->angle;30int32 x = (storeX + 0x2400 * RSDK.Cos512(ang)) & 0xFFFF0000;31int32 y = (storeY + 0x2400 * RSDK.Sin512(ang)) & 0xFFFF0000;3233if (((1 << playerID) & self->activePlayers) && self->playerIDs[playerID] == id) {34player->position.x += x - self->positions[id].x;35player->position.y += y - self->positions[id].y;36}3738self->position.x = x;39self->position.y = y;4041if (Player_CheckCollisionBox(player, self, &LargeGear->hitboxTooth) == C_TOP) {42collided = true;43storedID = id;44}4546self->positions[id].x = x;47self->positions[id++].y = y;48}4950self->position.x = storeX;51self->position.y = storeY;5253if (Player_CheckCollisionBox(player, self, &LargeGear->hitboxBase) == C_TOP) {54collided = true;55storedID = -1;56self->activePlayers |= 1 << playerID;57}58else {59if (collided)60self->activePlayers |= 1 << playerID;61else62self->activePlayers &= ~(1 << playerID);63}6465self->playerIDs[playerID] = storedID;66if (collided) {67Hitbox *playerHitbox = Player_GetHitbox(player);6869RSDK.ObjectTileCollision(player, player->collisionLayers, CMODE_RWALL, self->collisionPlane, playerHitbox->left << 16, 0, true);70RSDK.ObjectTileCollision(player, player->collisionLayers, CMODE_LWALL, self->collisionPlane, playerHitbox->right << 16, 0, true);71RSDK.ObjectTileCollision(player, player->collisionLayers, CMODE_FLOOR, self->collisionPlane, playerHitbox->bottom << 16, 0, true);72}73}7475self->position.x = storeX;76self->position.y = storeY;7778RSDK.ProcessAnimation(&self->baseAnimator);79}8081void LargeGear_LateUpdate(void) {}8283void LargeGear_StaticUpdate(void) {}8485void LargeGear_Draw(void)86{87RSDK_THIS(LargeGear);8889for (int32 i = 0; i < 0x200; i += 0x40) {90self->rotation = i + self->angle;9192RSDK.SetSpriteAnimation(LargeGear->aniFrames, 1, &self->toothAnimator, true, 7 - abs(RSDK.Sin512(self->rotation) / 73));9394RSDK.DrawSprite(&self->toothAnimator, NULL, false);95RSDK.Cos512(self->rotation + 0x180);96RSDK.Sin512(self->rotation + 0x180);97self->rotation = 0;98}99100self->rotation = 0;101RSDK.DrawSprite(&self->baseAnimator, NULL, false);102103self->rotation = self->angle;104RSDK.DrawSprite(&self->centerAnimator, NULL, false);105106self->rotation = 0;107RSDK.DrawSprite(&self->axleAnimator, NULL, false);108109for (int32 i = 0; i < 0x200; i += 0x80) {110int32 angle = i + self->angle;111112Vector2 drawPos = self->position;113114drawPos.x += 0x1300 * RSDK.Cos512(angle);115drawPos.y += 0x1300 * RSDK.Sin512(angle);116RSDK.DrawSprite(&self->rivetAnimator, &drawPos, false);117}118}119120void LargeGear_Create(void *data)121{122RSDK_THIS(LargeGear);123124self->active = ACTIVE_BOUNDS;125self->drawGroup = Zone->objectDrawGroup[0];126self->origin = self->position;127self->visible = true;128self->drawFX = FX_ROTATE | FX_FLIP;129self->updateRange.x = 0x800000;130self->updateRange.y = 0x800000;131132RSDK.SetSpriteAnimation(LargeGear->aniFrames, 0, &self->baseAnimator, true, 0);133RSDK.SetSpriteAnimation(LargeGear->aniFrames, 1, &self->toothAnimator, true, 0);134RSDK.SetSpriteAnimation(LargeGear->aniFrames, 2, &self->axleAnimator, true, 0);135RSDK.SetSpriteAnimation(LargeGear->aniFrames, 3, &self->centerAnimator, true, 0);136RSDK.SetSpriteAnimation(LargeGear->aniFrames, 4, &self->rivetAnimator, true, 0);137138self->angle = self->rotOffset;139}140141void LargeGear_StageLoad(void)142{143LargeGear->aniFrames = RSDK.LoadSpriteAnimation("TMZ1/LargeGear.bin", SCOPE_STAGE);144145LargeGear->hitboxTooth.left = -10;146LargeGear->hitboxTooth.top = -10;147LargeGear->hitboxTooth.right = 10;148LargeGear->hitboxTooth.bottom = 10;149150LargeGear->hitboxBase.left = -8;151LargeGear->hitboxBase.top = -64;152LargeGear->hitboxBase.right = 8;153LargeGear->hitboxBase.bottom = 64;154}155156#if GAME_INCLUDE_EDITOR157void LargeGear_EditorDraw(void)158{159RSDK_THIS(LargeGear);160161self->origin = self->position;162self->angle = self->rotOffset;163164LargeGear_Draw();165}166167void LargeGear_EditorLoad(void) { LargeGear->aniFrames = RSDK.LoadSpriteAnimation("TMZ1/LargeGear.bin", SCOPE_STAGE); }168#endif169170void LargeGear_Serialize(void)171{172RSDK_EDITABLE_VAR(LargeGear, VAR_INT32, rotSpeed);173RSDK_EDITABLE_VAR(LargeGear, VAR_INT32, rotOffset);174}175176177