Path: blob/main/Scripts/R7/RSpringCage.txt
1319 views
//---------------Sonic CD R Spring Cage Script----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Note - Object[+1] should be an R7Spring object56// Aliases7#alias Object.Value0 : Object.FullAngle8#alias Object.Value1 : Object.Angle9#alias Object.Value3 : Object.RightArmOffset1011// R7 Spring Aliases12#alias Object.Value0 : Object.Timer1314// States15#alias 0 : RSPRINGCAGE_IDLE16#alias 1 : RSPRINGCAGE_LOCKINPLAYER17#alias 2 : RSPRINGCAGE_SHOOTPLAYER18#alias 3 : RSPRINGCAGE_RESTORE1920// Gravity21#alias 1 : GRAVITY_AIR2223// Stage SFX24#alias 0 : SFX_S_LARGEBOOSTER // In origins, this SFX is Launcher25#alias 1 : SFX_S_SWITCH2627// Property Values28#alias 0 : ROTATING_CAGE29#alias 1 : STATIC_CAGE303132sub ObjectMain33switch Object.State34case RSPRINGCAGE_IDLE35if Object.PropertyValue == ROTATING_CAGE36Object.FullAngle++37Object.FullAngle %= 483839Object.Angle = Object.FullAngle40Object.Angle /= 641end if42break4344case RSPRINGCAGE_LOCKINPLAYER45if Object.RightArmOffset > 046// Close it in, 2 pixels per frame47Object.RightArmOffset -= 0x2000048else49PlayStageSfx(SFX_S_SWITCH, false)50Object.State++51end if52break5354case RSPRINGCAGE_SHOOTPLAYER55if Player.State != Player_State_Death56if Object.PropertyValue == ROTATING_CAGE57Object.FullAngle++58Object.FullAngle %= 4859Object.Angle = Object.FullAngle60Object.Angle /= 661end if6263Player.Animation = ANI_JUMPING6465Player.XPos = Object.XPos66Player.YPos = Object.YPos6768switch Object.Angle69case 070Player.XPos += 0x200000 // Offset of 32 pixels right71break72case 173Player.XPos += 0x180000 // Offset of 24 pixels right74Player.YPos -= 0x180000 // Offset of 24 pixels up75break76case 277Player.YPos -= 0x200000 // Offset of 32 pixels up78break79case 380Player.XPos -= 0x180000 // Offset of 24 pixels left81Player.YPos -= 0x180000 // Offset of 24 pixels up82break83case 484Player.XPos -= 0x200000 // Offset of 32 pixels left85break86case 587Player.XPos -= 0x180000 // Offset of 24 pixels left88Player.YPos += 0x180000 // Offset of 24 pixels down89break90case 691Player.YPos += 0x200000 // Offset of 32 pixels down92break93case 794Player.XPos += 0x180000 // Offset of 24 pixels right95Player.YPos += 0x180000 // Offset of 24 pixels down96break97end switch9899if Player.JumpPress == true100PlayStageSfx(SFX_S_LARGEBOOSTER, false)101102#platform: Use_Origins103Player.State = Player_State_Air_NoDropDash104#endplatform105106#platform: Use_Standalone107Player.State = Player_State_Air108#endplatform109Player.Gravity = GRAVITY_AIR110Player.Timer = 0111112// Tell the spring to start animating113Object[+1].Timer = 1114115Object.State++116switch Object.Angle117case 0118Player.Speed = 0x100000119Player.XVelocity = 0x100000120Player.YVelocity = 0121break122case 1123Player.Speed = 0xC0000124Player.XVelocity = 0xC0000125Player.YVelocity = -720896126break127case 2128Player.Speed = 0129Player.XVelocity = 0130Player.YVelocity = -0x100000131break132case 3133Player.Speed = -0xC0000134Player.XVelocity = -0xC0000135Player.YVelocity = -720896136break137case 4138Player.Speed = -0x100000139Player.XVelocity = -0x100000140Player.YVelocity = 0141break142case 5143Player.Speed = -0xC0000144Player.XVelocity = -0xC0000145Player.YVelocity = 720896146break147case 6148Player.Speed = 0149Player.XVelocity = 0150Player.YVelocity = 0x100000151break152case 7153Player.Speed = 0xC0000154Player.XVelocity = 0xC0000155Player.YVelocity = 720896156break157end switch158end if159else160Object.State = RSPRINGCAGE_RESTORE161end if162break163164case RSPRINGCAGE_RESTORE165if Object[+1].Timer == 0166if Object.RightArmOffset < 0x300000167// Opening it back up, 8 pixels per frame168Object.RightArmOffset += 0x80000169else170Object.State = RSPRINGCAGE_IDLE171end if172end if173break174175end switch176177// Change the spring's angle178179switch Object.Angle180case 0181Object[+1].Direction = FACING_RIGHT182Object[+1].PropertyValue = 1183break184case 1185Object[+1].Direction = FACING_RIGHT186Object[+1].PropertyValue = 4187break188case 2189Object[+1].Direction = FACING_RIGHT190Object[+1].PropertyValue = 0191break192case 3193Object[+1].Direction = FACING_RIGHT194Object[+1].PropertyValue = 5195break196case 4197Object[+1].Direction = FACING_RIGHT198Object[+1].PropertyValue = 2199break200case 5201Object[+1].Direction = 2202Object[+1].PropertyValue = 5203break204case 6205Object[+1].Direction = FACING_RIGHT206Object[+1].PropertyValue = 3207break208case 7209Object[+1].Direction = 2210Object[+1].PropertyValue = 4211break212end switch213214end sub215216217sub ObjectPlayerInteraction218219if Object.State == RSPRINGCAGE_IDLE220PlayerObjectCollision(C_TOUCH, -24, -24, 24, 24)221if CheckResult == true222Object.State = RSPRINGCAGE_LOCKINPLAYER223224// Put the player inside the cage225Player.XPos = Object.XPos226Player.YPos = Object.YPos227Player.State = Player_State_Static228Player.Animation = ANI_JUMPING229Player.Speed = 0230Player.XVelocity = 0231Player.YVelocity = 0232233// 8 possible directions, 8 possible jump locations~234switch Object.Angle235case 0236Player.XPos += 0x200000 // Offset of 32 pixels right237break238case 1239Player.XPos += 0x180000 // Offset of 24 pixels right240Player.YPos -= 0x180000 // Offset of 24 pixels up241break242case 2243Player.YPos -= 0x200000 // Offset of 32 pixels up244break245case 3246Player.XPos -= 0x180000 // Offset of 24 pixels left247Player.YPos -= 0x180000 // Offset of 24 pixels up248break249case 4250Player.XPos -= 0x200000 // Offset of 32 pixels left251break252case 5253Player.XPos -= 0x180000 // Offset of 24 pixels left254Player.YPos += 0x180000 // Offset of 24 pixels down255break256case 6257Player.YPos += 0x200000 // Offset of 32 pixels down258break259case 7260Player.XPos += 0x180000 // Offset of 24 pixels right261Player.YPos += 0x180000 // Offset of 24 pixels down262break263end switch264end if265end if266267end sub268269270sub ObjectDraw271272// Different draw routines for the 8 possible directions273274switch Object.Angle275case 0276DrawSprite(1)277Object.Direction = 2278TempValue0 = Object.XPos279TempValue0 -= Object.RightArmOffset280DrawSpriteFX(1, FX_FLIP, TempValue0, Object.YPos)281break282283case 1284DrawSprite(2)285Object.Direction = 3286TempValue2 = Object.RightArmOffset287TempValue2 >>= 1288TempValue0 = Object.XPos289TempValue0 -= TempValue2290TempValue1 = Object.YPos291TempValue1 += TempValue2292DrawSpriteFX(3, FX_FLIP, TempValue0, TempValue1)293break294295case 2296DrawSprite(4)297Object.Direction = FACING_LEFT298TempValue1 = Object.YPos299TempValue1 += Object.RightArmOffset300DrawSpriteFX(4, FX_FLIP, Object.XPos, TempValue1)301break302303case 3304Object.Direction = FACING_LEFT305TempValue2 = Object.RightArmOffset306TempValue2 >>= 1307TempValue0 = Object.XPos308TempValue0 += TempValue2309TempValue1 = Object.YPos310TempValue1 += TempValue2311DrawSpriteFX(2, FX_FLIP, TempValue0, TempValue1)312Object.Direction = 2313DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)314break315316case 4317TempValue0 = Object.XPos318TempValue0 += Object.RightArmOffset319DrawSpriteXY(5, TempValue0, Object.YPos)320Object.Direction = 2321DrawSpriteFX(5, FX_FLIP, Object.XPos, Object.YPos)322break323324case 5325Object.Direction = 3326DrawSpriteFX(2, FX_FLIP, Object.XPos, Object.YPos)327Object.Direction = FACING_RIGHT328TempValue2 = Object.RightArmOffset329TempValue2 >>= 1330TempValue0 = Object.XPos331TempValue0 += TempValue2332TempValue1 = Object.YPos333TempValue1 -= TempValue2334DrawSpriteFX(3, FX_FLIP, TempValue0, TempValue1)335break336337case 6338Object.Direction = 2339TempValue1 = Object.YPos340TempValue1 -= Object.RightArmOffset341DrawSpriteFX(4, FX_FLIP, Object.XPos, TempValue1)342Object.Direction = 3343DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos)344break345346case 7347Object.Direction = 2348TempValue2 = Object.RightArmOffset349TempValue2 >>= 1350TempValue0 = Object.XPos351TempValue0 -= TempValue2352TempValue1 = Object.YPos353TempValue1 -= TempValue2354DrawSpriteFX(2, FX_FLIP, TempValue0, TempValue1)355Object.Direction = FACING_LEFT356DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)357break358359end switch360361DrawSprite(0)362363end sub364365366sub ObjectStartup367368LoadSpriteSheet("R7/Objects.gif")369370// Cage Frames371372// Pivot Post Frame373SpriteFrame(-8, -8, 16, 16, 90, 52)374375// Top Horizontal Half376SpriteFrame(-8, -28, 64, 24, 34, 96)377378// Top Diagonal Half379SpriteFrame(-24, -56, 56, 56, 59, 121)380381// Bottom Diagonal Half382SpriteFrame(-56, -24, 56, 56, 59, 121)383384// (Shared) Vertical Half385SpriteFrame(-28, -56, 24, 64, 34, 121)386387// Bottom Horizontal Half388SpriteFrame(-56, -28, 64, 24, 34, 96)389390// Setup all Rotating Cage objects within the level391ArrayPos0 = 32392while ArrayPos0 < 1056393if Object[ArrayPos0].Type == TypeName[R Spring Cage]394395// Focus on the Cage's corresponding R7 Spring object396ArrayPos1 = ArrayPos0397ArrayPos1++398399Object[ArrayPos0].DrawOrder = 4400401// Set the right arm to start 48 pixels back402Object[ArrayPos0].RightArmOffset = 0x300000403404// Move the spring to the Cage's position too405Object[ArrayPos1].XPos = Object[ArrayPos0].XPos406Object[ArrayPos1].YPos = Object[ArrayPos0].YPos407end if408409ArrayPos0++410loop411412end sub413414415// ========================416// Editor Subs417// ========================418419sub RSDKEdit420if Editor.ReturnVariable == true421switch Editor.VariableID422case EDIT_VAR_PROPVAL // Property Value423CheckResult = Object.PropertyValue424break425case 0 // Type426CheckResult = Object.PropertyValue427break428end switch429else430switch Editor.VariableID431case EDIT_VAR_PROPVAL // Property Value432Object.PropertyValue = Editor.VariableValue433break434case 0 // Type435Object.PropertyValue = Editor.VariableValue436break437end switch438end if439end sub440441442sub RSDKDraw443DrawSprite(0)444Object.Direction = FACING_LEFT445TempValue1 = Object.YPos446TempValue1 += 0x300000447DrawSpriteFX(0, FX_FLIP, Object.XPos, TempValue1)448449if Editor.ShowGizmos == true450GetObjectType(TempValue0, "R7 Spring")451452ArrayPos1 = Object[+1].EntityNo453if Object[ArrayPos1].type != TempValue0454// Uh oh! The next object is supposed to be a special spring, but here it isn't...455// Gotta let the user know!456457Editor.DrawingOverlay = true458459// First draw a red line from the cage to the invalid object460DrawArrow(Object.XPos, Object.YPos, Object[ArrayPos1].XPos, Object[ArrayPos1].YPos, 255, 0, 0)461462// And now draw an X463464TempValue0 = Object[ArrayPos1].XPos465TempValue0 -= 0x100000466467TempValue1 = Object[ArrayPos1].YPos468TempValue1 -= 0x100000469470TempValue2 = Object[ArrayPos1].XPos471TempValue2 += 0x100000472473TempValue3 = Object[ArrayPos1].YPos474TempValue3 += 0x100000475476DrawLine(TempValue0, TempValue1, TempValue2, TempValue3, 255, 0, 0)477DrawLine(TempValue2, TempValue1, TempValue0, TempValue3, 255, 0, 0)478479Editor.DrawingOverlay = false480end if481end if482end sub483484485sub RSDKLoad486LoadSpriteSheet("R7/Objects.gif")487SpriteFrame(-28, -56, 24, 64, 34, 121)488489AddEditorVariable("Type")490SetActiveVariable("Type")491AddEnumVariable("Rotate", 0)492AddEnumVariable("Static", 1)493end sub494495496