Path: blob/master/Sonic 2/Scripts/HPZ/RotatePlatform.txt
1478 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Rotate Platform Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.state : object.isDynamic1213private alias object.value0 : object.rotateAngle14private alias object.value1 : object.drawPos.x15private alias object.value2 : object.drawPos.y16private alias object.value3 : object.collisionOffset.x17private alias object.value4 : object.collisionOffset.y18private alias object.value5 : object.length19private alias object.value6 : object.rotateSpeed20private alias object.value7 : object.useSpikeballs21private alias object.value8 : object.platformFrame22private alias object.value9 : object.pivotAnimTimer23private alias object.value10 : object.pivotFrame24private alias object.value11 : object.amplitude2526// Player Aliases27private alias object.xpos : player.xpos28private alias object.ypos : player.ypos293031// ========================32// Function Declarations33// ========================3435reserve function RotatePlatform_DebugDraw36reserve function RotatePlatform_DebugSpawn373839// ========================40// Tables41// ========================4243private table RotatePlatform_pivotFrames442, 2, 2, 2, 1, 0, 0, 145end table464748// ========================49// Function Definitions50// ========================5152private function RotatePlatform_DebugDraw53temp7 = 354DrawSprite(0)5556temp0 = 057temp1 = 1658while temp0 < temp759Cos(temp2, 128)60temp2 *= temp161temp2 <<= 762temp2 += object.xpos6364Sin(temp3, 128)65temp3 *= temp166temp3 <<= 767temp3 += object.ypos6869DrawSpriteXY(1, temp2, temp3)7071temp0++72temp1 += 1673loop74temp1 -= 87576Cos(temp2, 128)77temp2 *= temp178temp2 <<= 779temp2 += object.xpos8081Sin(temp3, 128)82temp3 *= temp183temp3 <<= 784temp3 += object.ypos8586DrawSpriteXY(2, temp2, temp3)87end function888990private function RotatePlatform_DebugSpawn91// Bug Details:92// -> Only the last Rotate Platform spawned here is given the PRIORITY_XBOUNDS_DESTROY priority, while the first two aren't93// -> Because of this, if you go make these go off screen and then return to them later,94// it'll only be a set of 2 platforms rather than the usual 395// (yeah this really isn't too big of a bug but hey, it's worth noting anyways)9697CreateTempObject(TypeName[Rotate Platform], 0, object.xpos, object.ypos)98object[tempObjectPos].length = 399object[tempObjectPos].rotateSpeed = 128100object[tempObjectPos].rotateAngle = 0101102CreateTempObject(TypeName[Rotate Platform], 0, object.xpos, object.ypos)103object[tempObjectPos].length = 3104object[tempObjectPos].rotateSpeed = 128105object[tempObjectPos].rotateAngle = 0x5500106107CreateTempObject(TypeName[Rotate Platform], 0, object.xpos, object.ypos)108object[tempObjectPos].length = 3109object[tempObjectPos].rotateSpeed = 128110object[tempObjectPos].rotateAngle = 0xAB00111end function112113114// ========================115// Events116// ========================117118event ObjectUpdate119if object.isDynamic == true120temp0 = oscillation121temp0 <<= 1122Sin(object.amplitude, temp0)123object.amplitude >>= 3124object.amplitude += 0xC0125else126object.amplitude = 0x100127end if128129temp2 = object.xpos130temp3 = object.ypos131object.rotateAngle += object.rotateSpeed132object.rotateAngle &= 0x1FFFF133134temp0 = object.rotateAngle135temp0 >>= 8136temp1 = object.length137temp1++138temp1 <<= 4139object.xpos = object.drawPos.x140object.ypos = object.drawPos.y141142Cos256(object.collisionOffset.x, temp0)143object.collisionOffset.x *= temp1144object.collisionOffset.x *= object.amplitude145object.collisionOffset.x += temp2146object.collisionOffset.x &= 0xFFFF0000147object.drawPos.x = object.collisionOffset.x148object.collisionOffset.x -= object.xpos149150Sin256(object.collisionOffset.y, temp0)151object.collisionOffset.y *= temp1152object.collisionOffset.y *= object.amplitude153object.collisionOffset.y += temp3154object.collisionOffset.y &= 0xFFFF0000155object.drawPos.y = object.collisionOffset.y156object.collisionOffset.y -= object.ypos157158if object.useSpikeballs == false159foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)160BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)161if checkResult == true162player[currentPlayer].xpos += object.collisionOffset.x163player[currentPlayer].ypos += object.collisionOffset.y164end if165next166else167foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)168BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)169if checkResult == true170CallFunction(Player_Hit)171end if172next173end if174175object.xpos = temp2176object.ypos = temp3177178temp0 = object.pivotAnimTimer179temp0 >>= 2180GetTableValue(object.pivotFrame, temp0, RotatePlatform_pivotFrames)181object.pivotAnimTimer++182object.pivotAnimTimer &= 31183end event184185186event ObjectDraw187temp0 = 0188temp1 = 16189temp4 = object.rotateAngle190temp4 >>= 8191while temp0 < object.length192Cos256(temp2, temp4)193temp2 *= temp1194temp2 *= object.amplitude195temp2 += object.xpos196197Sin256(temp3, temp4)198temp3 *= temp1199temp3 *= object.amplitude200temp3 += object.ypos201202DrawSpriteXY(3, temp2, temp3)203204temp0++205temp1 += 16206loop207208Cos256(object.drawPos.x, temp4)209object.drawPos.x *= temp1210object.drawPos.x *= object.amplitude211object.drawPos.x += object.xpos212object.drawPos.x &= 0xFFFF0000213214Sin256(object.drawPos.y, temp4)215object.drawPos.y *= temp1216object.drawPos.y *= object.amplitude217object.drawPos.y += object.ypos218object.drawPos.y &= 0xFFFF0000219220DrawSpriteXY(object.platformFrame, object.drawPos.x, object.drawPos.y)221DrawSprite(object.pivotFrame)222end event223224225event ObjectStartup226LoadSpriteSheet("HPZ/Objects.gif")227SpriteFrame(-8, -8, 16, 16, 181, 73) // orb (inactive) - #0228SpriteFrame(-8, -8, 16, 16, 181, 90) // orb (activating) - #1229SpriteFrame(-8, -8, 16, 16, 181, 107) // orb (active) - #2230SpriteFrame(-8, -8, 16, 16, 181, 73) // orb (inactive) - #3231SpriteFrame(-32, -8, 64, 16, 1, 183) // platform - #4232SpriteFrame(-20, -20, 40, 40, 402, 66) // spike - #5233234SetTableValue(TypeName[Rotate Platform], DebugMode_ObjCount, DebugMode_TypesTable)235SetTableValue(RotatePlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)236SetTableValue(RotatePlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)237DebugMode_ObjCount++238239foreach (TypeName[Rotate Platform], arrayPos0, ALL_ENTITIES)240if object[arrayPos0].isDynamic == true241object[arrayPos0].length = 5242else243object[arrayPos0].length = 4244end if245246object[arrayPos0].rotateSpeed = object[arrayPos0].propertyValue247object[arrayPos0].rotateSpeed >>= 3248object[arrayPos0].rotateSpeed <<= 7249object[arrayPos0].rotateSpeed &= 0x7FB250if object[arrayPos0].rotateSpeed >= 0x400251object[arrayPos0].rotateSpeed -= 0x400252FlipSign(object[arrayPos0].rotateSpeed)253end if254255object[arrayPos0].rotateAngle = object[arrayPos0].propertyValue256object[arrayPos0].rotateAngle &= 7257object[arrayPos0].rotateAngle *= 0x2A00258259object[arrayPos0].useSpikeballs = object[arrayPos0].propertyValue260object[arrayPos0].useSpikeballs >>= 7261if object[arrayPos0].useSpikeballs == false262object[arrayPos0].platformFrame = 4263else264object[arrayPos0].platformFrame = 5265end if266next267end event268269270// ========================271// Editor Events272// ========================273274event RSDKEdit275if editor.returnVariable == true276switch editor.variableID277case EDIT_VAR_PROPVAL // property value278checkResult = object.propertyValue279break280281case 0 // angle282checkResult = object.propertyValue283checkResult &= 7284break285286case 1 // rotateSpeed287checkResult = object.propertyValue288checkResult >>= 3289checkResult &= 0xF290break291292case 2 // useSpikeball293GetBit(checkResult, object.propertyValue, 7)294break295296case 3 // isDynamic297checkResult = object.state298break299300end switch301else302switch editor.variableID303case EDIT_VAR_PROPVAL // property value304object.propertyValue = editor.variableValue305break306307case 0 // angle308editor.variableValue &= 7309310temp0 = 7311Not(temp0)312object.propertyValue &= temp0313314object.propertyValue |= editor.variableValue315break316317case 1 // rotateSpeed318editor.variableValue &= 0xF319editor.variableValue <<= 3320321temp0 = 0x78322Not(temp0)323object.propertyValue &= temp0324325object.propertyValue |= editor.variableValue326break327328case 2 // useSpikeball329CheckNotEqual(editor.variableValue, false)330SetBit(object.propertyValue, 7, checkResult)331break332333case 3 // isDynamic334object.state = editor.variableValue335break336337end switch338end if339end event340341342event RSDKDraw343if object.isDynamic == true344object.length = 5345else346object.length = 4347end if348349object.rotateSpeed = object.propertyValue350object.rotateSpeed >>= 3351object.rotateSpeed <<= 7352object.rotateSpeed &= 0x7FB353if object.rotateSpeed >= 0x400354object.rotateSpeed -= 0x400355FlipSign(object.rotateSpeed)356end if357358object.rotateAngle = object.propertyValue359object.rotateAngle &= 7360object.rotateAngle *= 0x2A00361362object.useSpikeballs = object.propertyValue363object.useSpikeballs >>= 7364if object.useSpikeballs == false365object.platformFrame = 4366else367object.platformFrame = 5368end if369370if object.isDynamic == true371Sin(object.amplitude, 0)372object.amplitude >>= 3373object.amplitude += 0xC0374else375object.amplitude = 0x100376end if377378temp2 = object.xpos379temp3 = object.ypos380object.rotateAngle &= 0x1FFFF381382temp0 = object.rotateAngle383temp0 >>= 8384temp1 = object.length385temp1++386temp1 <<= 4387object.xpos = object.drawPos.x388object.ypos = object.drawPos.y389390Cos256(object.collisionOffset.x, temp0)391object.collisionOffset.x *= temp1392object.collisionOffset.x *= object.amplitude393object.collisionOffset.x += temp2394object.collisionOffset.x &= 0xFFFF0000395object.drawPos.x = object.collisionOffset.x396object.collisionOffset.x -= object.xpos397398Sin256(object.collisionOffset.y, temp0)399object.collisionOffset.y *= temp1400object.collisionOffset.y *= object.amplitude401object.collisionOffset.y += temp3402object.collisionOffset.y &= 0xFFFF0000403object.drawPos.y = object.collisionOffset.y404object.collisionOffset.y -= object.ypos405406object.xpos = temp2407object.ypos = temp3408409temp0 = 0410temp1 = 16411temp4 = object.rotateAngle412temp4 >>= 8413while temp0 < object.length414Cos256(temp2, temp4)415temp2 *= temp1416temp2 *= object.amplitude417temp2 += object.xpos418419Sin256(temp3, temp4)420temp3 *= temp1421temp3 *= object.amplitude422temp3 += object.ypos423424DrawSpriteXY(3, temp2, temp3)425426temp0++427temp1 += 16428loop429430Cos256(object.drawPos.x, temp4)431object.drawPos.x *= temp1432object.drawPos.x *= object.amplitude433object.drawPos.x += object.xpos434object.drawPos.x &= 0xFFFF0000435436Sin256(object.drawPos.y, temp4)437object.drawPos.y *= temp1438object.drawPos.y *= object.amplitude439object.drawPos.y += object.ypos440object.drawPos.y &= 0xFFFF0000441442DrawSpriteXY(object.platformFrame, object.drawPos.x, object.drawPos.y)443DrawSprite(2)444end event445446447event RSDKLoad448LoadSpriteSheet("HPZ/Objects.gif")449SpriteFrame(-8, -8, 16, 16, 181, 73) // orb (inactive) - #0450SpriteFrame(-8, -8, 16, 16, 181, 90) // orb (activating) - #1451SpriteFrame(-8, -8, 16, 16, 181, 107) // orb (active) - #2452SpriteFrame(-8, -8, 16, 16, 181, 73) // orb (inactive) - #3453SpriteFrame(-32, -8, 64, 16, 1, 183) // platform - #4454SpriteFrame(-20, -20, 40, 40, 402, 66) // spike - #5455456AddEditorVariable("angle")457SetActiveVariable("angle")458459AddEditorVariable("rotateSpeed")460SetActiveVariable("rotateSpeed")461462AddEditorVariable("useSpikeball")463SetActiveVariable("useSpikeball")464AddEnumVariable("false", false)465AddEnumVariable("true", true)466467AddEditorVariable("isDynamic")468SetActiveVariable("isDynamic")469AddEnumVariable("false", false)470AddEnumVariable("true", true)471end event472473474