Path: blob/master/Sonic 2/Scripts/MPZ/BeltPlatform.txt
1479 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Belt Platform Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.basePos.x12private alias object.value1 : object.basePos.y13private alias object.value2 : object.movePos.x14private alias object.value3 : object.movePos.y15private alias object.value4 : object.collisionOffset.x16private alias object.value5 : object.collisionOffset.y17private alias object.value6 : object.tablePtr18private alias object.value7 : object.tablePos19private alias object.value8 : object.tableSize20private alias object.value31 : object.wrapOffset.y2122// Player Aliases23private alias object.xpos : player.xpos24private alias object.ypos : player.ypos252627// ========================28// Function Declarations29// ========================3031reserve function BeltPlatform_UpdateMovement323334// ========================35// Tables36// ========================3738private table BeltPlatform_flippedTablePos395, 9, 3, 2, 6, 0, 4, 8, 7, 140end table4142private table BeltPlatform_tableSizes4318, 18, 1844end table4546private table BeltPlatform_tablePtrs[3]4748private table BeltPlatform_movementTable0490, 0, -22, 10, -32, 32, -32, 224, -22, 246, 0, 256, 22, 246, 32, 224, 32, 32, 22, 1050end table5152private table BeltPlatform_movementTable1530, 0, -22, 10, -32, 32, -32, 352, -22, 374, 0, 384, 22, 374, 32, 352, 32, 32, 22, 1054end table5556private table BeltPlatform_movementTable2570, 0, -22, 10, -32, 32, -32, 480, -22, 502, 0, 512, 22, 502, 32, 480, 32, 32, 22, 1058end table596061// ========================62// Funcion Definitions63// ========================6465private function BeltPlatform_UpdateMovement66temp0 = object[arrayPos0].tablePos67GetTableValue(object[arrayPos0].movePos.x, temp0, object[arrayPos0].tablePtr)68object[arrayPos0].movePos.x += object[arrayPos0].basePos.x6970temp0++71GetTableValue(object[arrayPos0].movePos.y, temp0, object[arrayPos0].tablePtr)72object[arrayPos0].movePos.y += object[arrayPos0].basePos.y7374temp0 = object[arrayPos0].xpos75temp0 >>= 1676temp2 = temp077temp0 -= object[arrayPos0].movePos.x78Abs(temp0)7980temp1 = object[arrayPos0].ypos81temp1 -= object.wrapOffset.y82temp1 >>= 1683temp1 &= 0x7FF84temp3 = temp185temp1 -= object[arrayPos0].movePos.y86Abs(temp1)8788if temp1 < temp089object[arrayPos0].xvel = 0x1000090temp1 <<= 1691object[arrayPos0].yvel = temp192object[arrayPos0].yvel /= temp093else94if temp1 != 095temp0 <<= 1696object[arrayPos0].xvel = temp097object[arrayPos0].xvel /= temp198else99object[arrayPos0].xvel = 0100end if101object[arrayPos0].yvel = 0x10000102end if103104if object[arrayPos0].movePos.x < temp2105FlipSign(object[arrayPos0].xvel)106end if107108if object[arrayPos0].movePos.y < temp3109FlipSign(object[arrayPos0].yvel)110end if111end function112113114// ========================115// Events116// ========================117118event ObjectUpdate119temp2 = 0120temp0 = object.xpos121temp1 = object.ypos122temp0 >>= 16123temp1 >>= 16124temp1 &= 0x7FF125126if object.xvel < 0127if object.yvel < 0128if temp0 <= object.movePos.x129if temp1 <= object.movePos.y130temp2 = true131end if132end if133else134if temp0 <= object.movePos.x135if temp1 >= object.movePos.y136temp2 = true137end if138end if139end if140else141if object.yvel < 0142if temp0 >= object.movePos.x143if temp1 <= object.movePos.y144temp2 = true145end if146end if147else148if temp0 >= object.movePos.x149if temp1 >= object.movePos.y150temp2 = true151end if152end if153end if154end if155156if temp2 == true157if object.direction == FLIP_NONE158object.tablePos += 2159if object.tablePos > object.tableSize160object.tablePos = 0161end if162else163object.tablePos -= 2164if object.tablePos < 0165object.tablePos = object.tableSize166end if167end if168169arrayPos0 = object.entityPos170CallFunction(BeltPlatform_UpdateMovement)171end if172173temp0 = object.xpos174temp0 &= 0xFFFF0000175temp1 = object.ypos176temp1 &= 0xFFFF0000177temp2 = object.xpos178temp2 += object.xvel179temp3 = object.ypos180temp3 += object.yvel181182object.collisionOffset.x = temp2183object.collisionOffset.x &= 0xFFFF0000184object.collisionOffset.x -= temp0185object.collisionOffset.y = temp3186object.collisionOffset.y &= 0xFFFF0000187object.collisionOffset.y -= temp1188189foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)190BoxCollisionTest(C_PLATFORM, object.entityPos, -16, -8, 16, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)191if checkResult == true192player[currentPlayer].xpos += object.collisionOffset.x193player[currentPlayer].ypos += object.collisionOffset.y194end if195next196197object.xpos = temp2198object.ypos = temp3199end event200201202event ObjectDraw203DrawSprite(0)204end event205206207event ObjectStartup208LoadSpriteSheet("MPZ/Objects.gif")209SpriteFrame(-16, -8, 32, 16, 34, 67)210211SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)212SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)213SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)214215foreach (TypeName[Belt Platform], arrayPos0, ALL_ENTITIES)216object[arrayPos0].priority = PRIORITY_INACTIVE217218temp0 = object[arrayPos0].propertyValue219temp0 >>= 4220GetTableValue(object[arrayPos0].tablePtr, temp0, BeltPlatform_tablePtrs)221GetTableValue(object[arrayPos0].tableSize, temp0, BeltPlatform_tableSizes)222223object[arrayPos0].tablePos = object[arrayPos0].propertyValue224object[arrayPos0].tablePos &= 0xF225if object[arrayPos0].direction == FLIP_X226GetTableValue(temp0, object[arrayPos0].tablePos, BeltPlatform_flippedTablePos)227object[arrayPos0].tablePos = temp0228end if229object[arrayPos0].tablePos <<= 1230231CallFunction(BeltPlatform_UpdateMovement)232next233end event234235236// ========================237// Editor Events238// ========================239240event RSDKEdit241if editor.returnVariable == true242switch editor.variableID243case EDIT_VAR_PROPVAL // property value244checkResult = object.propertyValue245break246247case 0 // type248checkResult = object.propertyValue249checkResult >>= 4250checkResult %= 6251break252253case 1 // startOffset254checkResult = object.propertyValue255checkResult &= 0x0F256break257258case 2 // direction259checkResult = object.direction260checkResult &= 1261break262263end switch264else265switch editor.variableID266case EDIT_VAR_PROPVAL // property value267object.propertyValue = editor.variableValue268break269270case 0 // type271editor.variableValue %= 6272editor.variableValue <<= 4273274object.propertyValue &= 0x0F275object.propertyValue |= editor.variableValue276break277278case 1 // startOffset279editor.variableValue &= 0x0F280281object.propertyValue &= 0xF0282object.propertyValue |= editor.variableValue283break284285case 2 // direction286editor.variableValue &= 1287object.direction = editor.variableValue288break289290end switch291end if292end event293294295event RSDKDraw296DrawSprite(0)297298if editor.showGizmos == true299temp0 = object.propertyValue300temp0 >>= 4301GetTableValue(object.tablePtr, temp0, BeltPlatform_tablePtrs)302GetTableValue(object.tableSize, temp0, BeltPlatform_tableSizes)303304object.tablePos = object.propertyValue305object.tablePos &= 15306if object.direction == FLIP_X307GetTableValue(temp0, object.tablePos, BeltPlatform_flippedTablePos)308object.tablePos = temp0309end if310object.tablePos <<= 1311arrayPos0 = object.entityPos312CallFunction(BeltPlatform_UpdateMovement)313314temp0 = object.xvel315temp0 <<= 5316temp0 += object.xpos317318temp1 = object.yvel319temp1 <<= 5320temp1 += object.ypos321322DrawArrow(object.xpos, object.ypos, temp0, temp1, 0x00, 0xFF, 0x00)323end if324end event325326327event RSDKLoad328LoadSpriteSheet("MPZ/Objects.gif")329SpriteFrame(-16, -8, 32, 16, 34, 67)330331SetTableValue(BeltPlatform_movementTable0, 0, BeltPlatform_tablePtrs)332SetTableValue(BeltPlatform_movementTable1, 1, BeltPlatform_tablePtrs)333SetTableValue(BeltPlatform_movementTable2, 2, BeltPlatform_tablePtrs)334335AddEditorVariable("type")336SetActiveVariable("type")337338AddEditorVariable("startOffset")339SetActiveVariable("startOffset")340341AddEditorVariable("direction")342SetActiveVariable("direction")343AddEnumVariable("Clockwise", 0)344AddEnumVariable("Counter-clockwise", 1)345346// represent positions in the scene347// should be aligned with top most platform in the chain348SetVariableAlias(ALIAS_VAR_VAL0, "basePos.x")349SetVariableAlias(ALIAS_VAR_VAL1, "basePos.y")350end event351352353