Path: blob/master/Sonic 2/Scripts/OOZ/SwingPlat.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Swing Platform Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.propertyValue : object.length1213private alias object.value0 : object.swingAngle14private 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.value45 : object.canSnap1920// States21private alias 0 : SWINGPLAT_SWING22private alias 1 : SWINGPLAT_SNAPPED23private alias 2 : SWINGPLAT_FLOATING2425// Player Aliases26private alias object.xpos : player.xpos27private alias object.ypos : player.ypos2829private alias object.value17 : debugMode.currentSelection303132// ========================33// Function Declarations34// ========================3536reserve function SwingPlatform_DebugDraw37reserve function SwingPlatform_DebugSpawn383940// ========================41// Static Values42// ========================4344private value SwingPlatform_startDebugID = 0454647// ========================48// Function Definitions49// ========================5051private function SwingPlatform_DebugDraw52temp7 = debugMode[0].currentSelection53temp7 -= SwingPlatform_startDebugID5455// Draw the post56DrawSprite(0)5758// Draw the chains59temp0 = 060temp1 = 1661while temp0 < temp762Cos(temp2, 128)63temp2 *= temp164temp2 <<= 765temp2 += object.xpos66Sin(temp3, 128)6768temp3 *= temp169temp3 <<= 770temp3 += object.ypos7172DrawSpriteXY(1, temp2, temp3)73temp0++74temp1 += 1675loop7677// Draw the platform itself78temp1 -= 879Cos(temp2, 128)8081temp2 *= temp182temp2 <<= 783temp2 += object.xpos84Sin(temp3, 128)8586temp3 *= temp187temp3 <<= 788temp3 += object.ypos8990DrawSpriteXY(2, temp2, temp3)91end function929394private function SwingPlatform_DebugSpawn95temp0 = debugMode[0].currentSelection96temp0 -= SwingPlatform_startDebugID97CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)98object[tempObjectPos].direction = object.direction99end function100101102// ========================103// Events104// ========================105106event ObjectUpdate107temp2 = object.xpos108temp3 = object.ypos109110GetTableValue(object.angle, 12, StageSetup_oscillationTable)111object.angle >>= 8112if object.direction == FLIP_X113object.angle ^= 0xFF114object.angle += 0x81115end if116object.angle <<= 1117118temp1 = object.length119temp1++120temp1 <<= 4121temp1 -= 8122object.xpos = object.drawPos.x123object.ypos = object.drawPos.y124125switch object.state126case SWINGPLAT_SWING127Cos(object.xpos, object.angle)128object.xpos *= temp1129object.xpos <<= 7130object.xpos += temp2131132Sin(object.ypos, object.angle)133object.ypos *= temp1134object.ypos <<= 7135object.ypos += temp3136break137138case SWINGPLAT_SNAPPED139object.ypos += object.yvel140object.yvel += 0x3000141temp7 = 1824 // Y level of oil in the level142temp7 <<= 16143if object.ypos >= temp7144object.state++145end if146object.xpos += object.xvel147break148149case SWINGPLAT_FLOATING150Sin(object.ypos, object.swingAngle)151object.swingAngle += 6152object.swingAngle &= 0x1FF153object.ypos >>= 7154object.ypos += 1824155object.ypos <<= 16156break157158end switch159160object.collisionOffset.x = object.xpos161object.collisionOffset.x &= 0xFFFF0000162temp4 = object.drawPos.x163temp4 &= 0xFFFF0000164object.collisionOffset.x -= temp4165166object.collisionOffset.y = object.ypos167object.collisionOffset.y &= 0xFFFF0000168temp5 = object.drawPos.y169temp5 &= 0xFFFF0000170object.collisionOffset.y -= temp5171172object.drawPos.x = object.xpos173object.drawPos.y = object.ypos174175object.xpos = temp4176object.ypos = temp5177foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)178BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)179if checkResult == true180if object.state == SWINGPLAT_SWING181if object.canSnap == true182if object.angle == 0x000183object.xvel = 0x20000184object.priority = PRIORITY_ACTIVE185object.state = SWINGPLAT_SNAPPED186end if187188if object.angle == 0x100189object.xvel = -0x20000190object.priority = PRIORITY_ACTIVE191object.state = SWINGPLAT_SNAPPED192end if193end if194end if195player[currentPlayer].xpos += object.collisionOffset.x196player[currentPlayer].ypos += object.collisionOffset.y197end if198next199200if object.state > 0201if object.outOfBounds == true202object.xpos = temp2203object.ypos = temp3204if object.outOfBounds == true205object.state = SWINGPLAT_SWING206object.priority = PRIORITY_BOUNDS207object.xvel = 0208object.yvel = 0209end if210end if211end if212object.xpos = temp2213object.ypos = temp3214end event215216217event ObjectDraw218temp0 = 0219temp1 = 16220while temp0 < object.length221Cos(temp2, object.angle)222temp2 *= temp1223temp2 <<= 7224temp2 += object.xpos225226Sin(temp3, object.angle)227temp3 *= temp1228temp3 <<= 7229temp3 += object.ypos230231DrawSpriteXY(1, temp2, temp3)232temp0++233temp1 += 16234loop235temp1 -= 8236237DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)238DrawSprite(0)239end event240241242event ObjectStartup243LoadSpriteSheet("OOZ/Objects.gif")244SpriteFrame(-8, -8, 16, 16, 51, 75)245SpriteFrame(-8, -8, 16, 16, 51, 75)246SpriteFrame(-32, -8, 64, 32, 68, 75)247248foreach (TypeName[Swing Platform], arrayPos0, ALL_ENTITIES)249GetBit(object[arrayPos0].canSnap, object[arrayPos0].propertyValue, 7)250object[arrayPos0].length &= 0x7F251next252253temp0 = 0254SwingPlatform_startDebugID = DebugMode_ObjCount255SwingPlatform_startDebugID--256while temp0 < 8257SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)258SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)259SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)260DebugMode_ObjCount++261temp0++262loop263end event264265266// ========================267// Editor Events268// ========================269270event RSDKEdit271if editor.returnVariable == true272switch editor.variableID273case EDIT_VAR_PROPVAL // property value274checkResult = object.propertyValue275break276277case 0 // length278checkResult = object.propertyValue279checkResult &= 0x7F280break281282case 1 // canSnap283GetBit(checkResult, object.propertyValue, 7)284break285286end switch287else288switch editor.variableID289case EDIT_VAR_PROPVAL // property value290object.propertyValue = editor.variableValue291break292293case 0 // length294editor.variableValue &= 0x7F295object.propertyValue &= 0x80296297object.propertyValue |= editor.variableValue298break299300case 1 // canSnap301CheckNotEqual(editor.variableValue, false)302SetBit(object.propertyValue, 7, checkResult)303break304305end switch306end if307end event308309310event RSDKDraw311temp7 = object.propertyValue312temp7 &= 0x7F313314DrawSprite(0)315316temp0 = 0317temp1 = 16318while temp0 < temp7319Cos(temp2, 128)320temp2 *= temp1321temp2 <<= 7322temp2 += object.xpos323324Sin(temp3, 128)325temp3 *= temp1326temp3 <<= 7327temp3 += object.ypos328329DrawSpriteXY(1, temp2, temp3)330temp0++331temp1 += 16332loop333temp1 -= 8334335Cos(temp2, 128)336temp2 *= temp1337temp2 <<= 7338temp2 += object.xpos339340Sin(temp3, 128)341temp3 *= temp1342temp3 <<= 7343temp3 += object.ypos344345DrawSpriteXY(2, temp2, temp3)346347if editor.showGizmos == true348editor.drawingOverlay = true349350object.inkEffect = INK_BLEND351352// Draw right side353temp0 = 0354temp1 = 16355while temp0 < temp7356Cos(temp2, 0)357temp2 *= temp1358temp2 <<= 7359temp2 += object.xpos360361Sin(temp3, 0)362temp3 *= temp1363temp3 <<= 7364temp3 += object.ypos365366DrawSpriteFX(1, FX_INK, temp2, temp3)367temp0++368temp1 += 16369loop370temp1 -= 8371372Cos(temp2, 0)373temp2 *= temp1374temp2 <<= 7375temp2 += object.xpos376377Sin(temp3, 0)378temp3 *= temp1379temp3 <<= 7380temp3 += object.ypos381382DrawSpriteFX(2, FX_INK, temp2, temp3)383384// Draw left side385temp0 = 0386temp1 = 16387while temp0 < temp7388Cos(temp2, 256)389temp2 *= temp1390temp2 <<= 7391temp2 += object.xpos392393Sin(temp3, 256)394temp3 *= temp1395temp3 <<= 7396temp3 += object.ypos397398DrawSpriteFX(1, FX_INK, temp2, temp3)399temp0++400temp1 += 16401loop402temp1 -= 8403404Cos(temp2, 256)405temp2 *= temp1406temp2 <<= 7407temp2 += object.xpos408409Sin(temp3, 256)410temp3 *= temp1411temp3 <<= 7412temp3 += object.ypos413414DrawSpriteFX(2, FX_INK, temp2, temp3)415416editor.drawingOverlay = false417end if418end event419420421event RSDKLoad422LoadSpriteSheet("OOZ/Objects.gif")423SpriteFrame(-8, -8, 16, 16, 51, 75)424SpriteFrame(-8, -8, 16, 16, 51, 75)425SpriteFrame(-32, -8, 64, 32, 68, 75)426427AddEditorVariable("length")428SetActiveVariable("length")429430AddEditorVariable("canSnap")431SetActiveVariable("canSnap")432AddEnumVariable("false", false)433AddEnumVariable("true", true)434end event435436437