Path: blob/master/Sonic 2/Scripts/MCZ/SwingPlat.txt
1483 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.value1 : object.drawPos.x14private alias object.value2 : object.drawPos.y15private alias object.value3 : object.collisionOffset.x16private alias object.value4 : object.collisionOffset.y17private alias object.value5 : object.recoilDir18private alias object.value6 : object.collided1920private alias 0 : SWINGPLAT_RECOILDIR_LEFT21private alias 1 : SWINGPLAT_RECOILDIR_RIGHT2223// Player Aliases24private alias object.xpos : player.xpos25private alias object.ypos : player.ypos2627private alias object.value17 : debugMode.currentSelection282930// ========================31// Function Declarations32// ========================3334reserve function SwingPlatform_DebugDraw35reserve function SwingPlatform_DebugSpawn363738// ========================39// Static Values40// ========================4142private value SwingPlatform_startDebugID = 0434445// ========================46// Function Definitions47// ========================4849private function SwingPlatform_DebugDraw5051temp7 = debugMode[0].currentSelection52temp7 -= SwingPlatform_startDebugID5354// Draw the chains55temp0 = 056temp1 = 1657while temp0 < temp758Cos(temp2, 128)59temp2 *= temp160temp2 <<= 761temp2 += object.xpos6263Sin(temp3, 128)64temp3 *= temp165temp3 <<= 766temp3 += object.ypos6768DrawSpriteXY(1, temp2, temp3)6970temp0++71temp1 += 1672loop73temp1 -= 87475Cos(temp2, 128)76temp2 *= temp177temp2 <<= 778temp2 += object.xpos7980Sin(temp3, 128)81temp3 *= temp182temp3 <<= 783temp3 += object.ypos8485// Draw the post86DrawSprite(0)8788// Draw the platform itself89DrawSpriteXY(2, temp2, temp3)90end function919293private function SwingPlatform_DebugSpawn94temp0 = debugMode[0].currentSelection95temp0 -= SwingPlatform_startDebugID96CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)97object[tempObjectPos].recoilDir = object.direction98end function99100101// ========================102// Events103// ========================104105event ObjectUpdate106// Backup the object's position107temp2 = object.xpos108temp3 = object.ypos109110// Oscillate in accordance with the rest of the stage's objects (namely other swinging platforms)111GetTableValue(object.angle, 12, StageSetup_oscillationTable)112object.angle >>= 8113114if object.recoilDir == SWINGPLAT_RECOILDIR_LEFT // As in, is the object is going to bounce back to the left?115if object.angle <= 0x40116object.angle = 0x40117if object.collided == false118object.collided = true119PlaySfx(SfxName[Plat Collide], false)120end if121else122object.collided = false123end if124else125if object.angle >= 0x40126object.angle = 0x40127if object.collided == false128object.collided = true129PlaySfx(SfxName[Plat Collide], false)130end if131else132object.collided = false133end if134end if135136if object.direction == FLIP_X137object.angle ^= 0xFF138object.angle += 0x81139end if140141object.angle <<= 1142143temp1 = object.length144temp1++145temp1 <<= 4146temp1 -= 8147148object.xpos = object.drawPos.x149object.ypos = object.drawPos.y150151Cos(object.collisionOffset.x, object.angle)152object.collisionOffset.x *= temp1153object.collisionOffset.x <<= 7154object.collisionOffset.x += temp2155object.collisionOffset.x &= 0xFFFF0000156object.drawPos.x = object.collisionOffset.x157object.collisionOffset.x -= object.xpos158159Sin(object.collisionOffset.y, object.angle)160object.collisionOffset.y *= temp1161object.collisionOffset.y <<= 7162object.collisionOffset.y += temp3163object.collisionOffset.y &= 0xFFFF0000164object.drawPos.y = object.collisionOffset.y165object.collisionOffset.y -= object.ypos166167foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)168BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)169if checkResult == true170player[currentPlayer].xpos += object.collisionOffset.x171player[currentPlayer].ypos += object.collisionOffset.y172end if173next174175// Restore object position176object.xpos = temp2177object.ypos = temp3178end event179180181event ObjectDraw182// First draw the chains...183temp0 = 0184temp1 = 16185while temp0 < object.length186Cos(temp2, object.angle)187temp2 *= temp1188temp2 <<= 7189temp2 += object.xpos190191Sin(temp3, object.angle)192temp3 *= temp1193temp3 <<= 7194temp3 += object.ypos195196DrawSpriteXY(1, temp2, temp3)197198temp0++199temp1 += 16200loop201temp1 -= 8202203// Then calculate platform position...204Cos(object.drawPos.x, object.angle)205object.drawPos.x *= temp1206object.drawPos.x <<= 7207object.drawPos.x += object.xpos208object.drawPos.x &= 0xFFFF0000209210Sin(object.drawPos.y, object.angle)211object.drawPos.y *= temp1212object.drawPos.y <<= 7213object.drawPos.y += object.ypos214object.drawPos.y &= 0xFFFF0000215216// Then draw the base rock anchor...217DrawSprite(0)218219// And finally draw the platform220DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)221end event222223224event ObjectStartup225LoadSpriteSheet("MCZ/Objects.gif")226SpriteFrame(-12, -12, 23, 33, 152, 131) // 0 - Anchor frame227SpriteFrame( -8, -8, 16, 16, 135, 148) // 1 - Link frame228SpriteFrame(-24, -8, 48, 16, 141, 165) // 2 - Platform frame229230foreach (TypeName[Swing Platform], arrayPos0, ALL_ENTITIES)231if object[arrayPos0].length > 0232object[arrayPos0].length--233end if234235object[arrayPos0].collided = true236237// Get the fourth bit of the property/length value238object[arrayPos0].recoilDir = object[arrayPos0].length239object[arrayPos0].recoilDir >>= 3240object[arrayPos0].recoilDir &= 1241242// Limit max chain length to 7243object[arrayPos0].length &= 7244object[arrayPos0].length++245next246247// Add this object to the debug mode object list a few times for the different chain lengths248temp0 = 0249SwingPlatform_startDebugID = DebugMode_ObjCount250SwingPlatform_startDebugID--251while temp0 < 8252SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)253SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)254SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)255DebugMode_ObjCount++256temp0++257loop258end event259260261// ========================262// Editor Events263// ========================264265event RSDKEdit266if editor.returnVariable == true267switch editor.variableID268case EDIT_VAR_PROPVAL // property value269checkResult = object.propertyValue270break271272case 0 // length273checkResult = object.propertyValue274checkResult &= 7275break276277case 1 // swingDir278GetBit(checkResult, object.propertyValue, 4)279break280281end switch282else283switch editor.variableID284case EDIT_VAR_PROPVAL // property value285object.propertyValue = editor.variableValue286break287288case 0 // length289temp0 = 7290Not(temp0)291object.propertyValue &= temp0292editor.variableValue &= 7293294object.propertyValue |= editor.variableValue295break296297case 1 // swingDir298CheckNotEqual(editor.variableValue, 0)299SetBit(object.propertyValue, 4, checkResult)300break301302end switch303end if304end event305306307event RSDKDraw308temp7 = object.propertyValue309if temp7 > 0310temp7--311end if312temp7 &= 7313temp7++314315// Draw the chains316temp0 = 0317temp1 = 16318while temp0 < temp7319Cos(temp2, 128)320temp2 *= temp1321temp2 <<= 7322temp2 += object.xpos323324Sin(temp3, 128)325temp3 *= temp1326temp3 <<= 7327temp3 += object.ypos328329DrawSpriteXY(1, temp2, temp3)330331temp0++332temp1 += 16333loop334temp1 -= 8335336Cos(temp2, 128)337temp2 *= temp1338temp2 <<= 7339temp2 += object.xpos340341Sin(temp3, 128)342temp3 *= temp1343temp3 <<= 7344temp3 += object.ypos345346// Draw the post347DrawSprite(0)348349// Draw the platform itself350DrawSpriteXY(2, temp2, temp3)351end event352353354event RSDKLoad355LoadSpriteSheet("MCZ/Objects.gif")356SpriteFrame(-12, -12, 23, 33, 152, 131) // 0 - Anchor frame357SpriteFrame( -8, -8, 16, 16, 135, 148) // 1 - Link frame358SpriteFrame(-24, -8, 48, 16, 141, 165) // 2 - Platform frame359360AddEditorVariable("length")361SetActiveVariable("length")362363AddEditorVariable("swingDir")364SetActiveVariable("swingDir")365AddEnumVariable("Left", SWINGPLAT_RECOILDIR_LEFT)366AddEnumVariable("Right", SWINGPLAT_RECOILDIR_RIGHT)367end event368369370