Path: blob/main/Scripts/Special/BGEffects_S5.txt
1319 views
//-----------------Sonic CD BGEffects Script------------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases5// Values 0-1 are unused...6#alias Object.Value2 : Object.PrevAngle7#alias Object.Value3 : Object.FansTimer8#alias Object.Value4 : Object.CrunchersTimer9#alias Object.Value5 : Object.FansSprite10#alias Object.Value6 : Object.CrunchersSprite1112// Priority13#alias 1 : PRIORITY_ACTIVE141516sub ObjectDraw17// Animate the Fan tiles throughout the level18Object.FansTimer++19if Object.FansTimer > 220Object.FansTimer = 021Object.FansSprite++22Object.FansSprite %= 323switch Object.FansSprite24case 025// Fans are 4x4 tiles, comprised of 8 unique tiles, so26// 8 individual tiles need to be updated to change the entire sprite27Copy16x16Tile(174, 472)28Copy16x16Tile(175, 473)29Copy16x16Tile(176, 474)30Copy16x16Tile(177, 475)31Copy16x16Tile(183, 476)32Copy16x16Tile(184, 477)33Copy16x16Tile(185, 478)34Copy16x16Tile(186, 479)35break3637case 138Copy16x16Tile(174, 480)39Copy16x16Tile(175, 481)40Copy16x16Tile(176, 482)41Copy16x16Tile(177, 483)42Copy16x16Tile(183, 484)43Copy16x16Tile(184, 485)44Copy16x16Tile(185, 486)45Copy16x16Tile(186, 487)46break4748case 249Copy16x16Tile(174, 488)50Copy16x16Tile(175, 489)51Copy16x16Tile(176, 490)52Copy16x16Tile(177, 491)53Copy16x16Tile(183, 492)54Copy16x16Tile(184, 493)55Copy16x16Tile(185, 494)56Copy16x16Tile(186, 495)57break5859end switch60end if6162// Animate the Crunching tiles in the level63Object.CrunchersTimer++64if Object.CrunchersTimer > 565Object.CrunchersTimer = 066Object.CrunchersSprite++67Object.CrunchersSprite &= 368switch Object.CrunchersSprite69case 070// Crunchers are 2x2 tiles, each tile unique,71// so 4 tiles need to be updated in order to completely change their sprite72Copy16x16Tile(76, 496)73Copy16x16Tile(77, 497)74Copy16x16Tile(82, 500)75Copy16x16Tile(83, 501)76break7778case 179Copy16x16Tile(76, 498)80Copy16x16Tile(77, 499)81Copy16x16Tile(82, 502)82Copy16x16Tile(83, 503)83break8485case 286Copy16x16Tile(76, 504)87Copy16x16Tile(77, 505)88Copy16x16Tile(82, 508)89Copy16x16Tile(83, 509)90break9192case 393Copy16x16Tile(76, 506)94Copy16x16Tile(77, 507)95Copy16x16Tile(82, 510)96Copy16x16Tile(83, 511)97break9899end switch100end if101102// Find the difference from the last and current scroll pos103104TempValue1 = Object.PrevAngle105TempValue2 = TileLayer[0].Angle106107// Acount for looping before doing the actual calculations108if TempValue1 < TempValue2109TempValue3 = TempValue2110TempValue3 -= TempValue1111if TempValue3 > 256112TempValue1 += 512113end if114else115TempValue3 = TempValue1116TempValue3 -= TempValue2117if TempValue3 > 256118TempValue2 += 512119end if120end if121122// The actual finding of the difference123TempValue0 = TempValue1124TempValue0 -= TempValue2125126// Store the current scroll pos for use next frame127Object.PrevAngle = TileLayer[0].Angle128129// Move the other BG layers based on the difference found130131TempValue1 = 0x10000132TempValue2 = 0x20000133134TempValue1 *= TempValue0135136HParallax[0].ScrollPos += TempValue1137138TempValue2 *= TempValue0139HParallax[2].ScrollPos += TempValue2140141// Make it only move 96 pixels max, otherwise wrap around142HParallax[2].ScrollPos %= 0x600000143144// And move the third layer to match145HParallax[3].ScrollPos = HParallax[2].ScrollPos146HParallax[3].ScrollPos >>= 16147148// Now, update the pseudo-3d-ness of the BG red bars using deformation149// Process is done from the bottom of the screen -> upwards150151// - ArrayPos0 is the current line, starting off as the number of lines to change152// - TempValue2 is the starting offset153// - TempValue3 gets applied to the offset after every line in order to make the top of the screen move less drastically to the bottom154155ArrayPos0 = 128156TempValue2 = 0x4000157TempValue3 = 0158while ArrayPos0 > -1159TempValue4 = HParallax[3].ScrollPos160TempValue4 *= TempValue2161162// Shift it by different amounts depending on the current renderer163// 14 is used for when using Software Rendering, 10 is used for Hardware164// Do note - swapping them around WILL crash the game!165// These values must've been picked with great care in order for that to happen166167#platform: HW_Rendering168TempValue4 >>= 10169#endplatform170171#platform: SW_Rendering172TempValue4 >>= 14173#endplatform174175Stage.DeformationData2[ArrayPos0] = TempValue4176TempValue2 -= TempValue3177TempValue3++178179ArrayPos0--180loop181182#platform: HW_Rendering183// If using the hardware render, draw the BG as a sprite & rect here184185DrawSpriteScreenFX(0, FX_SCALE, 0, 0)186187// Draw a black rectagle across the screen188DrawRect(296, 0, 256, 128, 0, 0, 0, 255)189#endplatform190191end sub192193194sub ObjectStartup195196// Set the stage's bounds197Stage.XBoundary1 = 0x3000000 // left bounds @ 768 pixels198Stage.XBoundary2 = 0xD000000 // right bounds @ 3328 pixels199Stage.YBoundary1 = 0x3000000 // upper bounds @ 768 pixels200Stage.YBoundary2 = 0xD000000 // lower bounds @ 3328 pixels201202#platform: HW_Rendering203// If needed, do some setup for hardware rendering204LoadSpriteSheet("Special/SSMap5.gif")205206// Seems to be a random patch in the middle of nowhere?207SpriteFrame(0, 0, 32, 48, 107, 384)208#endplatform209210// Set starting scroll positions211212// Make the first parallax layer start at 176 pixels from its base position213HParallax[0].ScrollPos = 0xB00000214215// Set the other starting scroll position, but with respect to the screen's size to make it start in the right place216TempValue0 = Screen.XSize217TempValue0 -= 320218TempValue0 <<= 15219220// Base position of 96 pixels221HParallax[1].ScrollPos = 0x600000222223// And then subtract from that as needed224HParallax[1].ScrollPos -= TempValue0225226// Setup all BGEffect objects in the level227ArrayPos0 = 32228while ArrayPos0 < 1056229if Object[ArrayPos0].Type == TypeName[BGEffects]230231// Make it always active232Object[ArrayPos0].Priority = PRIORITY_ACTIVE233234// It should the first object to have its draw code run235Object[ArrayPos0].DrawOrder = 0236237// Set the starting angle... but why is this 192? All other ones are 368 instead...238Object[ArrayPos0].PrevAngle = 192239240// Set the scale for the object to draw at241// (Only used for hardware rendering)242Object[ArrayPos0].Scale = 1536243244end if245246ArrayPos0++247loop248249end sub250251252// ========================253// Editor Subs254// ========================255256sub RSDKDraw257DrawSprite(0)258end sub259260261sub RSDKLoad262LoadSpriteSheet("Special/SSMap5.gif")263SpriteFrame(-256, -256, 512, 512, 0, 0)264265SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")266end sub267268269