Path: blob/main/Scripts/R5/CPlatform.txt
1319 views
//-----------------Sonic CD CPlatform Script------------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.LedgeLeft6#alias Object.Value1 : Object.LedgeRight7#alias Object.Value2 : Object.Timer8#alias Object.Value3 : Object.NoBlocks9#alias Object.Value4 : Object.YVelocity1011// States12#alias 0 : CPLATFORM_ACTIVE13#alias 1 : CPLATFORM_WAIT_R14#alias 2 : CPLATFORM_WAIT_L15#alias 3 : CPLATFORM_CRUMBLE_L16#alias 4 : CPLATFORM_CRUMBLE_R17#alias 5 : CPLATFORM_RESPAWNWAIT18#alias 6 : CPLATFORM_FALLINGBLOCK1920// Stage SFX21#alias 0 : SFX_S_CRUMBLE2223// Priority24#alias 0 : PRIORITY_BOUNDS25#alias 1 : PRIORITY_ACTIVE2627// Property Values28#alias 1 : PLATFORM_DEBRIS_129#alias 2 : PLATFORM_DEBRIS_2303132sub ObjectMain3334switch Object.State3536// Nothing for CPLATFORM_ACTIVE here37// Initial triggering of crumbling is all handled in ObjectPlayerInteraction instead3839case CPLATFORM_WAIT_R40if Object.Timer > 041Object.Timer--42else43PlayStageSfx(SFX_S_CRUMBLE, false)4445Object.State = CPLATFORM_CRUMBLE_R46end if47break4849case CPLATFORM_WAIT_L50if Object.Timer > 051Object.Timer--52else53PlayStageSfx(SFX_S_CRUMBLE, false)5455Object.State = CPLATFORM_CRUMBLE_L56end if57break5859case CPLATFORM_CRUMBLE_L60Object.Timer++61if Object.Timer == 1062Object.Timer = 063if Object.LedgeLeft < Object.LedgeRight64Object.NoBlocks--65Object.LedgeLeft += 166667// Start spawning fragments6869// First, get the XPos to start at70TempValue0 = Object.LedgeLeft71TempValue0 -= 872TempValue0 <<= 1673TempValue0 += Object.XPos7475// Then get the YPos, 8 pixels above this base object76TempValue1 = Object.YPos77TempValue1 -= 0x800007879// Spawning of the First Fragment80CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)81Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK82Object[TempObjectPos].YVelocity = -0x1000083Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_18485// Put the second piece 16 pixels down86TempValue1 += 0x1000008788// Spawning of the Second Fragment89CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)90Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK91Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_292else93ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, 0, 0)94end if95end if96break9798case CPLATFORM_CRUMBLE_R99Object.Timer++100if Object.Timer == 10101Object.Timer = 0102if Object.LedgeRight > Object.LedgeLeft103Object.NoBlocks--104Object.LedgeRight -= 16105106// Start making the Fragments107108// First, find the target XPos109TempValue0 = Object.LedgeRight110TempValue0 += 8111TempValue0 <<= 16112TempValue0 += Object.XPos113114// Then, make the target YPos 8 pixels above this base object115TempValue1 = Object.YPos116TempValue1 -= 0x80000117118// Create the first Fragment119CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)120Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK121Object[TempObjectPos].YVelocity = -0x10000122Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_1123124// Second piece should be 16 pixels down125TempValue1 += 0x100000126127// Create the second Fragment128CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)129Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK130Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_2131else132ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, 0, 0)133end if134end if135break136137case CPLATFORM_RESPAWNWAIT138// This state acts as a buffer of sorts, so that the platform doesn't respawn while it's still visible to the player139// It also acts as a soft reset, of sorts140if Object.OutOfBounds == true141Object.State = CPLATFORM_ACTIVE142Object.NoBlocks = Object.PropertyValue143144Object.LedgeLeft = Object.PropertyValue145Object.LedgeLeft <<= 3146147Object.LedgeRight = Object.LedgeLeft148FlipSign(Object.LedgeLeft)149150Object.Priority = PRIORITY_BOUNDS151Object.Timer = 0152end if153break154155case CPLATFORM_FALLINGBLOCK156// Apply a gravity of 0.25 pixels per frame157Object.YVelocity += 0x4000158if Object.YVelocity > 0159Object.YPos += Object.YVelocity160end if161162if Object.OutOfBounds == true163// Unload when no longer needed164Object.Type = TypeName[Blank Object]165end if166break167168end switch169170end sub171172173sub ObjectPlayerInteraction174175if Object.State == CPLATFORM_ACTIVE176PlayerObjectCollision(C_PLATFORM, Object.LedgeLeft, -16, Object.LedgeRight, 16)177178if CheckResult == true179Object.Timer = 1180Object.Priority = PRIORITY_ACTIVE181182if Player.XPos > Object.XPos183Object.State = CPLATFORM_WAIT_R184else185Object.State = CPLATFORM_WAIT_L186end if187end if188else189PlayerObjectCollision(C_PLATFORM, Object.LedgeLeft, -16, Object.LedgeRight, 16)190end if191192end sub193194195sub ObjectDraw196197switch Object.State198case CPLATFORM_ACTIVE199case CPLATFORM_WAIT_R200case CPLATFORM_WAIT_L201case CPLATFORM_CRUMBLE_R202// Draw the Platform piece by piece, starting from the left203TempValue0 = 0204TempValue1 = Object.LedgeLeft205TempValue1 <<= 16206TempValue1 += 0x80000207TempValue1 += Object.XPos208while TempValue0 < Object.NoBlocks209DrawSpriteXY(0, TempValue1, Object.YPos)210TempValue0++211TempValue1 += 0x100000212loop213break214215case CPLATFORM_CRUMBLE_L216// Draw the Platform piece by piece, starting from the right217TempValue0 = 0218TempValue1 = Object.LedgeRight219TempValue1 <<= 16220TempValue1 -= 0x80000221TempValue1 += Object.XPos222while TempValue0 < Object.NoBlocks223DrawSpriteXY(0, TempValue1, Object.YPos)224TempValue0++225TempValue1 -= 0x100000226loop227break228229case CPLATFORM_FALLINGBLOCK230DrawSprite(Object.PropertyValue)231break232233end switch234235end sub236237238sub ObjectStartup239LoadSpriteSheet("R5/Objects.gif")240241// Setup the Ledge Sizes for all CPlatform Objects present in the level242ArrayPos0 = 32243while ArrayPos0 < 1056244if Object[ArrayPos0].Type == TypeName[CPlatform]245Object[ArrayPos0].NoBlocks = Object[ArrayPos0].PropertyValue246247Object[ArrayPos0].LedgeLeft = Object[ArrayPos0].PropertyValue248Object[ArrayPos0].LedgeLeft <<= 3249250Object[ArrayPos0].LedgeRight = Object[ArrayPos0].LedgeLeft251252FlipSign(Object[ArrayPos0].LedgeLeft)253end if254255ArrayPos0++256loop257258// Ledge Frame259SpriteFrame(-8, -16, 16, 32, 108, 51)260261// Broken Ledge Frames262SpriteFrame(-8, -8, 16, 16, 108, 51)263SpriteFrame(-8, -8, 16, 16, 108, 67)264265end sub266267268// ========================269// Editor Subs270// ========================271272sub RSDKEdit273if Editor.ReturnVariable == true274switch Editor.VariableID275case EDIT_VAR_PROPVAL // Property Value276case 0 // BlocksNo277CheckResult = Object.PropertyValue278break279end switch280else281switch Editor.VariableID282case EDIT_VAR_PROPVAL // Property Value283case 0 // BlocksNo284Object.PropertyValue = Editor.VariableValue285break286end switch287end if288end sub289290291sub RSDKDraw292TempValue0 = 0293TempValue1 = Object.PropertyValue294TempValue1 <<= 19295TempValue1 -= 0x80000296TempValue1 += Object.XPos297while TempValue0 < Object.PropertyValue298DrawSpriteXY(0, TempValue1, Object.YPos)299TempValue0++300TempValue1 -= 0x100000301loop302end sub303304305sub RSDKLoad306LoadSpriteSheet("R5/Objects.gif")307SpriteFrame(-8, -16, 16, 32, 108, 51)308309AddEditorVariable("BlocksNo")310SetActiveVariable("BlocksNo")311end sub312313314