Path: blob/master/Sonic 1/Scripts/MZ/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("MZ/Objects.gif")189SpriteFrame(-8, -8, 16, 16, 76, 160) // connection joint - #0190SpriteFrame(-8, -8, 16, 16, 93, 160) // chain link - #1191SpriteFrame(-24, -8, 48, 16, 69, 177) // platform - #2192193temp0 = 0194SwingPlatform_startDebugID = DebugMode_ObjCount195SwingPlatform_startDebugID--196while temp0 < 8197SetTableValue(TypeName[Swing Platform], DebugMode_ObjCount, DebugMode_TypesTable)198SetTableValue(SwingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)199SetTableValue(SwingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)200DebugMode_ObjCount++201temp0++202loop203end event204205206event RSDKDraw207DrawSprite(0)208209temp0 = 0210temp1 = 16211while temp0 < object.length212Cos(temp2, 128)213temp2 *= temp1214temp2 <<= 7215temp2 += object.xpos216Sin(temp3, 128)217temp3 *= temp1218temp3 <<= 7219temp3 += object.ypos220DrawSpriteXY(1, temp2, temp3)221temp0++222temp1 += 16223loop224225temp1 -= 8226Cos(temp2, 128)227temp2 *= temp1228temp2 <<= 7229temp2 += object.xpos230Sin(temp3, 128)231temp3 *= temp1232temp3 <<= 7233temp3 += object.ypos234DrawSpriteXY(2, temp2, temp3)235236if editor.showGizmos == true237editor.drawingOverlay = true238// Draw the platform's path to the right and left too to show where and how far it'll go239240object.inkEffect = INK_ALPHA241242// Left chains243temp0 = 0244temp1 = 16245while temp0 < object.length246Cos(temp2, 0)247temp2 *= temp1248temp2 <<= 7249temp2 += object.xpos250Sin(temp3, 0)251temp3 *= temp1252temp3 <<= 7253temp3 += object.ypos254DrawSpriteFX(1, FX_INK, temp2, temp3)255temp0++256temp1 += 16257loop258259// Left platform260temp1 -= 8261Cos(temp2, 0)262temp2 *= temp1263temp2 <<= 7264temp2 += object.xpos265Sin(temp3, 0)266temp3 *= temp1267temp3 <<= 7268temp3 += object.ypos269DrawSpriteFX(2, FX_INK, temp2, temp3)270271// Right chains272temp0 = 0273temp1 = 16274while temp0 < object.length275Cos(temp2, 256)276temp2 *= temp1277temp2 <<= 7278temp2 += object.xpos279Sin(temp3, 256)280temp3 *= temp1281temp3 <<= 7282temp3 += object.ypos283DrawSpriteFX(1, FX_INK, temp2, temp3)284temp0++285temp1 += 16286loop287288// Right platform289temp1 -= 8290Cos(temp2, 256)291temp2 *= temp1292temp2 <<= 7293temp2 += object.xpos294Sin(temp3, 256)295temp3 *= temp1296temp3 <<= 7297temp3 += object.ypos298DrawSpriteFX(2, FX_INK, temp2, temp3)299300editor.drawingOverlay = false301end if302end event303304305event RSDKLoad306LoadSpriteSheet("MZ/Objects.gif")307SpriteFrame(-8, -8, 16, 16, 76, 160) // connection joint - #0308SpriteFrame(-8, -8, 16, 16, 93, 160) // chain link - #1309SpriteFrame(-24, -8, 48, 16, 69, 177) // platform - #2310311SetVariableAlias(ALIAS_VAR_PROPVAL, "length")312end event313314315