Path: blob/master/Sonic 1/Scripts/GHZ/SwingPlat.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// 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.y1819// Player Aliases20private alias object.xpos : player.xpos21private alias object.ypos : player.ypos2223private alias object.value17 : debugMode.currentSelection242526// ========================27// Function Declarations28// ========================2930reserve function SwingPlatform_DebugDraw31reserve function SwingPlatform_DebugSpawn323334// ========================35// Static Values36// ========================3738private value SwingPlatform_startDebugID = 0394041// ========================42// Function Definitions43// ========================4445private function SwingPlatform_DebugDraw46temp7 = debugMode[0].currentSelection47temp7 -= SwingPlatform_startDebugID4849// Draw the post50DrawSprite(0)5152// Draw the chains53temp0 = 054temp1 = 1655while temp0 < temp756Cos(temp2, 128)57temp2 *= temp158temp2 <<= 759temp2 += object.xpos60Sin(temp3, 128)61temp3 *= temp162temp3 <<= 763temp3 += object.ypos64DrawSpriteXY(1, temp2, temp3)65temp0++66temp1 += 1667loop6869// Draw the platform itself70temp1 -= 871Cos(temp2, 128)72temp2 *= temp173temp2 <<= 774temp2 += object.xpos7576Sin(temp3, 128)77temp3 *= temp178temp3 <<= 779temp3 += object.ypos8081DrawSpriteXY(2, temp2, temp3)82end function838485private function SwingPlatform_DebugSpawn86temp0 = debugMode[0].currentSelection87temp0 -= SwingPlatform_startDebugID8889CreateTempObject(TypeName[Swing Platform], temp0, object.xpos, object.ypos)90object[tempObjectPos].direction = object.direction91end function929394// ========================95// Events96// ========================9798event ObjectUpdate99// Backup the object's position, as it'll need to be moved for collision checks100temp2 = object.xpos101temp3 = object.ypos102103GetTableValue(object.swingAngle, 12, StageSetup_oscillationTable)104object.swingAngle >>= 8105if object.direction == FLIP_X106object.swingAngle ^= 255107object.swingAngle += 129108end if109object.swingAngle <<= 1110111temp1 = object.length112temp1++113temp1 <<= 4114temp1 -= 8115object.xpos = object.drawPos.x116object.ypos = object.drawPos.y117118Cos(object.collisionOffset.x, object.swingAngle)119object.collisionOffset.x *= temp1120object.collisionOffset.x <<= 7121object.collisionOffset.x += temp2122object.collisionOffset.x &= 0xFFFF0000123object.drawPos.x = object.collisionOffset.x124object.collisionOffset.x -= object.xpos125126Sin(object.collisionOffset.y, object.swingAngle)127object.collisionOffset.y *= temp1128object.collisionOffset.y <<= 7129object.collisionOffset.y += temp3130object.collisionOffset.y &= 0xFFFF0000131object.drawPos.y = object.collisionOffset.y132object.collisionOffset.y -= object.ypos133134foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)135BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)136if checkResult == true137player[currentPlayer].xpos += object.collisionOffset.x138player[currentPlayer].ypos += object.collisionOffset.y139end if140next141142// Move the object back to its actual position143object.xpos = temp2144object.ypos = temp3145end event146147148event ObjectDraw149// Draw the post150DrawSprite(0)151152// Draw the chains153temp0 = 0154temp1 = 16155while temp0 < object.length156Cos(temp2, object.swingAngle)157temp2 *= temp1158temp2 <<= 7159temp2 += object.xpos160Sin(temp3, object.swingAngle)161temp3 *= temp1162temp3 <<= 7163temp3 += object.ypos164DrawSpriteXY(1, temp2, temp3)165temp0++166temp1 += 16167loop168169// Draw the platform itself170temp1 -= 8171Cos(object.drawPos.x, object.swingAngle)172object.drawPos.x *= temp1173object.drawPos.x <<= 7174object.drawPos.x += object.xpos175object.drawPos.x &= 0xFFFF0000176177Sin(object.drawPos.y, object.swingAngle)178object.drawPos.y *= temp1179object.drawPos.y <<= 7180object.drawPos.y += object.ypos181object.drawPos.y &= 0xFFFF0000182183DrawSpriteXY(2, object.drawPos.x, object.drawPos.y)184end event185186187event ObjectStartup188LoadSpriteSheet("GHZ/Objects.gif")189190// Swinging Platform frames191SpriteFrame(-8, -8, 16, 16, 84, 1) // connection joint - #0192SpriteFrame(-8, -8, 16, 16, 101, 1) // chain link - #1193SpriteFrame(-24, -8, 48, 16, 118, 1) // platform - #2194195// Add this object to the debug mode item list 8 times, for 8 different lengths196// All entries have different lengths197temp0 = 0198SwingPlatform_startDebugID = DebugMode_ObjCount199SwingPlatform_startDebugID--200while temp0 < 8201SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)202SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)203SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)204DebugMode_ObjCount++205temp0++206loop207end event208209210// ========================211// Editor Events212// ========================213214event RSDKEdit215if editor.returnVariable == true216switch editor.variableID217case EDIT_VAR_PROPVAL // property value218checkResult = object.propertyValue219break220221case 0 // startDir222checkResult = object.direction223break224225end switch226else227switch editor.variableID228case EDIT_VAR_PROPVAL // property value229object.propertyValue = editor.variableValue230break231232case 0 // startDir233object.direction = editor.variableValue234break235236end switch237end if238end event239240241event RSDKDraw242// Draw the post243DrawSprite(0)244245// Draw the chains246temp0 = 0247temp1 = 16248while temp0 < object.length249Cos(temp2, 128)250temp2 *= temp1251temp2 <<= 7252temp2 += object.xpos253Sin(temp3, 128)254temp3 *= temp1255temp3 <<= 7256temp3 += object.ypos257DrawSpriteXY(1, temp2, temp3)258temp0++259temp1 += 16260loop261262// Draw the platform itself263temp1 -= 8264Cos(temp2, 128)265temp2 *= temp1266temp2 <<= 7267temp2 += object.xpos268Sin(temp3, 128)269temp3 *= temp1270temp3 <<= 7271temp3 += object.ypos272DrawSpriteXY(2, temp2, temp3)273274if editor.showGizmos == true275editor.drawingOverlay = true276277#platform: DUMMY278// Draw the platform's arc of movement rather than its end points279// TODO: Is this too much? It doesn't even work right...280281temp1 += 8282temp0 = 1283while temp0 < 255284Cos(object.drawPos.x, temp0)285object.drawPos.x *= temp1286object.drawPos.x <<= 7287object.drawPos.x += object.xpos288object.drawPos.x &= 0xFFFF0000289290Sin(object.drawPos.y, temp0)291object.drawPos.y *= temp1292object.drawPos.y <<= 7293object.drawPos.y += object.ypos294object.drawPos.y &= 0xFFFF0000295296DrawRectWorld(object.drawPos.x, object.drawPos.y, 1, 1, 255, 255, 255, 255)297298temp0++299loop300#endplatform301302// Draw the platform's path to the right and left too to show where and how far it'll go303object.inkEffect = INK_BLEND304305// Left chains306temp0 = 0307temp1 = 16308while temp0 < object.length309Cos(temp2, 0)310temp2 *= temp1311temp2 <<= 7312temp2 += object.xpos313Sin(temp3, 0)314temp3 *= temp1315temp3 <<= 7316temp3 += object.ypos317DrawSpriteFX(1, FX_INK, temp2, temp3)318temp0++319temp1 += 16320loop321322// Left platform323temp1 -= 8324Cos(temp2, 0)325temp2 *= temp1326temp2 <<= 7327temp2 += object.xpos328Sin(temp3, 0)329temp3 *= temp1330temp3 <<= 7331temp3 += object.ypos332DrawSpriteFX(2, FX_INK, temp2, temp3)333334// Right chains335temp0 = 0336temp1 = 16337while temp0 < object.length338Cos(temp2, 256)339temp2 *= temp1340temp2 <<= 7341temp2 += object.xpos342Sin(temp3, 256)343temp3 *= temp1344temp3 <<= 7345temp3 += object.ypos346DrawSpriteFX(1, FX_INK, temp2, temp3)347temp0++348temp1 += 16349loop350351// Right platform352temp1 -= 8353Cos(temp2, 256)354temp2 *= temp1355temp2 <<= 7356temp2 += object.xpos357Sin(temp3, 256)358temp3 *= temp1359temp3 <<= 7360temp3 += object.ypos361DrawSpriteFX(2, FX_INK, temp2, temp3)362363editor.drawingOverlay = false364end if365end event366367368event RSDKLoad369LoadSpriteSheet("GHZ/Objects.gif")370SpriteFrame(-8, -8, 16, 16, 84, 1) // connection joint - #0371SpriteFrame(-8, -8, 16, 16, 101, 1) // chain link - #1372SpriteFrame(-24, -8, 48, 16, 118, 1) // platform - #2373374AddEditorVariable("startDir")375SetActiveVariable("startDir")376AddEnumVariable("Left", 0)377AddEnumVariable("Right", 1)378379SetVariableAlias(ALIAS_VAR_PROPVAL, "length")380381// TODO: origins mission m006 uses state attr, for something?382end event383384385