Path: blob/master/Sonic 2/Scripts/CPZ/BumpingPlatform.txt
1478 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Bumping Platform Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.platformPos1.x12private alias object.value1 : object.platformPos2.x13private alias object.value2 : object.boundsL14private alias object.value3 : object.boundsR1516private alias 0 : BUMPINGPLATFORM_USE1PLATFORM17private alias 1 : BUMPINGPLATFORM_USE2PLATFORM1819// Player Aliases20private alias object.xpos : player.xpos212223// ========================24// Function Declarations25// ========================2627reserve function BumpingPlatform_DebugDraw28reserve function BumpingPlatform_DebugSpawn293031// ========================32// Tables33// ========================3435private table BumpingPlatform_stateTable360 // BUMPINGPLATFORM_USE1PLATFORM371 // BUMPINGPLATFORM_USE2PLATFORM381 // BUMPINGPLATFORM_USE2PLATFORM390 // BUMPINGPLATFORM_USE1PLATFORM40end table4142private table BumpingPlatform_boundsTable430x680000440xA80000450xE80000460x68000047end table4849private table BumpingPlatform_offsetTable50-0x680000, 0x00000051-0xB00000, 0x40000052-0x780000, 0x800000530x670000, 0x00000054end table555657// ========================58// Function Definitions59// ========================6061private function BumpingPlatform_DebugDraw62DrawSprite(0)63end function646566private function BumpingPlatform_DebugSpawn67CreateTempObject(TypeName[Bumping Platform], 0, object.xpos, object.ypos)68object[tempObjectPos].state = BUMPINGPLATFORM_USE1PLATFORM69object[tempObjectPos].boundsL = object.xpos70object[tempObjectPos].boundsL -= 0x68000071object[tempObjectPos].boundsR = object.xpos72object[tempObjectPos].boundsR += 0x68000073object[tempObjectPos].platformPos1.x = object.xpos74object[tempObjectPos].platformPos1.x += -0x68000075object[tempObjectPos].platformPos2.x = object.xpos76object[tempObjectPos].platformPos2.x += 0x00000077end function787980// ========================81// Events82// ========================8384event ObjectUpdate85temp6 = object.platformPos1.x86temp7 = object.platformPos2.x8788GetBit(temp0, object.direction, 0)89if temp0 == FLIP_NONE90object.platformPos1.x += 0x1000091if object.platformPos1.x >= object.boundsR92SetBit(object.direction, 0, FLIP_X)93end if94else95object.platformPos1.x -= 0x1000096if object.platformPos1.x <= object.boundsL97SetBit(object.direction, 0, FLIP_NONE)98end if99end if100101if object.state == BUMPINGPLATFORM_USE2PLATFORM102// Check Platform 1 Bumping103if object.direction == FLIP_Y104temp0 = object.platformPos1.x105temp0 += 0x180000106temp1 = object.platformPos2.x107temp1 -= 0x180000108if temp0 == temp1109object.direction ^= FLIP_XY110end if111end if112113if object.direction == FLIP_X114temp0 = object.platformPos1.x115temp0 -= 0x180000116temp1 = object.platformPos2.x117temp1 += 0x180000118if temp0 == temp1119object.direction ^= FLIP_XY120end if121end if122123// Move Platform 2124GetBit(temp0, object.direction, 1)125if temp0 == FLIP_NONE126object.platformPos2.x += 0x10000127if object.platformPos2.x >= object.boundsR128SetBit(object.direction, 1, FLIP_X)129end if130else131object.platformPos2.x -= 0x10000132if object.platformPos2.x <= object.boundsL133SetBit(object.direction, 1, FLIP_NONE)134end if135end if136137// Check Platform 2 Bumping138if object.direction == FLIP_Y139temp0 = object.platformPos1.x140temp0 += 0x180000141temp1 = object.platformPos2.x142temp1 -= 0x180000143if temp0 == temp1144object.direction ^= FLIP_XY145end if146end if147148if object.direction == FLIP_X149temp0 = object.platformPos1.x150temp0 -= 0x180000151temp1 = object.platformPos2.x152temp1 += 0x180000153if temp0 == temp1154object.direction ^= FLIP_XY155end if156end if157end if158159temp4 = object.platformPos1.x160temp5 = object.platformPos2.x161temp4 -= temp6162temp5 -= temp7163temp0 = object.xpos164foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)165object.xpos = temp6166BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)167if checkResult == true168player[currentPlayer].xpos += temp4169end if170171if object.state == BUMPINGPLATFORM_USE2PLATFORM172object.xpos = temp7173BoxCollisionTest(C_PLATFORM, object.entityPos, -24, -8, 24, 6, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)174if checkResult == true175player[currentPlayer].xpos += temp5176end if177end if178next179object.xpos = temp0180end event181182183event ObjectDraw184DrawSpriteXY(0, object.platformPos1.x, object.ypos)185if object.state == BUMPINGPLATFORM_USE2PLATFORM186DrawSpriteXY(0, object.platformPos2.x, object.ypos)187end if188end event189190191event ObjectStartup192LoadSpriteSheet("CPZ/Objects.gif")193SpriteFrame(-24, -8, 48, 14, 6, 204)194195foreach (TypeName[Bumping Platform], arrayPos0, ALL_ENTITIES)196temp0 = object[arrayPos0].propertyValue197198GetTableValue(object[arrayPos0].state, temp0, BumpingPlatform_stateTable)199200GetTableValue(temp1, temp0, BumpingPlatform_boundsTable)201object[arrayPos0].boundsL = object[arrayPos0].xpos202object[arrayPos0].boundsL -= temp1203object[arrayPos0].boundsR = object[arrayPos0].xpos204object[arrayPos0].boundsR += temp1205temp0 <<= 1206207GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)208object[arrayPos0].platformPos1.x = object[arrayPos0].xpos209object[arrayPos0].platformPos1.x += temp1210temp0++211212GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)213object[arrayPos0].platformPos2.x = object[arrayPos0].xpos214object[arrayPos0].platformPos2.x += temp1215216if object[arrayPos0].propertyValue == 2217object[arrayPos0].direction = FLIP_X218end if219220object[arrayPos0].priority = PRIORITY_ACTIVE221next222223SetTableValue(TypeName[Bumping Platform], DebugMode_ObjCount, DebugMode_TypesTable)224SetTableValue(BumpingPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)225SetTableValue(BumpingPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)226DebugMode_ObjCount++227end event228229230// ========================231// Editor Events232// ========================233234event RSDKEdit235if editor.returnVariable == true236switch editor.variableID237case EDIT_VAR_PROPVAL // property value238checkResult = object.propertyValue239break240241case 0 // type242checkResult = object.propertyValue243checkResult &= 3244break245246end switch247else248switch editor.variableID249case EDIT_VAR_PROPVAL // property value250object.propertyValue = editor.variableValue251break252253case 0 // type254object.propertyValue = editor.variableValue255object.propertyValue &= 3256break257258end switch259end if260end event261262263event RSDKDraw264temp0 = object.propertyValue265temp0 <<= 1266267GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)268// using temp2 as a object.platformPos1.x stand-in269temp2 = object.xpos270temp2 += temp1271temp0++272273GetTableValue(temp1, temp0, BumpingPlatform_offsetTable)274// and using temp3 as a object.platformPos2.x stand-in275temp3 = object.xpos276temp3 += temp1277278DrawSpriteXY(0, temp2, object.ypos)279if object.state == BUMPINGPLATFORM_USE2PLATFORM280DrawSpriteXY(0, temp3, object.ypos)281end if282end event283284285event RSDKLoad286LoadSpriteSheet("CPZ/Objects.gif")287SpriteFrame(-24, -8, 48, 14, 6, 204)288289AddEditorVariable("type")290SetActiveVariable("type")291AddEnumVariable("Small Gap (1 Platform, Moving Right)", 0)292AddEnumVariable("Large Gap (2 Platforms)", 1)293AddEnumVariable("Large Gap (2 Platforms)", 2)294AddEnumVariable("Small Gap (1 Platform, Moving Left)", 3)295end event296297298