Path: blob/master/SonicMania/Objects/AIZ/AIZTornado.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: AIZTornado Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectAIZTornado *AIZTornado;1011void AIZTornado_Update(void)12{13RSDK_THIS(AIZTornado);14self->prevPos.x = self->position.x;15self->prevPos.y = self->position.y;16StateMachine_Run(self->state);1718self->animatorTornado.frameID = self->turnAngle >> 4;19RSDK.ProcessAnimation(&self->animatorPropeller);20RSDK.ProcessAnimation(&self->animatorPilot);21RSDK.ProcessAnimation(&self->animatorFlame);22}2324void AIZTornado_LateUpdate(void) {}2526void AIZTornado_StaticUpdate(void) {}2728void AIZTornado_Draw(void)29{30RSDK_THIS(AIZTornado);31RSDK.DrawSprite(&self->animatorPilot, NULL, false);32RSDK.DrawSprite(&self->animatorPropeller, NULL, false);33RSDK.DrawSprite(&self->animatorTornado, NULL, false);34if (self->showFlame) {35Vector2 drawPos;36drawPos.x = self->position.x;37drawPos.y = self->position.y;38drawPos.y += AIZTornado->flameOffsets[self->animatorTornado.frameID];39RSDK.DrawSprite(&self->animatorFlame, &drawPos, false);40}41}4243void AIZTornado_Create(void *data)44{45RSDK_THIS(AIZTornado);46if (!SceneInfo->inEditor) {47self->visible = true;48self->updateRange.x = 0x1000000;49self->updateRange.y = 0x1000000;50self->drawFX = FX_FLIP;51self->drawGroup = Zone->objectDrawGroup[0];52self->movePos.x = self->position.x;53self->movePos.y = self->position.y;54self->turnAngle = 48;55self->isStood = true;56self->offsetX = 0x80000;57self->showFlame = true;5859if (RSDK.CheckSceneFolder("AIZ") || RSDK.CheckSceneFolder("Credits"))60self->active = ACTIVE_NORMAL;6162if (!StarPost->postIDs[0]) {63self->active = ACTIVE_NORMAL;64self->state = AIZTornado_State_Move;65}6667RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 0, &self->animatorTornado, true, 0);68RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 1, &self->animatorPropeller, true, 0);69RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 2, &self->animatorFlame, true, 0);70if (GET_CHARACTER_ID(1) == ID_SONIC) // if sonic is the leader71RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 6, &self->animatorPilot, true, 0);72else73RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 3, &self->animatorPilot, true, 0);74}75}7677void AIZTornado_StageLoad(void)78{79if (RSDK.CheckSceneFolder("AIZ") || RSDK.CheckSceneFolder("Credits"))80AIZTornado->aniFrames = RSDK.LoadSpriteAnimation("AIZ/AIZTornado.bin", SCOPE_STAGE);81}8283void AIZTornado_HandleMovement(void)84{85RSDK_THIS(AIZTornado);86self->movePos.x += AIZTornadoPath->moveVel.x;87self->movePos.y += AIZTornadoPath->moveVel.y;88self->newPos.x = self->movePos.x;89self->newPos.y = self->movePos.y;9091if (!self->disableInteractions) {92int32 x = self->movePos.x;93int32 y = self->movePos.y;94if (AIZTornadoPath->moveVel.y) {95self->turnAngle = 0;96}97else {98y = 0xA00 * RSDK.Sin256(2 * Zone->timer) + self->movePos.y;99self->turnAngle = (RSDK.Sin256(2 * Zone->timer) >> 3) + 32;100}101self->newPos.x += (x - self->movePos.x) >> 1;102self->newPos.y += (y - self->movePos.y) >> 1;103}104self->position.x = self->newPos.x;105self->position.y = self->newPos.y;106}107108void AIZTornado_HandlePlayerCollisions(void)109{110RSDK_THIS(AIZTornado);111EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);112Hitbox *hitbox = RSDK.GetHitbox(&self->animatorTornado, 0);113if (self->turnAngle >= 32)114player->drawGroup = self->drawGroup + 1;115else116player->drawGroup = self->drawGroup;117int32 x = self->position.x;118int32 y = self->position.y;119self->prevPos.x &= 0xFFFF0000;120self->prevPos.y &= 0xFFFF0000;121self->isStood = false;122self->moveVelocity.x = (x & 0xFFFF0000) - self->prevPos.x;123self->moveVelocity.y = (y & 0xFFFF0000) - self->prevPos.y;124self->position.x = self->prevPos.x;125self->position.y = self->prevPos.y;126127if (Player_CheckCollisionPlatform(player, self, hitbox)) {128RSDK.SetSpriteAnimation(player->aniFrames, ANI_RIDE, &player->animator, false, 0);129player->state = Player_State_Static;130player->position.x += self->moveVelocity.x;131player->position.y += self->moveVelocity.y;132player->flailing = false;133self->isStood = true;134if (player->velocity.y > 0x10000) {135self->collideTimer = 0;136self->gravityForce = 0x20000;137}138}139self->position.x = x;140self->position.y = y;141}142143void AIZTornado_State_Move(void)144{145RSDK_THIS(AIZTornado);146self->prevPos.x = self->position.x;147self->prevPos.y = self->position.y;148AIZTornado_HandleMovement();149if (!self->disableInteractions)150AIZTornado_HandlePlayerCollisions();151}152153#if GAME_INCLUDE_EDITOR154void AIZTornado_EditorDraw(void)155{156RSDK_THIS(AIZTornado);157RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 0, &self->animatorTornado, true, 0);158RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 1, &self->animatorPropeller, true, 0);159RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 2, &self->animatorFlame, true, 0);160RSDK.SetSpriteAnimation(AIZTornado->aniFrames, 3, &self->animatorPilot, true, 0);161162RSDK.DrawSprite(&self->animatorPilot, NULL, false);163RSDK.DrawSprite(&self->animatorPropeller, NULL, false);164RSDK.DrawSprite(&self->animatorTornado, NULL, false);165}166167void AIZTornado_EditorLoad(void) { AIZTornado->aniFrames = RSDK.LoadSpriteAnimation("AIZ/AIZTornado.bin", SCOPE_STAGE); }168#endif169170void AIZTornado_Serialize(void) {}171172173