Path: blob/master/Sonic 2/Scripts/MCZ/CollapsingLedge.txt
1480 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: C Ledge 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.delay1314private alias 0 : CLEDGE_ACTIVE15private alias 1 : CLEDGE_COLLAPSE16private alias 2 : CLEDGE_COLLAPSED17private alias 3 : CLEDGE_NONE18private alias 4 : CLEDGE_TILEDELAY19private alias 5 : CLEDGE_TILEFALL202122// ========================23// Function Declarations24// ========================2526reserve function CLedge_DebugDraw27reserve function CLedge_DebugSpawn282930// ========================31// Tables32// ========================3334private table CLedge_tileFrameTable351, 2, 3, 4, 5, 636end table3738private table CLedge_collapseTable392, 6, 10, 14, 18, 2240end table414243// ========================44// Function Definitions45// ========================4647private function CLedge_DebugDraw48DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)49end function505152private function CLedge_DebugSpawn53CreateTempObject(TypeName[C Ledge], 0, object.xpos, object.ypos)54object[tempObjectPos].direction = object.direction55end function565758// ========================59// Events60// ========================6162event ObjectUpdate63switch object.state64case CLEDGE_ACTIVE65break6667case CLEDGE_COLLAPSE68if object.timer < 1069object.timer++70else71temp0 = 072while temp0 < 673GetTableValue(temp1, temp0, CLedge_tileFrameTable)74CreateTempObject(TypeName[C Ledge], temp1, object.xpos, object.ypos)75object[tempObjectPos].state = CLEDGE_TILEDELAY76object[tempObjectPos].direction = object.direction77GetTableValue(object[tempObjectPos].delay, temp0, CLedge_collapseTable)78temp0++79loop80PlaySfx(SfxName[Ledge Break], false)81object.timer = 082object.state++83end if84break8586case CLEDGE_COLLAPSED87// During this state, the object is invisible, but it's still providing collision for a brief moment before it truly disappears88if object.timer < 2089object.timer++90else91object.timer = 092object.state++93end if94break9596case CLEDGE_NONE97break9899case CLEDGE_TILEDELAY100if object.timer < object.delay101object.timer++102else103object.timer = 0104object.state++105end if106break107108case CLEDGE_TILEFALL109object.ypos += object.yvel110object.yvel += 0x4000111if object.outOfBounds == true112object.type = TypeName[Blank Object]113end if114break115116end switch117118if object.state < CLEDGE_TILEDELAY119if object.outOfBounds == true120object.state = CLEDGE_ACTIVE121object.timer = 0122object.priority = PRIORITY_BOUNDS123end if124end if125126if object.state < CLEDGE_NONE127// In one of the platform states, so act like one and provide collision to the player128foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)129BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -24, 32, -8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)130131if checkResult == true132if object.state == CLEDGE_ACTIVE133object.state = CLEDGE_COLLAPSE134object.priority = PRIORITY_ACTIVE135end if136end if137next138end if139end event140141142event ObjectDraw143switch object.state144case CLEDGE_ACTIVE145case CLEDGE_COLLAPSE146// Full platform - simply draw the entire sprite147DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)148break149150case CLEDGE_COLLAPSED151case CLEDGE_NONE152break153154case CLEDGE_TILEDELAY155case CLEDGE_TILEFALL156// Tile fragment, draw whatever sprite's assigned to this object157DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)158break159160end switch161end event162163164event ObjectStartup165LoadSpriteSheet("MCZ/Objects.gif")166167SpriteFrame(-32, -24, 64, 48, 136, 66) // 0 - Full platform168169SpriteFrame( 8, -8, 24, 32, 176, 82) // 1-6 - Individual platform strips170SpriteFrame(-16, -8, 24, 32, 152, 82) // (for when it falls apart)171SpriteFrame( 16, -24, 16, 16, 184, 66)172SpriteFrame( 0, -24, 16, 16, 168, 66)173SpriteFrame(-16, -24, 16, 16, 152, 66)174SpriteFrame(-32, -24, 16, 16, 136, 66)175176// Huh? Blank Object?177// Prolly meant to be [C Ledge], but it might be [C Floor] or something in the original source instead178foreach (TypeName[Blank Object], arrayPos0, ALL_ENTITIES)179// This uses Property Value as direction, though that isn't the case for this object180// -> Interestingly, there are a few C Ledges that do have their prop val set to 1, the majority are181// right-facing ones, though there is a single left-facing one with it too182// -> Once again though, this doesn't matter anyway - check out down below183184object[arrayPos0].direction = object[arrayPos0].propertyValue185object[arrayPos0].direction &= FLIP_X186next187188// The above is meant to set up the directions of all C Ledges in the scene, but thanks to an erroneous TypeName189// it doesn't function correctly190// However this still works by chance, because the direction attribute is already set from the scene191// There are many ledges that have something in their property value, but that value isn't used by the game192193SetTableValue(TypeName[C Ledge], DebugMode_ObjCount, DebugMode_TypesTable)194SetTableValue(CLedge_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)195SetTableValue(CLedge_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)196DebugMode_ObjCount++197end event198199200// ========================201// Editor Events202// ========================203204event RSDKEdit205if editor.returnVariable == true206switch editor.variableID207case EDIT_VAR_PROPVAL // property value208checkResult = object.propertyValue209break210211case 0 // direction212checkResult = object.direction213checkResult &= 1214break215216end switch217else218switch editor.variableID219case EDIT_VAR_PROPVAL // property value220object.propertyValue = editor.variableValue221break222223case 0 // direction224object.direction = editor.variableValue225object.direction &= 1226break227228end switch229end if230end event231232233event RSDKDraw234DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)235end event236237238event RSDKLoad239LoadSpriteSheet("MCZ/Objects.gif")240SpriteFrame(-32, -24, 64, 48, 136, 66)241242// Redundant to the actual direction attribute, but this helps to highlight this over property value243AddEditorVariable("direction")244SetActiveVariable("direction")245AddEnumVariable("Left", 0)246AddEnumVariable("Right", 1)247248// May as well chuck this here too, y'know?249SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")250end event251252253