Path: blob/master/Sonic 1/Scripts/MZ/HCrusher.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Horiz 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.crusherType // unused13private alias object.value2 : object.useButton14private alias object.value3 : object.startPos.x15private alias object.value4 : object.endPos.x16private alias object.value5 : object.collisionOffset.x17private alias object.value6 : object.currentPos.x18private alias object.value7 : object.dontPlaySfx // not really used in any substantial way19private alias object.value8 : object.moveVel2021// States22private alias 0 : HORIZCRUSHER_DROPPING23private alias 1 : HORIZCRUSHER_DROPPED24private alias 2 : HORIZCRUSHER_RISING25private alias 3 : HORIZCRUSHER_RISEN2627// Player Aliases28private alias object.xpos : player.xpos29private alias object.gravity : player.gravity3031private alias object.value17 : debugMode.currentSelection3233// PushButton aliases34private alias object.propertyValue : pushButton.stood353637// ========================38// Function Declarations39// ========================4041reserve function HorizCrusher_DebugDraw42reserve function HorizCrusher_DebugSpawn43reserve function HorizCrusher_CheckOnScreen444546// ========================47// Static Values48// ========================4950private value HorizCrusher_startDebugID = 0515253// ========================54// Function Definitions55// ========================5657private function HorizCrusher_DebugDraw58temp7 = debugMode[0].currentSelection59temp7 -= HorizCrusher_startDebugID6061temp5 = object.xpos62switch temp763case 064temp6 = 0x38000065break6667case 168temp6 = 0x9F000069break7071case 272temp6 = 0x50000073break7475case 376temp6 = 0x38000077break7879end switch8081if object.direction == FLIP_NONE82FlipSign(temp6)83end if8485temp5 += temp686if temp5 > object.xpos87temp0 = temp588temp0 -= object.xpos89else90temp0 = object.xpos91temp0 -= temp592end if9394temp0 >>= 1695temp0 += 496temp1 = 29997temp1 -= temp098if object.direction == FLIP_X99temp2 = temp0100temp2 += 34101FlipSign(temp2)102else103temp2 = 16104end if105temp0 += 17106EditFrame(3, temp2, -8, temp0, 16, temp1, 388)107108DrawSpriteXY(3, temp5, object.ypos)109DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)110DrawSpriteFX(1, FX_FLIP, temp5, object.ypos)111DrawSpriteFX(2, FX_FLIP, temp5, object.ypos)112end function113114115private function HorizCrusher_DebugSpawn116temp7 = debugMode[0].currentSelection117temp7 -= HorizCrusher_startDebugID118119CreateTempObject(TypeName[Horiz Crusher], 0, object.xpos, object.ypos)120object[tempObjectPos].direction = object.direction121object[tempObjectPos].useButton = false122if object.direction == FLIP_NONE123object[tempObjectPos].moveVel = -0x7000124else125object[tempObjectPos].moveVel = 0x7000126end if127128object[tempObjectPos].startPos.x = object.xpos129object[tempObjectPos].endPos.x = object[tempObjectPos].startPos.x130131switch temp7132case 0133temp6 = 0x380000134break135136case 1137temp6 = 0x9F0000138break139140case 2141temp6 = 0x500000142break143144case 3145temp6 = 0x380000146break147148end switch149150if object.direction == FLIP_NONE151FlipSign(temp6)152end if153154object[tempObjectPos].endPos.x += temp6155156if object[tempObjectPos].useButton == true // this is never true (it's set to false right above)157object[tempObjectPos].xpos = object[tempObjectPos].endPos.x158end if159end function160161162// Unused func163private function HorizCrusher_CheckOnScreen164checkResult = false165temp0 = object.ypos166temp0 >>= 16167temp0 -= camera[0].ypos168Abs(temp0)169if 64 <= screen.ycenter // huh? 64? i think that's supposed to be temp0...170temp1 = object.endPos.x171temp1 -= object.startPos.x172temp1 >>= 16173temp1 += 8174temp1 >>= 1175temp0 = object.startPos.x176temp0 += object.endPos.x177temp0 >>= 17178temp0 -= 12179temp0 -= camera[0].xpos180Abs(temp0)181temp0 -= temp1182temp0 -= 40183if temp0 <= screen.xcenter184checkResult = true185end if186end if187end function188189190// ========================191// Events192// ========================193194event ObjectUpdate195if object.useButton == true196if pushButton[+1].stood == false197object.dontPlaySfx = false198object.xvel += object.moveVel199object.xpos += object.xvel200201temp0 = false202if object.direction == FLIP_NONE203if object.xpos <= object.endPos.x204temp0 = true205end if206else207if object.xpos >= object.endPos.x208temp0 = true209end if210end if211212if temp0 == true213object.xpos = object.endPos.x214object.xvel = 0215end if216else217if object.moveVel > 0218object.xpos -= 0x8000219else220object.xpos += 0x8000221end if222223temp0 = false224if object.direction == FLIP_NONE225if object.xpos >= object.startPos.x226temp0 = true227end if228else229if object.xpos <= object.startPos.x230temp0 = true231end if232end if233234if temp0 == true235object.xpos = object.startPos.x236object.xvel = 0237end if238end if239else240switch object.state241case HORIZCRUSHER_DROPPING242object.dontPlaySfx = false243object.xvel += object.moveVel244object.xpos += object.xvel245temp0 = false246if object.direction == FLIP_NONE247if object.xpos <= object.endPos.x248temp0 = true249end if250else251if object.xpos >= object.endPos.x252temp0 = true253end if254end if255256if temp0 == true257object.xpos = object.endPos.x258object.xvel = 0259object.state++260end if261break262263case HORIZCRUSHER_DROPPED264object.timer++265if object.timer == 60266object.timer = 0267if object.moveVel > 0268object.xvel = -0x8000269else270object.xvel = 0x8000271end if272object.state++273end if274break275276case HORIZCRUSHER_RISING277object.xpos += object.xvel278temp0 = false279if object.direction == FLIP_NONE280if object.xpos >= object.startPos.x281temp0 = true282end if283else284if object.xpos <= object.startPos.x285temp0 = true286end if287end if288289if temp0 == true290object.xpos = object.startPos.x291object.xvel = 0292object.state++293end if294break295296case HORIZCRUSHER_RISEN297object.timer++298if object.timer == 4299object.timer = 0300object.state = HORIZCRUSHER_DROPPING301end if302break303304end switch305end if306307object.collisionOffset.x = object.xpos308object.collisionOffset.x &= 0xFFFF0000309object.collisionOffset.x -= object.currentPos.x310311temp0 = object.xpos312object.xpos = object.currentPos.x313temp5 = object.collisionOffset.x314temp5 >>= 16315if object.direction == FLIP_NONE316temp6 = -42317temp6 += temp5318temp7 = -12319temp7 += temp5320else321temp6 = 12322temp6 += temp5323temp7 = 42324temp7 += temp5325end if326327foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)328BoxCollisionTest(C_SOLID, object.entityPos, -12, -32, 12, 32, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)329switch checkResult330case COL_TOP331player[currentPlayer].xpos += object.collisionOffset.x332break333334case COL_LEFT335if object.collisionOffset.x < 0336player[currentPlayer].xpos += object.collisionOffset.x337end if338break339340case COL_RIGHT341if object.collisionOffset.x > 0342player[currentPlayer].xpos += object.collisionOffset.x343end if344break345346case COL_BOTTOM347if player[currentPlayer].gravity == GRAVITY_GROUND348CallFunction(Player_Kill)349end if350break351352end switch353354BoxCollisionTest(C_TOUCH, object.entityPos, temp6, -24, temp7, 24, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)355if checkResult == true356CallFunction(Player_Hit)357end if358next359360object.xpos = temp0361object.currentPos.x = object.xpos362object.currentPos.x &= 0xFFFF0000363end event364365366event ObjectDraw367if object.xpos > object.startPos.x368temp0 = object.xpos369temp0 -= object.startPos.x370else371temp0 = object.startPos.x372temp0 -= object.xpos373end if374temp0 >>= 16375temp0 += 4376temp1 = 299377temp1 -= temp0378379if object.direction == FLIP_X380temp2 = temp0381temp2 += 34382FlipSign(temp2)383else384temp2 = 16385end if386temp0 += 17387EditFrame(3, temp2, -8, temp0, 16, temp1, 388)388389DrawSpriteXY(3, object.currentPos.x, object.ypos)390DrawSpriteFX(0, FX_FLIP, object.startPos.x, object.ypos)391DrawSpriteFX(1, FX_FLIP, object.currentPos.x, object.ypos)392DrawSpriteFX(2, FX_FLIP, object.currentPos.x, object.ypos)393end event394395396event ObjectStartup397LoadSpriteSheet("MZ/Objects.gif")398SpriteFrame(36, -16, 8, 32, 289, 158)399SpriteFrame(-12, -32, 32, 64, 256, 142)400SpriteFrame(-43, -24, 31, 48, 256, 207)401SpriteFrame(-92, -8, 184, 16, 132, 388)402403foreach (TypeName[Horiz Crusher], arrayPos0, ALL_ENTITIES)404object[arrayPos0].useButton = object[arrayPos0].propertyValue405object[arrayPos0].useButton >>= 7406407GetBit(object[arrayPos0].direction, object[arrayPos0].propertyValue, 6)408409// Bug Details:410// Right-facing crushers should have a positive velocity value, but this startup code gives a negative vel to *all* crushers, not just left-facing ones411// This object isn't normally placed in any scenes, though, so it doesn't matter too much (and the debug spawn code gives the correct vels too, it's only here where it's wrong)412object[arrayPos0].moveVel = -0x7000413414object[arrayPos0].state = object[arrayPos0].propertyValue415object[arrayPos0].state &= 3416417object[arrayPos0].startPos.x = object[arrayPos0].xpos418object[arrayPos0].endPos.x = object[arrayPos0].startPos.x419switch object[arrayPos0].state420case HORIZCRUSHER_DROPPING421temp0 = 0x380000422break423424case HORIZCRUSHER_DROPPED425temp0 = 0x9F0000426break427428case HORIZCRUSHER_RISING429temp0 = 0x500000430break431432case HORIZCRUSHER_RISEN433temp0 = 0x380000434break435436end switch437438if object[arrayPos0].direction == FLIP_NONE439FlipSign(temp0)440end if441442object[arrayPos0].endPos.x += temp0443444if object[arrayPos0].useButton == true445object[arrayPos0].xpos = object[arrayPos0].endPos.x446end if447next448449temp0 = 0450HorizCrusher_startDebugID = DebugMode_ObjCount451while temp0 < 4452SetTableValue(TypeName[Horiz Crusher], DebugMode_ObjCount, DebugMode_TypesTable)453SetTableValue(HorizCrusher_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)454SetTableValue(HorizCrusher_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)455DebugMode_ObjCount++456temp0++457loop458end event459460461// ========================462// Editor Events463// ========================464465event RSDKEdit466if editor.returnVariable == true467switch editor.variableID468case EDIT_VAR_PROPVAL // property value469checkResult = object.propertyValue470break471472case 0 // useButton473GetBit(checkResult, object.propertyValue, 7)474break475476case 1 // direction477GetBit(checkResult, object.propertyValue, 6)478break479480case 2 // type481checkResult = object.propertyValue482checkResult &= 3483break484485end switch486else487switch editor.variableID488case EDIT_VAR_PROPVAL // property value489object.propertyValue = editor.variableValue490break491492case 0 // useButton493CheckNotEqual(editor.variableValue, false)494SetBit(object.propertyValue, 7, checkResult)495break496497case 1 // direction498CheckNotEqual(editor.variableValue, false)499SetBit(object.propertyValue, 6, checkResult)500break501502case 2 // type503temp1 = 3504Not(temp1)505object.propertyValue &= temp1506507temp0 = editor.variableValue508temp0 &= 3509object.propertyValue |= temp0510break511512end switch513end if514end event515516517event RSDKDraw518GetBit(object.useButton, object.propertyValue, 7)519520GetBit(object.direction, object.propertyValue, 6)521522object.startPos.x = object.xpos523object.endPos.x = object.startPos.x524525object.state = object.propertyValue526object.state &= 3527528switch object.state529case HORIZCRUSHER_DROPPING530case HORIZCRUSHER_RISEN531object.endPos.x += 0x380000532break533534case HORIZCRUSHER_DROPPED535object.endPos.x += 0x9F0000536break537538case HORIZCRUSHER_RISING539object.endPos.x += 0x500000540break541542end switch543object.currentPos.x = object.xpos544object.currentPos.x &= 0xFFFF0000545546if object.xpos > object.startPos.x547temp0 = object.xpos548temp0 -= object.startPos.x549else550temp0 = object.startPos.x551temp0 -= object.xpos552end if553temp0 >>= 16554temp0 += 4555temp1 = 299556temp1 -= temp0557558if object.direction == FLIP_X559temp2 = temp0560temp2 += 34561FlipSign(temp2)562else563temp2 = 16564end if565temp0 += 17566EditFrame(3, temp2, -8, temp0, 16, temp1, 388)567568DrawSpriteXY(3, object.currentPos.x, object.ypos)569DrawSpriteFX(0, FX_FLIP, object.startPos.x, object.ypos)570DrawSpriteFX(1, FX_FLIP, object.currentPos.x, object.ypos)571DrawSpriteFX(2, FX_FLIP, object.currentPos.x, object.ypos)572end event573574575event RSDKLoad576LoadSpriteSheet("MZ/Objects.gif")577SpriteFrame(36, -16, 8, 32, 289, 158)578SpriteFrame(-12, -32, 32, 64, 256, 142)579SpriteFrame(-43, -24, 31, 48, 256, 207)580SpriteFrame(-92, -8, 184, 16, 132, 388)581582AddEditorVariable("useButton")583SetActiveVariable("useButton")584AddEnumVariable("false", false)585AddEnumVariable("true", true)586587AddEditorVariable("direction")588SetActiveVariable("direction")589AddEnumVariable("Left", 0)590AddEnumVariable("Right", 1)591592AddEditorVariable("length")593SetActiveVariable("length")594AddEnumVariable("56 Pixels", 0)595AddEnumVariable("159 Pixels", 1)596AddEnumVariable("80 Pixels", 2)597AddEnumVariable("56 Pixels (Use Button)", 3)598end event599600601