Path: blob/master/Sonic 1/Scripts/Enemies/Orbinaut.txt
1482 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Orbinaut Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.unused12private alias object.value1 : object.activeOrbs13private alias object.value2 : object.startPos.x14private alias object.value3 : object.fireOrbs15private alias object.value4 : object.targetPlayer16private alias object.value5 : object.backupTargetPlayer // if we cant target any players, target the last player detected (or P1 if none)17private alias object.value6 : object.targetPlayerDistance1819private alias 0 : ORBINAUT_NOTARGET20private alias 1 : ORBINAUT_FIRINGORBS21private alias 2 : ORBINAUT_NOORBS22private alias 3 : ORBINAUT_ORB2324// Player Aliases25private alias object.xpos : player.xpos26private alias object.ypos : player.ypos2728private alias object.value40 : player.hitboxLeft29private alias object.value38 : player.hitboxTop30private alias object.value41 : player.hitboxRight31private alias object.value39 : player.hitboxBottom3233private alias object.value17 : debugMode.currentSelection343536// ========================37// Function Declarations38// ========================3940reserve function Orbinaut_DebugDraw41reserve function Orbinaut_DebugSpawn42reserve function Orbinaut_HandleCollisions43reserve function Orbinaut_HandleCollisions_Orb44reserve function Orbinaut_CheckOffScreen4546// ========================47// Static Values48// ========================4950private value Orbinaut_startDebugID = 0515253// ========================54// Function Definitions55// ========================5657private function Orbinaut_DebugDraw58temp0 = debugMode.currentSelection59temp0 -= Orbinaut_startDebugID60temp0--61temp0 ^= 162temp0 <<= 163DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)64end function656667private function Orbinaut_DebugSpawn68temp0 = debugMode.currentSelection69temp0 -= Orbinaut_startDebugID70CreateTempObject(TypeName[Orbinaut], temp0, object.xpos, object.ypos)71object[tempObjectPos].startPos.x = object[tempObjectPos].xpos72object[tempObjectPos].activeOrbs = 157374if object[tempObjectPos].propertyValue > 175object[tempObjectPos].fireOrbs = false76object[tempObjectPos].propertyValue &= 177GetBit(temp0, object.direction, 0)78if temp0 == FLIP_NONE79object[tempObjectPos].direction = FLIP_NONE80object[tempObjectPos].xvel = -0x400081else82object[tempObjectPos].direction = FLIP_X83object[tempObjectPos].xvel = 0x400084end if85else86object[tempObjectPos].fireOrbs = true87object[tempObjectPos].xvel = 088GetBit(temp0, object.direction, 0)89if temp0 == FLIP_NONE90object[tempObjectPos].direction = FLIP_NONE91else92object[tempObjectPos].direction = FLIP_X93end if94end if95end function969798private function Orbinaut_HandleCollisions99temp0 = 0100temp7 = object.angle101temp1 = object.xpos102temp2 = object.ypos103while temp0 < 4104GetBit(temp6, object.activeOrbs, temp0)105if temp6 == true106Cos256(object.xpos, temp7)107object.xpos <<= 12108object.xpos += temp1109110Sin256(object.ypos, temp7)111object.ypos <<= 12112object.ypos += temp2113114foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)115BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)116if checkResult == true117CallFunction(Player_Hit)118end if119next120end if121temp7 += 0x40122temp7 &= 0xFF123temp0++124loop125126object.xpos = temp1127object.ypos = temp2128foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)129BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)130if checkResult == true131CallFunction(Player_BadnikBreak)132end if133next134end function135136137private function Orbinaut_HandleCollisions_Orb138foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)139BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)140if checkResult == true141CallFunction(Player_Hit)142end if143next144end function145146147private function Orbinaut_CheckOffScreen148if object.outOfBounds == true149temp0 = object.xpos150object.xpos = object.startPos.x151if object.outOfBounds == true152object.xpos = object.startPos.x153object.activeOrbs = 15154if object.fireOrbs == false155if object.propertyValue == 0156object.direction = FLIP_NONE157object.xvel = -0x4000158else159object.direction = FLIP_X160object.xvel = 0x4000161end if162else163if object.propertyValue == 0164object.direction = FLIP_NONE165else166object.direction = FLIP_X167end if168object.xvel = 0169end if170171object.unused = 0172object.animationTimer = 0173object.priority = PRIORITY_BOUNDS174object.state = ORBINAUT_NOTARGET175object.angle = 0176else177object.xpos = temp0178end if179end if180end function181182183// ========================184// Events185// ========================186187event ObjectUpdate188switch object.state189case ORBINAUT_NOTARGET190object.priority = PRIORITY_ACTIVE191object.xpos += object.xvel192if object.direction == FLIP_NONE193object.angle++194else195object.angle--196end if197object.angle &= 255198CallFunction(Orbinaut_HandleCollisions)199200if object.fireOrbs == true201object.targetPlayerDistance = 0x7FFFFFFF202object.targetPlayer = 0xFFFF203object.backupTargetPlayer = 0204foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)205temp0 = player[currentPlayer].ypos206temp0 -= object.ypos207Abs(temp0)208if temp0 < object.targetPlayerDistance209object.targetPlayerDistance = temp0210object.backupTargetPlayer = currentPlayer211end if212213if temp0 < 0x400000214if object.targetPlayer != 0xFFFF215arrayPos0 = object.targetPlayer216temp0 = player[currentPlayer].xpos217temp0 -= object.xpos218Abs(temp0)219temp1 = object[arrayPos0].xpos220temp1 -= object.xpos221Abs(temp1)222if temp0 < temp1223object.targetPlayer = currentPlayer224end if225else226object.targetPlayer = currentPlayer227end if228end if229next230231if object.targetPlayer != 0xFFFF232arrayPos0 = object.targetPlayer233temp0 = object.xpos234temp0 -= object[arrayPos0].xpos235Abs(temp0)236if temp0 <= 0x800000237object.state = ORBINAUT_FIRINGORBS238object.frame = 1239end if240else241arrayPos0 = object.backupTargetPlayer242end if243244if object[arrayPos0].xpos < object.xpos245object.direction = FLIP_NONE246else247object.direction = FLIP_X248end if249end if250CallFunction(Orbinaut_CheckOffScreen)251break252253case ORBINAUT_FIRINGORBS254if object.direction == FLIP_NONE255object.angle++256else257object.angle--258end if259object.angle &= 0xFF260261temp0 = 0262temp7 = object.angle263while temp0 < 4264if temp7 == 64265GetBit(temp6, object.activeOrbs, temp0)266if temp6 == true267Cos256(temp1, temp7)268temp1 <<= 12269temp1 += object.xpos270Sin256(temp2, temp7)271temp2 <<= 12272temp2 += object.ypos273SetBit(object.activeOrbs, temp0, false)274CreateTempObject(TypeName[Orbinaut], 0, temp1, temp2)275object[tempObjectPos].state = ORBINAUT_ORB276if object.direction == FLIP_NONE277object[tempObjectPos].xvel = -0x20000278else279object[tempObjectPos].xvel = 0x20000280end if281end if282end if283temp7 += 0x40284temp7 &= 0xFF285temp0++286loop287288CallFunction(Orbinaut_HandleCollisions)289290if object.activeOrbs == 0291object.state = ORBINAUT_NOORBS292if object.direction == FLIP_NONE293object.xvel = -0x4000294else295object.xvel = 0x4000296end if297end if298299if object.animationTimer < 16300object.animationTimer++301else302object.frame = 2303end if304305CallFunction(Orbinaut_CheckOffScreen)306break307308case ORBINAUT_NOORBS309object.xpos += object.xvel310CallFunction(Orbinaut_HandleCollisions)311CallFunction(Orbinaut_CheckOffScreen)312break313314case ORBINAUT_ORB315object.xpos += object.xvel316CallFunction(Orbinaut_HandleCollisions_Orb)317if object.outOfBounds == true318object.type = TypeName[Blank Object]319end if320break321322end switch323end event324325326event ObjectDraw327switch object.state328case ORBINAUT_NOTARGET329case ORBINAUT_FIRINGORBS330temp0 = 0331temp7 = object.angle332while temp0 < 4333GetBit(temp6, object.activeOrbs, temp0)334if temp6 == true335Cos256(temp1, temp7)336temp1 <<= 12337temp1 += object.xpos338Sin256(temp2, temp7)339temp2 <<= 12340temp2 += object.ypos341DrawSpriteXY(3, temp1, temp2)342end if343temp7 += 64344temp7 &= 255345temp0++346loop347DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)348break349350case ORBINAUT_NOORBS351DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)352break353354case ORBINAUT_ORB355DrawSprite(3)356break357358end switch359end event360361362event ObjectStartup363CheckCurrentStageFolder("Zone04")364if checkResult == true365LoadSpriteSheet("LZ/Objects.gif")366SpriteFrame(-10, -10, 20, 20, 50, 105)367SpriteFrame(-10, -10, 20, 20, 71, 105)368SpriteFrame(-10, -10, 20, 20, 50, 154)369SpriteFrame(-8, -8, 16, 16, 107, 1)370end if371372CheckCurrentStageFolder("Zone05")373if checkResult == true374LoadSpriteSheet("SLZ/Objects.gif")375SpriteFrame(-10, -10, 20, 20, 51, 1)376SpriteFrame(-10, -10, 20, 20, 72, 1)377SpriteFrame(-10, -10, 20, 20, 93, 1)378SpriteFrame(-8, -8, 16, 16, 114, 1)379end if380381CheckCurrentStageFolder("Zone06")382if checkResult == true383LoadSpriteSheet("SBZ/Objects.gif")384SpriteFrame(-10, -10, 20, 20, 1, 138)385SpriteFrame(-10, -10, 20, 20, 22, 138)386SpriteFrame(-10, -10, 20, 20, 43, 138)387SpriteFrame(-8, -8, 16, 16, 64, 142)388end if389390CheckCurrentStageFolder("Zone07")391if checkResult == true392LoadSpriteSheet("MBZ/Objects.gif")393SpriteFrame(-10, -10, 20, 20, 119, 114)394SpriteFrame(-10, -10, 20, 20, 140, 114)395SpriteFrame(-10, -10, 20, 20, 119, 135)396SpriteFrame(-8, -8, 16, 16, 140, 135)397end if398399foreach (TypeName[Orbinaut], arrayPos0, ALL_ENTITIES)400object[arrayPos0].startPos.x = object[arrayPos0].xpos401object[arrayPos0].activeOrbs = 15402if object[arrayPos0].propertyValue > 1403object[arrayPos0].fireOrbs = false404object[arrayPos0].propertyValue &= 1405if object[arrayPos0].propertyValue == 0406object[arrayPos0].direction = FLIP_NONE407object[arrayPos0].xvel = -0x4000408else409object[arrayPos0].direction = FLIP_X410object[arrayPos0].xvel = 0x4000411end if412else413object[arrayPos0].fireOrbs = true414object[arrayPos0].xvel = 0415if object[arrayPos0].propertyValue == 0416object[arrayPos0].direction = FLIP_NONE417else418object[arrayPos0].direction = FLIP_X419end if420end if421next422423temp0 = 0424Orbinaut_startDebugID = DebugMode_ObjCount425Orbinaut_startDebugID--426while temp0 < 2427SetTableValue(TypeName[Orbinaut], DebugMode_ObjCount, DebugMode_TypesTable)428SetTableValue(Orbinaut_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)429SetTableValue(Orbinaut_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)430DebugMode_ObjCount++431temp0++432loop433end event434435436// ========================437// Editor Events438// ========================439440event RSDKEdit441if editor.returnVariable == true442switch editor.variableID443case EDIT_VAR_PROPVAL // property value444checkResult = object.propertyValue445break446447case 0 // direction448GetBit(checkResult, object.propertyValue, 0)449break450451case 1 // fireOrbs452GetBit(checkResult, object.propertyValue, 1)453checkResult ^= true454break455456end switch457else458switch editor.variableID459case EDIT_VAR_PROPVAL // property value460object.propertyValue = editor.variableValue461break462463case 0 // direction464CheckNotEqual(editor.variableValue, false)465SetBit(object.propertyValue, 0, checkResult)466break467468case 1 // fireOrbs469CheckNotEqual(editor.variableValue, false)470checkResult ^= true471SetBit(object.propertyValue, 1, checkResult)472break473474end switch475end if476end event477478479event RSDKDraw480GetBit(object.direction, object.propertyValue, 0)481482// Draw Orbs483temp0 = 0484temp7 = object.angle485while temp0 < 4486Cos256(temp1, temp7)487temp1 <<= 12488temp1 += object.xpos489490Sin256(temp2, temp7)491temp2 <<= 12492temp2 += object.ypos493494DrawSpriteXY(3, temp1, temp2)495496temp7 += 64497temp7 &= 0xFF498temp0++499loop500DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)501end event502503504event RSDKLoad505// Make sure we have a fall-back, in case the current folder isn't actually a valid one506temp0 = false507508CheckCurrentStageFolder("Zone05")509temp0 |= checkResult510if checkResult == true511LoadSpriteSheet("SLZ/Objects.gif")512SpriteFrame(-10, -10, 20, 20, 51, 1)513SpriteFrame(-10, -10, 20, 20, 72, 1)514SpriteFrame(-10, -10, 20, 20, 93, 1)515SpriteFrame(-8, -8, 16, 16, 114, 1)516end if517518CheckCurrentStageFolder("Zone06")519temp0 |= checkResult520if checkResult == true521LoadSpriteSheet("SBZ/Objects.gif")522SpriteFrame(-10, -10, 20, 20, 1, 138)523SpriteFrame(-10, -10, 20, 20, 22, 138)524SpriteFrame(-10, -10, 20, 20, 43, 138)525SpriteFrame(-8, -8, 16, 16, 64, 142)526end if527528CheckCurrentStageFolder("Zone07")529temp0 |= checkResult530if checkResult == true531LoadSpriteSheet("MBZ/Objects.gif")532SpriteFrame(-10, -10, 20, 20, 119, 114)533SpriteFrame(-10, -10, 20, 20, 140, 114)534SpriteFrame(-10, -10, 20, 20, 119, 135)535SpriteFrame(-8, -8, 16, 16, 140, 135)536end if537538if temp0 == false539// We use LZ's sprites as the fallback, "Zone04" (LZ's folder) will come here too540LoadSpriteSheet("LZ/Objects.gif")541SpriteFrame(-10, -10, 20, 20, 50, 105)542SpriteFrame(-10, -10, 20, 20, 71, 105)543SpriteFrame(-10, -10, 20, 20, 50, 154)544SpriteFrame(-8, -8, 16, 16, 107, 1)545end if546547AddEditorVariable("direction")548SetActiveVariable("direction")549AddEnumVariable("Left", 0)550AddEnumVariable("Right", 1)551552// the actual value is "cantFireOrbs" but fireOrbs is cleaner553AddEditorVariable("fireOrbs")554SetActiveVariable("fireOrbs")555AddEnumVariable("false", false)556AddEnumVariable("true", true)557end event558559560