Path: blob/master/Sonic 1/Scripts/MZ/ChainedCrusher.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Chained Crusher Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.timer12private alias object.value1 : object.crusherType13private alias object.value2 : object.useButton14private alias object.value3 : object.startPos.y15private alias object.value4 : object.endPos.y16private alias object.value5 : object.collisionOffset.y17private alias object.value6 : object.currentPos.y18private alias object.value7 : object.dontPlaySfx // set by Push Block objects1920private alias 0 : CHAINCRUSHER_DROPPING21private alias 1 : CHAINCRUSHER_DROPPED22private alias 2 : CHAINCRUSHER_RISING23private alias 3 : CHAINCRUSHER_RISEN24private alias 4 : CHAINCRUSHER_DROPWHENACTIVE2526private alias 0 : CHAINCRUSHER_TYPE_LARGE27private alias 1 : CHAINCRUSHER_TYPE_MED28private alias 2 : CHAINCRUSHER_TYPE_SMALL29private alias 3 : CHAINCRUSHER_TYPE_SMALL_ACTIVE3031// Player Aliases32private alias object.ypos : player.ypos33private alias object.gravity : player.gravity3435// Debug Mode Aliases36private alias object.value17 : debugMode.currentSelection3738// PushButton aliases39private alias object.propertyValue : pushButton.stood404142// ========================43// Function Declarations44// ========================4546reserve function ChainedCrusher_DebugDraw47reserve function ChainedCrusher_DebugSpawn48reserve function ChainedCrusher_CheckOnScreen495051// ========================52// Static Values53// ========================5455private value ChainedCrusher_startDebugID = 0565758// ========================59// Function Definitions60// ========================6162private function ChainedCrusher_DebugDraw63temp7 = debugMode[0].currentSelection64temp7 -= ChainedCrusher_startDebugID65temp6 = temp766temp6 /= 767temp7 %= 768temp5 = object.ypos69switch temp770case 071temp5 += 0x70000072break7374case 175temp5 += 0xA0000076break7778case 279temp5 += 0x50000080break8182case 383temp5 += 0x78000084break8586case 487temp5 += 0x38000088break8990case 591temp5 += 0x58000092break9394case 695temp5 += 0xB8000096break97end switch9899temp0 = temp5100temp0 -= object.ypos101temp0 >>= 16102temp0 += 4103temp1 = 257104temp1 -= temp0105temp2 = temp0106temp2 += 18107FlipSign(temp2)108EditFrame(5, -4, temp2, 8, temp0, 308, temp1)109DrawSpriteXY(5, object.xpos, temp5)110DrawSpriteXY(0, object.xpos, object.ypos)111switch temp6112case 0113DrawSpriteXY(1, object.xpos, temp5)114DrawSpriteXY(4, object.xpos, temp5)115break116117case 1118DrawSpriteXY(2, object.xpos, temp5)119DrawSpriteXY(4, object.xpos, temp5)120break121122case 2123case 3124DrawSpriteXY(3, object.xpos, temp5)125break126end switch127end function128129130private function ChainedCrusher_DebugSpawn131temp7 = debugMode[0].currentSelection132temp7 -= ChainedCrusher_startDebugID133134temp6 = temp7135temp6 /= 7136temp7 %= 7137CreateTempObject(TypeName[Chained Crusher], 0, object.xpos, object.ypos)138object[tempObjectPos].useButton = false139object[tempObjectPos].crusherType = temp6140if object[tempObjectPos].crusherType == CHAINCRUSHER_TYPE_SMALL141object[tempObjectPos].state = CHAINCRUSHER_DROPWHENACTIVE142end if143144object[tempObjectPos].startPos.y = object.ypos145object[tempObjectPos].endPos.y = object[tempObjectPos].startPos.y146switch temp7147case 0148object[tempObjectPos].endPos.y += 0x700000149break150151case 1152object[tempObjectPos].endPos.y += 0xA00000153break154155case 2156object[tempObjectPos].endPos.y += 0x500000157break158159case 3160object[tempObjectPos].endPos.y += 0x780000161break162163case 4164object[tempObjectPos].endPos.y += 0x380000165break166167case 5168object[tempObjectPos].endPos.y += 0x580000169break170171case 6172object[tempObjectPos].endPos.y += 0xB80000173break174175end switch176end function177178179private function ChainedCrusher_CheckOnScreen180checkResult = false181temp0 = object.xpos182temp0 >>= 16183temp0 -= camera[0].xpos184Abs(temp0)185switch object.crusherType186case CHAINCRUSHER_TYPE_LARGE187temp0 -= 64188break189190case CHAINCRUSHER_TYPE_MED191temp0 -= 56192break193194case CHAINCRUSHER_TYPE_SMALL195temp0 -= 0 // sure196break197198case CHAINCRUSHER_TYPE_SMALL_ACTIVE199temp0 -= 24200break201end switch202203if temp0 <= screen.xcenter204temp1 = object.endPos.y205temp1 -= object.startPos.y206temp1 >>= 16207temp1 += 8208temp1 >>= 1209210temp0 = object.startPos.y211temp0 += object.endPos.y212temp0 >>= 17213temp0 -= 12214temp0 -= camera[0].ypos215Abs(temp0)216217temp0 -= temp1218temp0 -= 40219if temp0 <= screen.ycenter220checkResult = true221end if222end if223end function224225226// ========================227// Events228// ========================229230event ObjectUpdate231object.priority = PRIORITY_ACTIVE232233if object.useButton == true234if pushButton[+1].stood == false235object.dontPlaySfx = false236object.yvel += 0x7000237object.ypos += object.yvel238if object.ypos >= object.endPos.y239if object.yvel > 0x7000240CallFunction(ChainedCrusher_CheckOnScreen)241if checkResult == true242PlaySfx(SfxName[Crusher], false)243end if244end if245object.ypos = object.endPos.y246object.yvel = 0247end if248else249object.yvel = -0x8000250object.ypos += object.yvel251if object.ypos <= object.startPos.y252object.ypos = object.startPos.y253object.yvel = 0254else255if object.dontPlaySfx == false256temp0 = oscillation257temp0 &= 15258if temp0 == 0259CallFunction(ChainedCrusher_CheckOnScreen)260if checkResult == true261PlaySfx(SfxName[Chain Pull], false)262end if263end if264end if265end if266end if267else268switch object.state269case CHAINCRUSHER_DROPPING270object.dontPlaySfx = false271object.yvel += 0x7000272object.ypos += object.yvel273if object.ypos >= object.endPos.y274if object.yvel > 0x7000275CallFunction(ChainedCrusher_CheckOnScreen)276if checkResult == true277PlaySfx(SfxName[Crusher], false)278end if279end if280object.ypos = object.endPos.y281object.yvel = 0282object.state++283end if284break285286case CHAINCRUSHER_DROPPED287object.timer++288if object.timer == 60289object.timer = 0290object.yvel = -0x8000291object.state++292end if293break294295case CHAINCRUSHER_RISING296object.ypos += object.yvel297if object.ypos <= object.startPos.y298object.ypos = object.startPos.y299object.yvel = 0300object.state++301else302if object.dontPlaySfx == false303temp0 = oscillation304temp0 &= 15305if temp0 == 0306CallFunction(ChainedCrusher_CheckOnScreen)307if checkResult == true308PlaySfx(SfxName[Chain Pull], false)309end if310end if311end if312end if313break314315case CHAINCRUSHER_RISEN316object.timer++317if object.timer == 4318object.timer = 0319object.state = CHAINCRUSHER_DROPPING320end if321break322323case CHAINCRUSHER_DROPWHENACTIVE324CallFunction(ChainedCrusher_CheckOnScreen)325if checkResult == true326object.state = CHAINCRUSHER_DROPPING327object.crusherType++328end if329break330end switch331end if332333object.collisionOffset.y = object.ypos334object.collisionOffset.y &= 0xFFFF0000335object.collisionOffset.y -= object.currentPos.y336337temp0 = object.ypos338object.ypos = object.currentPos.y339foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)340switch object.crusherType341case CHAINCRUSHER_TYPE_LARGE342BoxCollisionTest(C_SOLID, object.entityPos, -56, -12, 56, 10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)343switch checkResult344case COL_NONE345BoxCollisionTest(C_TOUCH, object.entityPos, -48, 12, 48, 36, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)346if checkResult == true347CallFunction(Player_Hit)348end if349break350351case COL_TOP352player[currentPlayer].ypos += object.collisionOffset.y353break354355case COL_BOTTOM356if player[currentPlayer].gravity == GRAVITY_GROUND357if object.collisionOffset.y >= 0358CallFunction(Player_Kill)359end if360end if361break362end switch363break364365case CHAINCRUSHER_TYPE_MED366BoxCollisionTest(C_SOLID, object.entityPos, -48, -12, 48, 10, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)367switch checkResult368case COL_NONE369BoxCollisionTest(C_TOUCH, object.entityPos, -47, 12, 47, 36, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)370if checkResult == true371CallFunction(Player_Hit)372end if373break374375case COL_TOP376player[currentPlayer].ypos += object.collisionOffset.y377break378379case COL_BOTTOM380if player[currentPlayer].gravity == GRAVITY_GROUND381if object.collisionOffset.y >= 0382CallFunction(Player_Kill)383end if384end if385break386end switch387break388389case CHAINCRUSHER_TYPE_SMALL_ACTIVE390BoxCollisionTest(C_SOLID, object.entityPos, -16, -12, 16, 12, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)391switch checkResult392case COL_TOP393player[currentPlayer].ypos += object.collisionOffset.y394break395396case COL_BOTTOM397if player[currentPlayer].gravity == GRAVITY_GROUND398if object.collisionOffset.y >= 0399CallFunction(Player_Kill)400end if401end if402break403end switch404break405end switch406next407408object.ypos = temp0409object.currentPos.y = object.ypos410object.currentPos.y &= 0xFFFF0000411412temp0 = object.xpos413temp0 >>= 16414temp0 -= camera[0].xpos415Abs(temp0)416temp0 -= 128417if temp0 > screen.xcenter418if object.useButton == true419object.ypos = object.endPos.y420else421object.ypos = object.startPos.y422end if423object.timer = 0424425if object.crusherType >= CHAINCRUSHER_TYPE_SMALL426object.state = CHAINCRUSHER_DROPWHENACTIVE427object.crusherType = CHAINCRUSHER_TYPE_SMALL428else429object.state = CHAINCRUSHER_DROPPING430end if431432object.priority = PRIORITY_BOUNDS433end if434end event435436437event ObjectDraw438temp0 = object.ypos439temp0 -= object.startPos.y440temp0 >>= 16441temp0 += 4442temp1 = 257443temp1 -= temp0444temp2 = temp0445temp2 += 18446FlipSign(temp2)447EditFrame(5, -4, temp2, 8, temp0, 308, temp1)448DrawSpriteXY(5, object.xpos, object.currentPos.y)449DrawSpriteXY(0, object.xpos, object.startPos.y)450switch object.crusherType451case CHAINCRUSHER_TYPE_LARGE452DrawSpriteXY(1, object.xpos, object.currentPos.y)453DrawSpriteXY(4, object.xpos, object.currentPos.y)454break455456case CHAINCRUSHER_TYPE_MED457DrawSpriteXY(2, object.xpos, object.currentPos.y)458DrawSpriteXY(4, object.xpos, object.currentPos.y)459break460461case CHAINCRUSHER_TYPE_SMALL462case CHAINCRUSHER_TYPE_SMALL_ACTIVE463DrawSpriteXY(3, object.xpos, object.currentPos.y)464break465end switch466end event467468469event ObjectStartup470LoadSpriteSheet("MZ/Objects.gif")471SpriteFrame(-16, -52, 32, 32, 256, 76)472SpriteFrame(-56, -20, 112, 32, 143, 180)473SpriteFrame(-48, -20, 96, 32, 159, 147)474SpriteFrame(-16, -20, 32, 32, 256, 109)475SpriteFrame(-44, 12, 87, 32, 199, 256)476SpriteFrame(-4, -206, 8, 188, 308, 69)477478foreach (TypeName[Chained Crusher], arrayPos0, ALL_ENTITIES)479object[arrayPos0].useButton = object[arrayPos0].propertyValue480object[arrayPos0].useButton >>= 7481482object[arrayPos0].crusherType = object[arrayPos0].propertyValue483object[arrayPos0].crusherType &= 0x7F484object[arrayPos0].crusherType >>= 4485object[arrayPos0].crusherType %= 3486487if object[arrayPos0].crusherType == CHAINCRUSHER_TYPE_SMALL488object[arrayPos0].state = CHAINCRUSHER_DROPWHENACTIVE489end if490491temp0 = object[arrayPos0].propertyValue492temp0 &= 7493if temp0 > 6494temp0 = 0495end if496497object[arrayPos0].startPos.y = object[arrayPos0].ypos498object[arrayPos0].endPos.y = object[arrayPos0].startPos.y499switch temp0500case 0501object[arrayPos0].endPos.y += 0x700000502break503504case 1505object[arrayPos0].endPos.y += 0xA00000506break507508case 2509object[arrayPos0].endPos.y += 0x500000510break511512case 3513object[arrayPos0].endPos.y += 0x780000514break515516case 4517object[arrayPos0].endPos.y += 0x380000518break519520case 5521object[arrayPos0].endPos.y += 0x580000522break523524case 6525object[arrayPos0].endPos.y += 0xB80000526break527end switch528529if object[arrayPos0].useButton == true530object[arrayPos0].ypos = object[arrayPos0].endPos.y531end if532next533534temp0 = 0535ChainedCrusher_startDebugID = DebugMode_ObjCount536while temp0 < 21537SetTableValue(TypeName[Chained Crusher], DebugMode_ObjCount, DebugMode_TypesTable)538SetTableValue(ChainedCrusher_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)539SetTableValue(ChainedCrusher_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)540DebugMode_ObjCount++541temp0++542loop543end event544545546// ========================547// Editor Events548// ========================549550event RSDKEdit551if editor.returnVariable == true552switch editor.variableID553case EDIT_VAR_PROPVAL // property value554checkResult = object.propertyValue555break556557case 0 // useButton558checkResult = object.propertyValue559checkResult >>= 7560checkResult &= 1561break562563case 1 // type564checkResult = object.propertyValue565checkResult &= 0x7F566checkResult >>= 4567checkResult %= 3568break569570case 2 // length571checkResult = object.propertyValue572checkResult &= 7573if checkResult > 6574checkResult = 0575end if576break577578end switch579else580switch editor.variableID581case EDIT_VAR_PROPVAL // property value582object.propertyValue = editor.variableValue583break584585case 0 // useButton586CheckNotEqual(editor.variableValue, false)587SetBit(object.propertyValue, 7, checkResult)588break589590case 1 // type591temp1 = 0x70592Not(temp1)593object.propertyValue &= temp1594595editor.variableValue &= 3596editor.variableValue <<= 4597object.propertyValue |= editor.variableValue598break599600case 2 // length601temp1 = 7602Not(temp1)603object.propertyValue &= temp1604605temp0 = editor.variableValue606temp0 &= 7607object.propertyValue |= temp0608break609610end switch611end if612end event613614615event RSDKDraw616temp7 = object.ypos617// Get Values618object.useButton = object.propertyValue619object.useButton >>= 7620object.crusherType = object.propertyValue621object.crusherType &= 0x7F622object.crusherType >>= 4623object.crusherType %= 3624625temp0 = object.propertyValue626temp0 &= 7627if temp0 > 6628temp0 = 0629end if630631object.startPos.y = object.ypos632object.endPos.y = object.startPos.y633switch temp0634case 0635object.endPos.y += 0x700000636break637638case 1639object.endPos.y += 0xA00000640break641642case 2643object.endPos.y += 0x500000644break645646case 3647object.endPos.y += 0x780000648break649650case 4651object.endPos.y += 0x380000652break653654case 5655object.endPos.y += 0x580000656break657658case 6659object.endPos.y += 0xB80000660break661662end switch663664object.ypos = object.startPos.y665if object.useButton == true666object.ypos = object.endPos.y667end if668object.inkEffect = INK_BLEND669670// Drawww (Actual)671object.currentPos.y = object.ypos672object.currentPos.y &= 0xFFFF0000673temp0 = object.ypos674temp0 -= object.startPos.y675temp0 >>= 16676temp0 += 4677temp1 = 257678temp1 -= temp0679temp2 = temp0680temp2 += 18681FlipSign(temp2)682EditFrame(5, -4, temp2, 8, temp0, 308, temp1)683DrawSpriteXY(5, object.xpos, object.currentPos.y)684DrawSpriteXY(0, object.xpos, object.startPos.y)685switch object.crusherType686case CHAINCRUSHER_TYPE_LARGE687DrawSpriteXY(1, object.xpos, object.currentPos.y)688DrawSpriteXY(4, object.xpos, object.currentPos.y)689break690691case CHAINCRUSHER_TYPE_MED692DrawSpriteXY(2, object.xpos, object.currentPos.y)693DrawSpriteXY(4, object.xpos, object.currentPos.y)694break695696case CHAINCRUSHER_TYPE_SMALL697DrawSpriteXY(3, object.xpos, object.currentPos.y)698break699700end switch701702// Drawww (Preview)703object.ypos = object.endPos.y704if object.useButton == true705object.ypos = object.startPos.y706end if707object.currentPos.y = object.ypos708object.currentPos.y &= 0xFFFF0000709temp0 = object.ypos710temp0 -= object.startPos.y711temp0 >>= 16712temp0 += 4713temp1 = 257714temp1 -= temp0715temp2 = temp0716temp2 += 18717FlipSign(temp2)718EditFrame(5, -4, temp2, 8, temp0, 308, temp1)719DrawSpriteFX(5, FX_INK, object.xpos, object.currentPos.y)720DrawSpriteFX(0, FX_INK, object.xpos, object.startPos.y)721switch object.crusherType722case CHAINCRUSHER_TYPE_LARGE723DrawSpriteFX(1, FX_INK, object.xpos, object.currentPos.y)724DrawSpriteFX(4, FX_INK, object.xpos, object.currentPos.y)725break726727case CHAINCRUSHER_TYPE_MED728DrawSpriteFX(2, FX_INK, object.xpos, object.currentPos.y)729DrawSpriteFX(4, FX_INK, object.xpos, object.currentPos.y)730break731732case CHAINCRUSHER_TYPE_SMALL733DrawSpriteFX(3, FX_INK, object.xpos, object.currentPos.y)734break735736end switch737738object.ypos = temp7739end event740741742event RSDKLoad743LoadSpriteSheet("MZ/Objects.gif")744SpriteFrame(-16, -52, 32, 32, 256, 76)745SpriteFrame(-56, -20, 112, 32, 143, 180)746SpriteFrame(-48, -20, 96, 32, 159, 147)747SpriteFrame(-16, -20, 32, 32, 256, 109)748SpriteFrame(-44, 12, 87, 32, 199, 256)749SpriteFrame(-4, -206, 8, 188, 308, 69)750751AddEditorVariable("useButton")752SetActiveVariable("useButton")753AddEnumVariable("false", false)754AddEnumVariable("true", true)755756AddEditorVariable("type")757SetActiveVariable("type")758AddEnumVariable("Large", CHAINCRUSHER_TYPE_LARGE)759AddEnumVariable("Medium", CHAINCRUSHER_TYPE_MED)760AddEnumVariable("Small (Drop On Interval)", CHAINCRUSHER_TYPE_SMALL)761AddEnumVariable("Small (Wait For Visible)", CHAINCRUSHER_TYPE_SMALL_ACTIVE)762763AddEditorVariable("length")764SetActiveVariable("length")765AddEnumVariable("112 Pixels", 0)766AddEnumVariable("160 Pixels", 1)767AddEnumVariable("80 Pixels", 2)768AddEnumVariable("120 Pixels", 3)769AddEnumVariable("56 Pixels", 4)770AddEnumVariable("88 Pixels", 5)771AddEnumVariable("184 Pixels", 6)772end event773774775