Path: blob/master/Sonic 1/Scripts/Mission/Motobug2.txt
1482 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// This bit of code is new to Motobug2, let's check collision with Mission Blocks and use them as an extension of normal ground8283// If we just turned around, then let's see if there's actually more Mission Blocks in the direction we were going84if object.state == MOTOBUG_PAUSED85foreach (TypeName[MissionBlock], arrayPos0, ACTIVE_ENTITIES)86temp1 = false8788temp2 = object[arrayPos0].ixpos89temp2 -= object.ixpos90CheckGreater(temp2, -18)91temp1 = checkResult92CheckLower(temp2, 18)93temp1 &= checkResult9495temp2 = object[arrayPos0].iypos96temp2 -= object.iypos97CheckGreater(temp2, 15)98temp1 &= checkResult99CheckLower(temp2, 40)100temp1 &= checkResult101102if temp1 == true103// There's still more Mission Blocks for us to drive on, so instead of turning around let's just keep going104object.state = MOTOBUG_MOVING105object.animation = MOTOBUG_ANI_MOVING106end if107next108end if109110// If we're moving, then let's see if there are more Mission Blocks ahead of us111if object.state == MOTOBUG_MOVING112temp0 = false113114foreach (TypeName[MissionBlock], arrayPos0, ACTIVE_ENTITIES)115temp1 = false116117temp2 = object[arrayPos0].ixpos118temp2 -= object.ixpos119CheckGreater(temp2, -36)120temp1 = checkResult121CheckLower(temp2, 36)122temp1 &= checkResult123124temp2 = object[arrayPos0].iypos125temp2 -= object.iypos126CheckGreater(temp2, -30)127temp1 &= checkResult128CheckLower(temp2, 30)129temp1 &= checkResult130131temp0 |= temp1132next133134if temp0 != false135// If we're at the end of the row of Mission Blocks, then let's turn around136object.state = MOTOBUG_PAUSED137object.animation = MOTOBUG_ANI_IDLE138end if139end if140141// Update exhaust process142if object.exhaustTimer < 20143object.exhaustTimer++144else145object.exhaustTimer = 0146147CreateTempObject(TypeName[Motobug Exhaust], 0, object.xpos, object.ypos)148149// Offset the exhaust based on the Motobug's direction150if object.direction == FLIP_NONE151object[tempObjectPos].xpos += 0x160000152else153object[tempObjectPos].xpos -= 0x160000154end if155156// Set the exhaust to match the Motobug's direction157object[tempObjectPos].direction = object.direction158end if159break160161case MOTOBUG_PAUSED162if object.timer < 59163// Stay still for a moment...164object.timer++165else166// Start moving again167object.timer = 0168169object.state = MOTOBUG_MOVING170object.animation = MOTOBUG_ANI_MOVING171172// Flip the Motobug173object.direction ^= FLIP_X174FlipSign(object.xvel)175end if176break177178end switch179180if object.outOfBounds == true181temp0 = object.xpos182temp1 = object.ypos183184object.xpos = object.startPos.x185object.ypos = object.startPos.y186187if object.outOfBounds == true188if object.propertyValue == 0189object.direction = FLIP_NONE190object.xvel = -0x10000191else192object.direction = FLIP_X193object.xvel = 0x10000194end if195196object.animation = MOTOBUG_ANI_MOVING197object.priority = PRIORITY_BOUNDS198object.state = MOTOBUG_MOVING199else200object.xpos = temp0201object.ypos = temp1202end if203end if204205// Check collision with players206foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)207BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)208if checkResult == true209CallFunction(Player_BadnikBreak)210end if211next212213if object.animation == MOTOBUG_ANI_MOVING214object.frame = object.animationTimer215object.frame >>= 3216object.animationTimer++217object.animationTimer &= 31218end if219end event220221222event ObjectDraw223if object.state != 2 // This state doesn't exist??? (this check is new to Motobug2 too btw, normal Motobug doesn't have this)224DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)225end if226end event227228229event ObjectStartup230if game.playMode == BOOT_PLAYMODE_MISSION231LoadSpriteSheet("GHZ/Objects.gif")232SpriteFrame(-21, -13, 40, 28, 98, 127)233SpriteFrame(-20, -14, 39, 29, 139, 127)234SpriteFrame(-20, -13, 39, 28, 98, 156)235SpriteFrame(-20, -14, 39, 29, 139, 127)236end if237238// (They removed the MBZ sheet checks and such here, more power to 'em I suppose)239240// Setup all Motobugs241foreach (TypeName[Motobug], arrayPos0, ALL_ENTITIES)242object[arrayPos0].startPos.x = object[arrayPos0].xpos243object[arrayPos0].startPos.y = object[arrayPos0].ypos244245// Set their direction based on their propertyValue246if object[arrayPos0].propertyValue == 0247object[arrayPos0].direction = FLIP_NONE248object[arrayPos0].xvel = -0x10000249else250object[arrayPos0].direction = FLIP_X251object[arrayPos0].xvel = 0x10000252end if253next254255// Add Motobug to the debug item list256SetTableValue(TypeName[Motobug], DebugMode_ObjCount, DebugMode_TypesTable)257SetTableValue(Motobug_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)258SetTableValue(Motobug_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)259DebugMode_ObjCount++260end event261262263// ========================264// Editor Events265// ========================266267event RSDKEdit268if editor.returnVariable == true269switch editor.variableID270case EDIT_VAR_PROPVAL // property value271checkResult = object.propertyValue272checkResult &= 1273break274275case 0 // direction276checkResult = object.propertyValue277checkResult &= 1278break279280end switch281else282switch editor.variableID283case EDIT_VAR_PROPVAL // property value284object.propertyValue = editor.variableValue285object.propertyValue &= 1286break287288case 0 // direction289object.propertyValue = editor.variableValue290object.propertyValue &= 1291break292293end switch294end if295end event296297298event RSDKDraw299GetBit(object.direction, object.propertyValue, 0)300DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)301end event302303304event RSDKLoad305LoadSpriteSheet("GHZ/Objects.gif")306SpriteFrame(-21, -13, 40, 28, 98, 127)307308AddEditorVariable("direction")309SetActiveVariable("direction")310AddEnumVariable("Left", 0)311AddEnumVariable("Right", 1)312end event313314315