Path: blob/master/Sonic 2/Scripts/MCZ/VDropBridge.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: V Drop Bridge Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias 0 : VDROPBRIDGE_CLOSED12private alias 1 : VDROPBRIDGE_OPENING_L13private alias 2 : VDROPBRIDGE_OPENING_R14private alias 3 : VDROPBRIDGE_OPEN_L15private alias 4 : VDROPBRIDGE_OPEN_R1617// Activator switch alias18private alias object.propertyValue : pullSwitch.pulled192021// ========================22// Function Declarations23// ========================2425reserve function VDropBridge_DebugDraw26reserve function VDropBridge_DebugSpawn272829// ========================30// Function Definitions31// ========================3233private function VDropBridge_DebugDraw34DrawSprite(0)35end function363738private function VDropBridge_DebugSpawn39CreateTempObject(TypeName[V Drop Bridge], 0, object.xpos, object.ypos)40object[tempObjectPos].direction = object.direction41object[tempObjectPos].angle = 25642end function434445// ========================46// Events47// ========================4849event ObjectUpdate50switch object.state51case VDROPBRIDGE_CLOSED52if pullSwitch[-1].pulled == true53if object.direction == FLIP_NONE54object.state = VDROPBRIDGE_OPENING_R55else56object.state = VDROPBRIDGE_OPENING_L57end if5859if object.priority != PRIORITY_XBOUNDS_DESTROY60object.priority = PRIORITY_ACTIVE61end if6263PlaySfx(SfxName[Drop Bridge], false)64end if6566foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)67BoxCollisionTest(C_SOLID, object.entityPos, -8, -136, 8, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)68next69break7071case VDROPBRIDGE_OPENING_L72if object.angle < 38473object.angle += 274else75object.state = VDROPBRIDGE_OPEN_L76PlaySfx(SfxName[Drop Bridge 2], false)77end if7879foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)80BoxCollisionTest(C_SOLID, object.entityPos, -8, -136, 8, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)81next82break8384case VDROPBRIDGE_OPENING_R85if object.angle > 12886object.angle -= 287else88object.state = VDROPBRIDGE_OPEN_R89PlaySfx(SfxName[Drop Bridge 2], false)90end if9192foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)93BoxCollisionTest(C_SOLID, object.entityPos, -8, -136, 8, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)94next95break9697case VDROPBRIDGE_OPEN_L98foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)99BoxCollisionTest(C_SOLID, object.entityPos, -136, -8, -8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)100next101break102103case VDROPBRIDGE_OPEN_R104foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)105BoxCollisionTest(C_SOLID, object.entityPos, 8, -8, 136, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)106next107break108109end switch110111if object.outOfBounds == true112if object.priority != PRIORITY_XBOUNDS_DESTROY113// If offscreen, reset this object114object.angle = 256115object.state = VDROPBRIDGE_CLOSED116end if117end if118end event119120121event ObjectDraw122// Draw all the bridge segments with a loop123temp0 = 0124temp1 = 0x800125while temp0 < 8126Sin(temp2, object.angle)127temp2 *= temp1128temp2 += object.xpos129130Cos(temp3, object.angle)131temp3 *= temp1132temp3 += object.ypos133134DrawSpriteXY(0, temp2, temp3)135136temp0++137temp1 += 0x800138loop139end event140141142event ObjectStartup143LoadSpriteSheet("MCZ/Objects.gif")144145SpriteFrame(-8, -8, 16, 16, 135, 131)146147foreach (TypeName[V Drop Bridge], arrayPos0, ALL_ENTITIES)148object[arrayPos0].angle = 256149object[arrayPos0].direction = object[arrayPos0].propertyValue150object[arrayPos0].direction &= FLIP_X151next152153SetTableValue(TypeName[V Drop Bridge], DebugMode_ObjCount, DebugMode_TypesTable)154SetTableValue(VDropBridge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)155SetTableValue(VDropBridge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)156DebugMode_ObjCount++157end event158159160// ========================161// Editor Events162// ========================163164event RSDKEdit165if editor.returnVariable == true166switch editor.variableID167case EDIT_VAR_PROPVAL // property value168checkResult = object.propertyValue169break170171case 0 // openDir172checkResult = object.propertyValue173checkResult &= 1174break175176end switch177else178switch editor.variableID179case EDIT_VAR_PROPVAL // property value180object.propertyValue = editor.variableValue181break182183case 0 // openDir184object.propertyValue = editor.variableValue185break186187end switch188end if189end event190191192event RSDKDraw193temp0 = 0194temp1 = 0x800195while temp0 < 8196Sin(temp2, 256)197temp2 *= temp1198temp2 += object.xpos199Cos(temp3, 256)200temp3 *= temp1201temp3 += object.ypos202DrawSpriteXY(0, temp2, temp3)203temp0++204temp1 += 0x800205loop206207if editor.showGizmos == true208editor.drawingOverlay = true209210// Draw semi-transparent version of how the bridge will be when lowered211212if object.propertyValue == 0213temp4 = 128214else215temp4 = 384216end if217218object.inkEffect = INK_BLEND219220temp0 = 0221temp1 = 0x800222while temp0 < 8223Sin(temp2, temp4)224temp2 *= temp1225temp2 += object.xpos226Cos(temp3, temp4)227temp3 *= temp1228temp3 += object.ypos229DrawSpriteFX(0, FX_INK, temp2, temp3)230temp0++231temp1 += 0x800232loop233234editor.drawingOverlay = false235end if236end event237238239event RSDKLoad240LoadSpriteSheet("MCZ/Objects.gif")241SpriteFrame(-8, -8, 16, 16, 135, 131)242243AddEditorVariable("openDir")244SetActiveVariable("openDir")245AddEnumVariable("Right", 0)246AddEnumVariable("Left", 1)247end event248249250