Path: blob/main/Scripts/R5/FallPlatform.txt
1319 views
//--------------Sonic CD Falling Platform Script--------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5#alias Object.Value0 : Object.Stood6#alias Object.Value1 : Object.DipTimer7#alias Object.Value2 : Object.MoveY8#alias Object.Value3 : Object.Timer9#alias Object.Value4 : Object.YVelocity10#alias Object.Value5 : Object.StartPosY1112// HUD Alias13#alias Object[24].PropertyValue : HUD.CurrentTimePeriod1415// States16#alias 0 : FALLPLATFORM_FLOAT17#alias 1 : FALLPLATFORM_SUSPEND18#alias 2 : FALLPLATFORM_FALLING19#alias 3 : FALLPLATFORM_OFFSCREEN2021// Time Period Aliases22#alias 0 : TIME_PRESENT23#alias 1 : TIME_PAST24#alias 2 : TIME_GOOD_FUTURE25#alias 3 : TIME_BAD_FUTURE2627// Priority28#alias 0 : PRIORITY_BOUNDS29#alias 1 : PRIORITY_ACTIVE303132sub ObjectMain3334// Object.Stood is supposed to be set from last frame, by ObjectPlayerInteraction3536if Object.Stood == true37if Object.State == FALLPLATFORM_FLOAT38Object.State = FALLPLATFORM_SUSPEND39end if4041if Object.DipTimer < 1642// Sink down4344Object.DipTimer++4546TempValue0 = Object.DipTimer47TempValue0 &= 34849if TempValue0 == 350// Dip a pixel down51Object.MoveY = 0x1000052else53Object.MoveY = 054end if55else56Object.MoveY = 057end if58else59if Object.DipTimer > 060// Move back up6162Object.DipTimer--6364TempValue0 = Object.DipTimer65TempValue0 &= 36667if TempValue0 == 368// Recover a pixel upwards again69Object.MoveY = -0x1000070else71Object.MoveY = 072end if73else74Object.MoveY = 075end if76end if7778// Reset it, to be set in ObjectPlayerInteraction again later this frame79Object.Stood = false8081switch Object.State82case FALLPLATFORM_SUSPEND83if Object.Timer < 3084// Hold for a moment before starting to fall85Object.Timer++86else87// Fall away!8889Object.YVelocity = 090Object.Timer = 091Object.State = FALLPLATFORM_FALLING9293// Make this Object always active, needed for its respawn process94Object.Priority = PRIORITY_ACTIVE95end if96break9798case FALLPLATFORM_FALLING99// If the Object yet hasn't reached a Y Velocity of 4 pixels per frame,100// then accelerate at a rate of 0.125 pixels per frame101if Object.YVelocity < 0x40000102Object.YVelocity += 0x2000103end if104105// Move the Platform106// (Via increasing its move value)107Object.MoveY += Object.YVelocity108109// Has the Object fallen out of range now?110if Object.OutOfBounds == true111112// Move the Platform back to its base Position113Object.YPos = Object.StartPosY114115// Reset to the Buffer State116Object.State = FALLPLATFORM_OFFSCREEN117Object.YVelocity = 0118119end if120break121122case FALLPLATFORM_OFFSCREEN123if Object.OutOfBounds == true124// Now that the Platform is out of the Player's view, reset all the way back to normal125Object.State = FALLPLATFORM_FLOAT126Object.Priority = PRIORITY_BOUNDS127end if128break129130end switch131132end sub133134135sub ObjectPlayerInteraction136137if Object.State < FALLPLATFORM_OFFSCREEN138139// Support for different Platform sizes140// This also supports Conveyor Platforms, in a way, but the Player isn't moved along the Conveyor141switch Object.PropertyValue142case 0143// Small Platform144PlayerObjectCollision(C_PLATFORM, -16, -16, 16, 12)145if CheckResult == true146Object.Stood = true147Player.YPos += Object.MoveY148end if149break150151case 1152// Medium-sized Platform153PlayerObjectCollision(C_PLATFORM, -32, -16, 32, 12)154if CheckResult == true155Object.Stood = true156Player.YPos += Object.MoveY157end if158break159160case 2161// Large Platform162PlayerObjectCollision(C_PLATFORM, -48, -16, 48, 12)163if CheckResult == true164Object.Stood = true165Player.YPos += Object.MoveY166end if167break168169case 3170// Small Conveyor Platform171PlayerObjectCollision(C_PLATFORM, -16, -16, 16, 12)172if CheckResult == true173Object.Stood = true174Player.YPos += Object.MoveY175end if176break177178case 4179// Medium-sized Conveyor Platform180PlayerObjectCollision(C_PLATFORM, -32, -16, 32, 12)181if CheckResult == true182Object.Stood = true183Player.YPos += Object.MoveY184end if185break186187case 5188// Large Conveyor Platform189PlayerObjectCollision(C_PLATFORM, -48, -16, 48, 12)190if CheckResult == true191Object.Stood = true192Player.YPos += Object.MoveY193end if194break195196end switch197198end if199200end sub201202203sub ObjectDraw204205Object.YPos += Object.MoveY206207if Object.State < FALLPLATFORM_OFFSCREEN208switch Object.PropertyValue209case 0210case 1211case 2212// Normal Platform213DrawSprite(Object.PropertyValue)214break215216case 3217// Small Conveyor Platform218DrawSprite(0)219DrawSprite(3)220break221222case 4223// Medium-sized Coneyor Platform224DrawSprite(1)225DrawSprite(4)226break227228case 5229// Large Conveyor Platform230DrawSprite(2)231DrawSprite(5)232break233234end switch235end if236237end sub238239240sub ObjectStartup241LoadSpriteSheet("R5/Objects.gif")242243// All the Time Periods get unique platform sprites244switch HUD.CurrentTimePeriod245case TIME_PRESENT246LoadSpriteSheet("R5/Objects.gif")247SpriteFrame(-16, -16, 32, 32, 1, 51)248SpriteFrame(-32, -16, 64, 32, 34, 51)249SpriteFrame(-48, -16, 96, 32, 1, 84)250SpriteFrame(-16, -16, 32, 16, 65, 208)251SpriteFrame(-32, -16, 64, 16, 1, 208)252SpriteFrame(-48, -16, 96, 16, 1, 191)253break254255case TIME_PAST256LoadSpriteSheet("R5/Objects3.gif")257SpriteFrame(-16, -16, 32, 32, 1, 170)258SpriteFrame(-32, -16, 64, 32, 34, 170)259SpriteFrame(-48, -16, 96, 32, 1, 203)260SpriteFrame(-16, -16, 32, 16, 223, 148)261SpriteFrame(-32, -16, 64, 16, 159, 148)262SpriteFrame(-48, -16, 96, 16, 159, 131)263break264265case TIME_GOOD_FUTURE266LoadSpriteSheet("R5/Objects3.gif")267SpriteFrame(-16, -16, 32, 32, 1, 170)268SpriteFrame(-32, -16, 64, 32, 34, 170)269SpriteFrame(-48, -16, 96, 32, 1, 203)270SpriteFrame(-16, -16, 32, 16, 223, 182)271SpriteFrame(-32, -16, 64, 16, 159, 182)272SpriteFrame(-48, -16, 96, 16, 159, 165)273break274275case TIME_BAD_FUTURE276LoadSpriteSheet("R5/Objects3.gif")277SpriteFrame(-16, -16, 32, 32, 1, 170)278SpriteFrame(-32, -16, 64, 32, 34, 170)279SpriteFrame(-48, -16, 96, 32, 1, 203)280SpriteFrame(-16, -16, 32, 16, 223, 216)281SpriteFrame(-32, -16, 64, 16, 159, 216)282SpriteFrame(-48, -16, 96, 16, 159, 199)283break284285end switch286287// Loop through all Objects in the Stage and find all Falling Platforms288ArrayPos0 = 32289while ArrayPos0 < 1056290if Object[ArrayPos0].Type == TypeName[Falling Platform]291292// Store the Falling Platform's starting Position, needed for when it'll respawn293Object[ArrayPos0].StartPosY = Object[ArrayPos0].YPos294295end if296297ArrayPos0++298loop299300end sub301302303// ========================304// Editor Subs305// ========================306307sub RSDKEdit308if Editor.ReturnVariable == true309switch Editor.VariableID310case EDIT_VAR_PROPVAL // Property Value311CheckResult = Object.PropertyValue312break313case 0 // Type314CheckResult = Object.PropertyValue315break316end switch317else318switch Editor.VariableID319case EDIT_VAR_PROPVAL // Property Value320Object.PropertyValue = Editor.VariableValue321break322case 0 // Type323Object.PropertyValue = Editor.VariableValue324break325end switch326end if327end sub328329330sub RSDKDraw331if Object.PropertyValue >= 3332TempValue0 = -3333TempValue0 += Object.PropertyValue334DrawSprite(TempValue0)335end if336337DrawSprite(Object.PropertyValue)338339if Editor.ShowGizmos == true340Editor.DrawingOverlay = true341342// Draw an arrow pointing down to show that this Platform is of the falling type343344TempValue0 = Object.YPos345TempValue0 += 0x300000346347DrawArrow(Object.XPos, Object.YPos, Object.XPos, TempValue0, 255, 255, 255)348349Editor.DrawingOverlay = false350end if351end sub352353354sub RSDKLoad355// sticking with the R5A version of the sprites here...356// TODO: support for other time periods357LoadSpriteSheet("R5/Objects.gif")358SpriteFrame(-16, -16, 32, 32, 1, 51)359SpriteFrame(-32, -16, 64, 32, 34, 51)360SpriteFrame(-48, -16, 96, 32, 1, 84)361SpriteFrame(-16, -16, 32, 16, 65, 208)362SpriteFrame(-32, -16, 64, 16, 1, 208)363SpriteFrame(-48, -16, 96, 16, 1, 191)364365AddEditorVariable("Type")366SetActiveVariable("Type")367AddEnumVariable("Small", 0)368AddEnumVariable("Medium", 1)369AddEnumVariable("Large", 2)370AddEnumVariable("Small Conveyor", 3)371AddEnumVariable("Medium Conveyor", 4)372AddEnumVariable("Large Conveyor", 5)373end sub374375376