Path: blob/master/Sonic 2/Scripts/ARZ/SwingPlat.txt
1482 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.currentSelection3031// Path ID Aliases32private alias 0 : PATH_A333435// ========================36// Function Declarations37// ========================3839reserve function SwingPlatform_DebugDraw40reserve function SwingPlatform_DebugSpawn414243// ========================44// Static Values45// ========================4647private value SwingPlatform_startDebugID = 0484950// ========================51// Function Definitions52// ========================5354private function SwingPlatform_DebugDraw55temp7 = debugMode[0].currentSelection56temp7 -= SwingPlatform_startDebugID57DrawSprite(0)5859temp0 = 060temp1 = 1661while temp0 < temp762Cos(temp2, 128)63temp2 *= temp164temp2 <<= 765temp2 += object.xpos66Sin(temp3, 128)67temp3 *= temp168temp3 <<= 769temp3 += object.ypos70DrawSpriteXY(1, temp2, temp3)71temp0++72temp1 += 1673loop74temp1 -= 87576Cos(temp2, 128)77temp2 *= temp178temp2 <<= 779temp2 += object.xpos8081Sin(temp3, 128)82temp3 *= temp183temp3 <<= 784temp3 += object.ypos8586DrawSpriteXY(2, temp2, temp3)87end function888990private function SwingPlatform_DebugSpawn91temp0 = debugMode[0].currentSelection92temp0 -= SwingPlatform_startDebugID93CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)94object[tempObjectPos].direction = object.direction95end function969798// ========================99// Events100// ========================101102event ObjectUpdate103temp2 = object.xpos104temp3 = object.ypos105GetTableValue(object.swingAngle, 12, StageSetup_oscillationTable)106object.swingAngle >>= 8107if object.direction == FLIP_X108object.swingAngle ^= 255109object.swingAngle += 129110end if111object.swingAngle <<= 1112113temp1 = object.length114temp1++115temp1 <<= 4116temp1 -= 8117object.xpos = object.drawPos.x118object.ypos = object.drawPos.y119120switch object.state121case SWINGPLAT_SWING122Cos(object.xpos, object.swingAngle)123object.xpos *= temp1124object.xpos <<= 7125object.xpos += temp2126127Sin(object.ypos, object.swingAngle)128object.ypos *= temp1129object.ypos <<= 7130object.ypos += temp3131break132133case SWINGPLAT_SNAPPED134object.ypos += object.yvel135object.yvel += 0x1800136temp7 = stage.waterLevel137temp7 <<= 16138if object.ypos >= temp7139object.xvel = 0x10000140object.state++141end if142object.xpos += object.xvel143break144145case SWINGPLAT_FLOATING146object.ypos = stage.waterLevel147object.ypos <<= 16148object.xpos += object.xvel149if object.direction == FLIP_NONE150ObjectTileCollision(CSIDE_LWALL, 32, 12, PATH_A)151else152ObjectTileCollision(CSIDE_RWALL, -32, 12, PATH_A)153end if154break155156end switch157158object.collisionOffset.x = object.xpos159object.collisionOffset.x &= 0xFFFF0000160temp4 = object.drawPos.x161temp4 &= 0xFFFF0000162object.collisionOffset.x -= temp4163164object.collisionOffset.y = object.ypos165object.collisionOffset.y &= 0xFFFF0000166temp5 = object.drawPos.y167temp5 &= 0xFFFF0000168object.collisionOffset.y -= temp5169170object.drawPos.x = object.xpos171object.drawPos.y = object.ypos172173object.xpos = temp4174object.ypos = temp5175foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)176BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)177if checkResult == true178if object.state == SWINGPLAT_SWING179if object.canSnap == true180if object.direction == FLIP_NONE181if object.swingAngle == 0x00182object.xvel = 0x20000183object.priority = PRIORITY_ACTIVE184object.state = SWINGPLAT_SNAPPED185end if186else187// Bug Details:188// -> An inverted platform's range is 0x200 to 0x300, so this never hits..189// -> If the goal was to make it snap when it's on the left, then you'd want to use a 0x300 here190if object.swingAngle == 0x100191object.xvel = -0x20000192object.priority = PRIORITY_ACTIVE193object.state = SWINGPLAT_SNAPPED194end if195end if196end if197end if198player[currentPlayer].xpos += object.collisionOffset.x199player[currentPlayer].ypos += object.collisionOffset.y200end if201next202203if object.state > SWINGPLAT_SNAPPED204if object.outOfBounds == true205object.xpos = temp2206object.ypos = temp3207if object.outOfBounds == true208object.state = SWINGPLAT_SWING209object.priority = PRIORITY_BOUNDS210object.xvel = 0211object.yvel = 0212end if213end if214end if215object.xpos = temp2216object.ypos = temp3217end event218219220event ObjectDraw221temp0 = 0222temp1 = 16223while temp0 < object.length224Cos(temp2, object.swingAngle)225temp2 *= temp1226temp2 <<= 7227temp2 += object.xpos228229Sin(temp3, object.swingAngle)230temp3 *= temp1231temp3 <<= 7232temp3 += object.ypos233234DrawSpriteXY(1, temp2, temp3)235236temp0++237temp1 += 16238loop239temp1 -= 8240241DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)242DrawSprite(0)243end event244245246event ObjectStartup247LoadSpriteSheet("ARZ/Objects.gif")248SpriteFrame(-15, -12, 30, 20, 160, 235)249SpriteFrame(-8, -8, 16, 16, 174, 218)250SpriteFrame(-32, -8, 64, 16, 126, 191)251252foreach (TypeName[Swing Platform], arrayPos0, ALL_ENTITIES)253GetBit(object[arrayPos0].canSnap, object[arrayPos0].length, 7)254object[arrayPos0].length &= 0x7F255next256257temp0 = 0258SwingPlatform_startDebugID = DebugMode_ObjCount259SwingPlatform_startDebugID--260while temp0 < 8261SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)262SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)263SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)264DebugMode_ObjCount++265temp0++266loop267end event268269270// ========================271// Editor Events272// ========================273274event RSDKEdit275if editor.returnVariable == true276switch editor.variableID277case EDIT_VAR_PROPVAL // property value278checkResult = object.propertyValue279break280281case 0 // length282checkResult = object.propertyValue283checkResult &= 0x7F284break285286case 1 // canSnap287GetBit(checkResult, object.propertyValue, 7)288break289end switch290else291switch editor.variableID292case EDIT_VAR_PROPVAL // property value293object.propertyValue = editor.variableValue294break295296case 0 // length297editor.variableValue &= 0x7F298object.propertyValue &= 0x80299300object.propertyValue |= editor.variableValue301break302303case 1 // canSnap304CheckNotEqual(editor.variableValue, false)305SetBit(object.propertyValue, 7, checkResult)306break307end switch308end if309end event310311312event RSDKDraw313temp7 = object.propertyValue314temp7 &= 0x7F315316DrawSprite(0)317318temp0 = 0319temp1 = 16320while temp0 < temp7321Cos(temp2, 128)322temp2 *= temp1323temp2 <<= 7324temp2 += object.xpos325326Sin(temp3, 128)327temp3 *= temp1328temp3 <<= 7329temp3 += object.ypos330331DrawSpriteXY(1, temp2, temp3)332temp0++333temp1 += 16334loop335temp1 -= 8336337Cos(temp2, 128)338temp2 *= temp1339temp2 <<= 7340temp2 += object.xpos341342Sin(temp3, 128)343temp3 *= temp1344temp3 <<= 7345temp3 += object.ypos346347DrawSpriteXY(2, temp2, temp3)348end event349350351event RSDKLoad352LoadSpriteSheet("ARZ/Objects.gif")353SpriteFrame(-15, -12, 30, 20, 160, 235)354SpriteFrame(-8, -8, 16, 16, 174, 218)355SpriteFrame(-32, -8, 64, 16, 126, 191)356357AddEditorVariable("length")358SetActiveVariable("length")359360AddEditorVariable("canSnap")361SetActiveVariable("canSnap")362AddEnumVariable("false", false)363AddEnumVariable("true", true)364end event365366367