Path: blob/master/Sonic 1/Scripts/Enemies/Motobug.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Motobug Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.startPos.x13private alias object.value2 : object.startPos.y14private alias object.value3 : object.exhaustTimer1516private alias 0 : MOTOBUG_MOVING17private alias 1 : MOTOBUG_PAUSED1819private alias 0 : MOTOBUG_ANI_MOVING20private alias 1 : MOTOBUG_ANI_IDLE2122// Player Aliases23private alias object.value40 : player.hitboxLeft24private alias object.value38 : player.hitboxTop25private alias object.value41 : player.hitboxRight26private alias object.value39 : player.hitboxBottom2728// Path ID Aliases29private alias 0 : PATH_A303132// ========================33// Function Declarations34// ========================3536reserve function Motobug_DebugDraw37reserve function Motobug_DebugSpawn383940// ========================41// Function Definitions42// ========================4344private function Motobug_DebugDraw45DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)46end function474849private function Motobug_DebugSpawn50CreateTempObject(TypeName[Motobug], 0, object.xpos, object.ypos)51GetBit(temp0, object.direction, 0)52if temp0 == FLIP_NONE53object[tempObjectPos].direction = FLIP_NONE54object[tempObjectPos].xvel = -0x1000055else56object[tempObjectPos].direction = FLIP_X57object[tempObjectPos].xvel = 0x1000058end if59end function606162// ========================63// Events64// ========================6566event ObjectUpdate67switch object.state68case MOTOBUG_MOVING69object.priority = PRIORITY_ACTIVE7071object.xpos += object.xvel7273// Check object collision74ObjectTileGrip(CSIDE_FLOOR, 0, 15, PATH_A)75if checkResult == false76// If on the edge, then pause to turn around77object.state = MOTOBUG_PAUSED78object.animation = MOTOBUG_ANI_IDLE79end if8081// Update exhaust process82if object.exhaustTimer < 2083object.exhaustTimer++84else85object.exhaustTimer = 08687CreateTempObject(TypeName[Motobug Exhaust], 0, object.xpos, object.ypos)8889// Offset the exhaust based on the Motobug's direction90if object.direction == FLIP_NONE91object[tempObjectPos].xpos += 0x16000092else93object[tempObjectPos].xpos -= 0x16000094end if9596// Set the exhaust to match the Motobug's direction97object[tempObjectPos].direction = object.direction98end if99break100101case MOTOBUG_PAUSED102if object.timer < 59103// Stay still for a moment...104object.timer++105else106// Start moving again107object.timer = 0108109object.state = MOTOBUG_MOVING110object.animation = MOTOBUG_ANI_MOVING111112// Flip the Motobug113object.direction ^= FLIP_X114FlipSign(object.xvel)115end if116break117118end switch119120if object.outOfBounds == true121temp0 = object.xpos122temp1 = object.ypos123124object.xpos = object.startPos.x125object.ypos = object.startPos.y126127if object.outOfBounds == true128if object.propertyValue == 0129object.direction = FLIP_NONE130object.xvel = -0x10000131else132object.direction = FLIP_X133object.xvel = 0x10000134end if135136object.animation = MOTOBUG_ANI_MOVING137object.priority = PRIORITY_BOUNDS138object.state = MOTOBUG_MOVING139else140object.xpos = temp0141object.ypos = temp1142end if143end if144145// Check collision with players146foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)147BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)148if checkResult == true149CallFunction(Player_BadnikBreak)150end if151next152153if object.animation == MOTOBUG_ANI_MOVING154object.frame = object.animationTimer155object.frame >>= 3156object.animationTimer++157object.animationTimer &= 31158end if159end event160161162event ObjectDraw163DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)164end event165166167event ObjectStartup168// Check which sprites to load based on current folder169CheckCurrentStageFolder("Zone01")170#platform: USE_ORIGINS171// Motobugs are big fans of the phrase "being in Mission Mode"172temp0 = checkResult173CheckEqual(game.playMode, BOOT_PLAYMODE_MISSION)174checkResult |= temp0175#endplatform176if checkResult == true177// Motobug in GHZ (or a mission) - load GHZ frames178LoadSpriteSheet("GHZ/Objects.gif")179SpriteFrame(-21, -13, 40, 28, 98, 127)180SpriteFrame(-20, -14, 39, 29, 139, 127)181SpriteFrame(-20, -13, 39, 28, 98, 156)182SpriteFrame(-20, -14, 39, 29, 139, 127)183end if184185CheckCurrentStageFolder("Zone07")186if checkResult == true187// Motobug in MBZ - load MBZ frames188LoadSpriteSheet("MBZ/Objects.gif")189SpriteFrame(-21, -13, 40, 28, 170, 145)190SpriteFrame(-20, -14, 39, 29, 171, 174)191SpriteFrame(-20, -13, 39, 28, 171, 204)192SpriteFrame(-20, -14, 39, 29, 171, 174)193end if194195// Setup all Motobugs196foreach (TypeName[Motobug], arrayPos0, ALL_ENTITIES)197object[arrayPos0].startPos.x = object[arrayPos0].xpos198object[arrayPos0].startPos.y = object[arrayPos0].ypos199200// Set their direction based on their propertyValue201if object[arrayPos0].propertyValue == 0202object[arrayPos0].direction = FLIP_NONE203object[arrayPos0].xvel = -0x10000204else205object[arrayPos0].direction = FLIP_X206object[arrayPos0].xvel = 0x10000207end if208next209210// Add Motobug to the debug item list211SetTableValue(TypeName[Motobug], DebugMode_ObjCount, DebugMode_TypesTable)212SetTableValue(Motobug_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)213SetTableValue(Motobug_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)214DebugMode_ObjCount++215end event216217218// ========================219// Editor Events220// ========================221222event RSDKEdit223if editor.returnVariable == true224switch editor.variableID225case EDIT_VAR_PROPVAL // property value226checkResult = object.propertyValue227checkResult &= 1228break229230case 0 // direction231checkResult = object.propertyValue232checkResult &= 1233break234235end switch236else237switch editor.variableID238case EDIT_VAR_PROPVAL // property value239object.propertyValue = editor.variableValue240object.propertyValue &= 1241break242243case 0 // direction244object.propertyValue = editor.variableValue245object.propertyValue &= 1246break247248end switch249end if250end event251252253event RSDKDraw254GetBit(object.direction, object.propertyValue, 0)255DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)256end event257258259event RSDKLoad260// Check which sprites to load based on current folder261CheckCurrentStageFolder("Zone07")262if checkResult == true263// Motobug in in MBZ - load MBZ frames264265LoadSpriteSheet("MBZ/Objects.gif")266SpriteFrame(-21, -13, 40, 28, 170, 145)267else268// Thanks to Origins using Motobugs everywhere, just load the GHZ sheet as a fallback, even if not in GHZ269270LoadSpriteSheet("GHZ/Objects.gif")271SpriteFrame(-21, -13, 40, 28, 98, 127)272end if273274AddEditorVariable("direction")275SetActiveVariable("direction")276AddEnumVariable("Left", 0)277AddEnumVariable("Right", 1)278end event279280281