Path: blob/main/Scripts/R7/PathSwap.txt
1319 views
//-----------------Sonic CD Path Swap Script------------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Do note, these are not the same genre of "Path Swappers" as used in loops!5// Although in Sonic 1/Sonic 2 they're dedicated objects that can be placed, in Sonic CD the chunks are instead swapped in real-time, just like the original game6// And, the system used in R7's loops is handled in the stage's respective [R7X Setup] script, not here7// This object is just the little Sonic sign that you can jump at89// Aliases10#alias 0 : PATHSWAP_IDLE11#alias 1 : PATHSWAP_SPINNING1213#alias Object.Value0 : Object.Timer1415// If the Player has touched this Path Swapper last frame, used to distinguish new touches from old touches16#alias Object.Value7 : Object.PrevTouch1718#alias Object.Value1 : Object.ChunkX119#alias Object.Value3 : Object.ChunkX220#alias Object.Value2 : Object.ChunkY121#alias Object.Value4 : Object.ChunkY22223// Holds the chunk ID of what's already there on the level map, New holds what it should be replaced with24#alias Object.Value5 : Object.ChunkIDOld25#alias Object.Value6 : Object.ChunkIDNew2627// Priority28#alias 0 : PRIORITY_BOUNDS29#alias 1 : PRIORITY_ACTIVE303132sub ObjectMain33if Object.State == PATHSWAP_SPINNING34if Object.Timer < 3935Object.Timer++36else37Object.State = PATHSWAP_IDLE38Object.Timer = 039Object.Priority = PRIORITY_BOUNDS40end if4142PathSwap_Frame = Object.Timer43PathSwap_Frame /= 544end if4546if PathSwap_Flag == false47TempValue0 = Object.ChunkIDOld48else49TempValue0 = Object.ChunkIDNew50end if5152if Object.PropertyValue != 153SetTileLayerEntry(TempValue0, 0, Object.ChunkX1, Object.ChunkY1)54TempValue0++55SetTileLayerEntry(TempValue0, 0, Object.ChunkX2, Object.ChunkY1)56TempValue0++57SetTileLayerEntry(TempValue0, 0, Object.ChunkX1, Object.ChunkY2)58TempValue0++59SetTileLayerEntry(TempValue0, 0, Object.ChunkX2, Object.ChunkY2)60end if6162end sub636465sub ObjectPlayerInteraction6667if Object.PropertyValue < 268if Object.State == PATHSWAP_IDLE69if PathSwap_Frame == 070PlayerObjectCollision(C_TOUCH, -16, -16, 16, 16)71if CheckResult == true72if Object.PrevTouch == false73Object.State = PATHSWAP_SPINNING74Object.Priority = PRIORITY_ACTIVE75Object.PrevTouch = true7677// This is a weird way to do it... but sure78// A `^= true` would work just as well here too, though you don't see those all too often in CD79PathSwap_Flag++80PathSwap_Flag &= true8182#platform: Use_Haptics83// Give the player a bit of a shake to really convey the feeling that they've hit a sign, y'know?8485HapticEffect(19, 0, 0, 0)86#endplatform8788end if89else90Object.PrevTouch = false91end if92end if93end if94end if9596end sub979899sub ObjectDraw100if Object.PropertyValue < 2101DrawSprite(PathSwap_Frame)102end if103end sub104105106sub ObjectStartup107108LoadSpriteSheet("R7/Objects.gif")109110// Path Swapper Frames111SpriteFrame(-24, -15, 48, 40, 109, 18)112SpriteFrame(-24, -11, 48, 36, 158, 22)113SpriteFrame(-24, -7, 48, 32, 207, 26)114SpriteFrame(-24, -11, 48, 36, 158, 63)115SpriteFrame(-24, -15, 48, 40, 109, 59)116SpriteFrame(-24, -11, 48, 36, 158, 63)117SpriteFrame(-24, -7, 48, 32, 207, 26)118SpriteFrame(-24, -11, 48, 36, 158, 22)119120PathSwap_Flag = false121PathSwap_Frame = 0122123ArrayPos0 = 32124while ArrayPos0 < 1056125if Object[ArrayPos0].Type == TypeName[Path Swap]126127// Setup chunk positions128129Object[ArrayPos0].ChunkX1 = Object[ArrayPos0].iXPos130Object[ArrayPos0].ChunkX1 >>= 8131Object[ArrayPos0].ChunkX1 <<= 1132133Object[ArrayPos0].ChunkX2 = Object[ArrayPos0].ChunkX1134Object[ArrayPos0].ChunkX2++135136Object[ArrayPos0].ChunkY1 = Object[ArrayPos0].iYPos137Object[ArrayPos0].ChunkY1 >>= 8138Object[ArrayPos0].ChunkY1 <<= 1139140Object[ArrayPos0].ChunkY2 = Object[ArrayPos0].ChunkY1141Object[ArrayPos0].ChunkY2++142143// Setup chunk IDs144145// Get the base chunk ID146GetTileLayerEntry(Object[ArrayPos0].ChunkIDOld, 0, Object[ArrayPos0].ChunkX1, Object[ArrayPos0].ChunkY1)147148// The chunk's B replacement is always 4 chunks immediately after it149Object[ArrayPos0].ChunkIDNew = Object[ArrayPos0].ChunkIDOld150Object[ArrayPos0].ChunkIDNew += 4151152end if153154ArrayPos0++155loop156157end sub158159160// ========================161// Editor Subs162// ========================163164sub RSDKEdit165if Editor.ReturnVariable == true166switch Editor.VariableID167case EDIT_VAR_PROPVAL // Property Value168case 0 // Type169CheckResult = Object.PropertyValue170break171end switch172else173switch Editor.VariableID174case EDIT_VAR_PROPVAL // Property Value175case 0 // Type176Object.PropertyValue = Editor.VariableValue177break178end switch179end if180end sub181182183sub RSDKDraw184GetBit(Object.InkEffect, Object.PropertyValue, 1) // Invis types get to be blended185DrawSpriteFX(0, FX_INK, Object.XPos, Object.YPos)186end sub187188189sub RSDKLoad190LoadSpriteSheet("R7/Objects.gif")191SpriteFrame(-24, -15, 48, 40, 109, 18)192193AddEditorVariable("Type")194SetActiveVariable("Type")195196// Bit of a guess here -197// Subtype 0 is used just about everywhere, 2 is used in SSZ1B once, and then 2 is completely unused it seems?198199AddEnumVariable("Normal", 0)200AddEnumVariable("Decoration", 1)201AddEnumVariable("Invisible", 2) // Used to update chunks but without the sign being visible there202end sub203204205