Path: blob/master/SonicMania/Objects/GHZ/Motobug.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: Motobug Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectMotobug *Motobug;1011void Motobug_Update(void)12{13RSDK_THIS(Motobug);14StateMachine_Run(self->state);15}1617void Motobug_LateUpdate(void) {}1819void Motobug_StaticUpdate(void) {}2021void Motobug_Draw(void)22{23RSDK_THIS(Motobug);24RSDK.DrawSprite(&self->animator, NULL, false);25}2627void Motobug_Create(void *data)28{29RSDK_THIS(Motobug);30self->visible = true;31self->drawFX |= FX_FLIP;32self->drawGroup = Zone->objectDrawGroup[0];33self->startPos = self->position;34self->startDir = self->direction;35self->active = ACTIVE_BOUNDS;36self->updateRange.x = 0x800000;37self->updateRange.y = 0x800000;38self->wasTurning = true;3940if (data) {41RSDK.SetSpriteAnimation(Motobug->aniFrames, 3, &self->animator, true, 0);42self->state = Motobug_State_Smoke;43}44else {45self->timer = 16;46RSDK.SetSpriteAnimation(Motobug->aniFrames, 0, &self->animator, true, 0);47self->state = Motobug_State_Init;48}49}5051void Motobug_StageLoad(void)52{53if (RSDK.CheckSceneFolder("GHZ"))54Motobug->aniFrames = RSDK.LoadSpriteAnimation("GHZ/Motobug.bin", SCOPE_STAGE);55else if (RSDK.CheckSceneFolder("Blueprint"))56Motobug->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/Motobug.bin", SCOPE_STAGE);5758Motobug->hitboxBadnik.left = -14;59Motobug->hitboxBadnik.top = -14;60Motobug->hitboxBadnik.right = 14;61Motobug->hitboxBadnik.bottom = 14;6263DEBUGMODE_ADD_OBJ(Motobug);64}6566void Motobug_DebugDraw(void)67{68RSDK.SetSpriteAnimation(Motobug->aniFrames, 0, &DebugMode->animator, true, 0);69RSDK.DrawSprite(&DebugMode->animator, NULL, false);70}71void Motobug_DebugSpawn(void)72{73RSDK_THIS(DebugMode);7475CREATE_ENTITY(Motobug, NULL, self->position.x, self->position.y);76}77void Motobug_CheckOffScreen(void)78{79RSDK_THIS(Motobug);8081if (!RSDK.CheckOnScreen(self, NULL) && !RSDK.CheckPosOnScreen(&self->startPos, &self->updateRange)) {82self->position = self->startPos;83self->direction = self->startDir;84Motobug_Create(NULL);85}86}87void Motobug_CheckPlayerCollisions(void)88{89RSDK_THIS(Motobug);9091foreach_active(Player, player)92{93if (Player_CheckBadnikTouch(player, self, &Motobug->hitboxBadnik))94Player_CheckBadnikBreak(player, self, true);95}96}97void Motobug_State_Fall(void)98{99RSDK_THIS(Motobug);100101RSDK.ProcessAnimation(&self->animator);102103if (self->wasTurning)104self->position.x += self->velocity.x;105106self->position.y += self->velocity.y;107self->velocity.y += 0x3800;108109if (RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, 0xF0000, 8)) {110self->wasTurning = true;111self->velocity.y = 0;112RSDK.SetSpriteAnimation(Motobug->aniFrames, 0, &self->animator, true, 0);113self->state = Motobug_State_Move;114Motobug_State_Move();115}116else {117Motobug_CheckPlayerCollisions();118Motobug_CheckOffScreen();119}120}121void Motobug_State_Move(void)122{123RSDK_THIS(Motobug);124125self->position.x += self->velocity.x;126127if (!RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0, 0xF0000, 8)) {128RSDK.SetSpriteAnimation(Motobug->aniFrames, 1, &self->animator, true, 0);129self->turnTimer = 0;130131bool32 collided = false;132if (self->direction)133collided = RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, -0x10000, 0xF0000, 8);134else135collided = RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0x10000, 0xF0000, 8);136137if (collided)138self->state = Motobug_State_Idle;139else140self->state = Motobug_State_Fall;141}142143if (!--self->timer) {144self->timer = 16;145EntityMotobug *smoke = CREATE_ENTITY(Motobug, INT_TO_VOID(true), self->position.x, self->position.y);146if (self->direction == FLIP_X)147smoke->position.x -= 0x140000;148else149smoke->position.x += 0x140000;150}151152RSDK.ProcessAnimation(&self->animator);153154Motobug_CheckPlayerCollisions();155Motobug_CheckOffScreen();156}157void Motobug_State_Idle(void)158{159RSDK_THIS(Motobug);160161RSDK.ProcessAnimation(&self->animator);162163bool32 collided = false;164if (self->direction)165collided = RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, -0x10000, 0xF0000, 8);166else167collided = RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0x10000, 0xF0000, 8);168169if (collided) {170++self->turnTimer;171if (self->turnTimer == 30) {172RSDK.SetSpriteAnimation(Motobug->aniFrames, 2, &self->animator, true, 0);173self->state = Motobug_State_Turn;174}175}176else {177self->wasTurning = false;178RSDK.SetSpriteAnimation(Motobug->aniFrames, 0, &self->animator, true, 0);179self->state = Motobug_State_Fall;180self->direction ^= FLIP_X;181self->velocity.x = -self->velocity.x;182}183184Motobug_CheckPlayerCollisions();185Motobug_CheckOffScreen();186}187void Motobug_State_Init(void)188{189RSDK_THIS(Motobug);190191self->active = ACTIVE_NORMAL;192self->velocity.x = -0x10000;193self->velocity.y = 0;194195self->state = Motobug_State_Move;196Motobug_State_Move();197}198void Motobug_State_Smoke(void)199{200RSDK_THIS(Motobug);201202RSDK.ProcessAnimation(&self->animator);203204if (self->animator.frameID == self->animator.frameCount - 1)205destroyEntity(self);206}207void Motobug_State_Turn(void)208{209RSDK_THIS(Motobug);210211RSDK.ProcessAnimation(&self->animator);212213bool32 collided = false;214if (self->direction)215collided = RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, -0x10000, 0xF0000, 8);216else217collided = RSDK.ObjectTileGrip(self, Zone->collisionLayers, CMODE_FLOOR, 0, 0x10000, 0xF0000, 8);218219if (collided) {220if (self->animator.frameID == self->animator.frameCount - 1) {221RSDK.SetSpriteAnimation(Motobug->aniFrames, 0, &self->animator, true, 0);222self->direction ^= FLIP_X;223self->velocity.x = -self->velocity.x;224self->state = Motobug_State_Move;225Motobug_State_Move();226}227else {228Motobug_CheckPlayerCollisions();229Motobug_CheckOffScreen();230}231}232else {233self->wasTurning = false;234RSDK.SetSpriteAnimation(Motobug->aniFrames, 0, &self->animator, true, 0);235self->state = Motobug_State_Fall;236self->direction ^= FLIP_X;237self->velocity.x = -self->velocity.x;238}239}240241#if GAME_INCLUDE_EDITOR242void Motobug_EditorDraw(void) { Motobug_Draw(); }243244void Motobug_EditorLoad(void)245{246if (RSDK.CheckSceneFolder("GHZ"))247Motobug->aniFrames = RSDK.LoadSpriteAnimation("GHZ/Motobug.bin", SCOPE_STAGE);248else if (RSDK.CheckSceneFolder("Blueprint"))249Motobug->aniFrames = RSDK.LoadSpriteAnimation("Blueprint/Motobug.bin", SCOPE_STAGE);250}251#endif252253void Motobug_Serialize(void) {}254255256