Path: blob/main/Scripts/R7/Spotlights.txt
1319 views
//-----------------Sonic CD Spotlights Script-----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Aliases56// Position for where the checkpoint should progress to its next version7#alias Object.Value1 : Object.Checkpoint89// The colors the Spotlight should use10// Just like everything else, these colors are in RRGGBB11#alias Object.Value2 : Object.PrimaryBaseColor12#alias Object.Value3 : Object.SecondaryBaseColor13#alias Object.Value4 : Object.PrimaryDisplayColor14#alias Object.Value5 : Object.SecondaryDisplayColor1516// There are several different types of spotlights that appear in the stage17#alias Object.Value0 : Object.SpotlightType18// 0 - Pair of two primary ones19// - Using SSZ1A's, it's the two big green ones20// 1 - Single primary one21// - Using SSZ1A's, it's a single green one22// 2 - Pair of two secondary ones23// - Using SSZ1A's, it's the two yellow ones24// 3 - Single small primary one25// - Using SSZ1A's, it's a single small green one26// 4 - Pair of primary and secondary27// - Using SSZ1A's, the pair of a small green one with a big yellow one28// Then it loops back2930// HUD Alias31#alias Object[24].PropertyValue : HUD.CurrentTimePeriod3233// Time Periods34#alias 0 : TIME_PRESENT35#alias 2 : TIME_GOOD_FUTURE36#alias 3 : TIME_BAD_FUTURE3738// Face Buffer Flags39#alias 3 : FACE_FLAG_COLOURED_2D4041// Priority42#alias 1 : PRIORITY_ACTIVE4344// Function declarations45#function Spotlights_UpdateCorner464748function Spotlights_UpdateCorner4950// Called individually for each corner in a spotlight to update it5152// Preconditions:53// - ArrayPos0 is the ID of the vertex that should be changes54// - TempValue0 is the X multiplier for how much extra this vertex should move55// - TempValue1 is the Y multiplier for how much extra this vertex should move56// (These last two values are here since spotlights aren't uniform in width - they can be skewed to uneven dimensions as well)575859Sin(TempValue2, Object.Rotation)60TempValue2 *= TempValue16162Cos(TempValue3, Object.Rotation)63TempValue3 *= TempValue06465VertexBuffer[ArrayPos0].x = TempValue266VertexBuffer[ArrayPos0].x -= TempValue367VertexBuffer[ArrayPos0].x >>= 968VertexBuffer[ArrayPos0].x += Object.XPos6970Cos(TempValue2, Object.Rotation)71TempValue2 *= TempValue17273Sin(TempValue3, Object.Rotation)74TempValue3 *= TempValue07576VertexBuffer[ArrayPos0].y = TempValue277VertexBuffer[ArrayPos0].y += TempValue378VertexBuffer[ArrayPos0].y >>= 979VertexBuffer[ArrayPos0].y += 2568081end function828384sub ObjectMain85TempValue0 = Oscillation86TempValue0 <<= 28788// Get some smooth arc movement values8990Sin(TempValue1, TempValue0)91TempValue1 >>= 592TempValue1 += 649394Cos(TempValue2, TempValue0)95TempValue2 >>= 596TempValue2 += 649798// Make the spotlight colors oscillate99100Object.PrimaryDisplayColor = TempValue1101Object.PrimaryDisplayColor <<= 24102Object.PrimaryDisplayColor += Object.PrimaryBaseColor103104Object.SecondaryDisplayColor = TempValue2105Object.SecondaryDisplayColor <<= 24106Object.SecondaryDisplayColor += Object.SecondaryBaseColor107108// Check if the current spotlight type should be switched109110TempValue0 = Screen.XOffset111TempValue0 += Screen.CenterX112if TempValue0 > Object.Checkpoint113TempValue0 -= Object.Checkpoint114if TempValue0 > 440115// Move the next checkpoint ahead116Object.Checkpoint += 880117118// Trigger the next spotlight type to start119Object.SpotlightType++120121if Object.SpotlightType > 4122// Loop back123Object.SpotlightType = 0124end if125end if126else127TempValue0 -= Object.Checkpoint128if TempValue0 < -440129// Move the next checkpoint back130Object.Checkpoint -= 880131132// Trigger the next spotlight type to start133Object.SpotlightType--134135if Object.SpotlightType < 0136// Loop ahead137Object.SpotlightType = 4138end if139end if140end if141142// Scroll the spotlight143Object.XPos = Object.Checkpoint144Object.XPos -= Screen.XOffset145146// Different handlings for the different types of spotlights147switch Object.SpotlightType148case 0149// Pair of two primary spotlights150151// Make these spotlights draw above the rest of the stage & its objects152Object.DrawOrder = 5153154// 2 rectangles means 8 vertices and 2 faces1553DScene.NoVertices = 81563DScene.NoFaces = 2157158// 1st Spotlight offset - move it a bit to the left159Object.XPos -= 48160161// Mirror the face color to match the targetted color162FaceBuffer[0].Color = Object.PrimaryDisplayColor163FaceBuffer[1].Color = Object.PrimaryDisplayColor164165166// First do spotlight 1 (the left one)167168// Get the base rotation for the spotlight169170TempValue0 = Oscillation171TempValue0 <<= 1172Sin(Object.Rotation, TempValue0)173if Object.Rotation > 0174// Enforce that the spotlight never goes towards the left175FlipSign(Object.Rotation)176end if177Object.Rotation /= 10178Object.Rotation += 512179180// And now move all the vertexes for it181182// Top right183ArrayPos0 = 0184TempValue0 = -16185TempValue1 = -384186CallFunction(Spotlights_UpdateCorner)187188// Top left189ArrayPos0++190TempValue0 = 16191TempValue1 = -384192CallFunction(Spotlights_UpdateCorner)193194// Bottom right195ArrayPos0++196TempValue0 = -8197TempValue1 = 0198CallFunction(Spotlights_UpdateCorner)199200// Bottom left201ArrayPos0++202TempValue0 = 8203TempValue1 = 0204CallFunction(Spotlights_UpdateCorner)205206ArrayPos0++207208// And now update the other spotlight (to the right)209210// Move the sedong spotlight to the right211// (48 px from the base spotlight position)212Object.XPos += 96213214TempValue0 = Oscillation215TempValue0 <<= 1216Sin(Object.Rotation, TempValue0)217Object.Rotation /= 10218Object.Rotation += 512219220// Top right221TempValue0 = -16222TempValue1 = -384223CallFunction(Spotlights_UpdateCorner)224225// Top left226ArrayPos0++227TempValue0 = 16228TempValue1 = -384229CallFunction(Spotlights_UpdateCorner)230231// Bottom right232ArrayPos0++233TempValue0 = -8234TempValue1 = 0235CallFunction(Spotlights_UpdateCorner)236237// Bottom left238ArrayPos0++239TempValue0 = 8240TempValue1 = 0241CallFunction(Spotlights_UpdateCorner)242243ArrayPos0++244break245246case 1247// Single primary spotlight248249// Make this object draw in the background250Object.DrawOrder = 2251252// 1 rectangle means 4 vertices and 1 face2533DScene.NoVertices = 42543DScene.NoFaces = 1255256// Set its color to what it should be257FaceBuffer[0].Color = Object.PrimaryDisplayColor258259// Handle spotlight movement260TempValue0 = Oscillation261TempValue0 <<= 1262Sin(Object.Rotation, TempValue0)263Object.Rotation >>= 3264Object.Rotation += 512265266// Top right267ArrayPos0 = 0268TempValue0 = -16269TempValue1 = -384270CallFunction(Spotlights_UpdateCorner)271272// Top left273ArrayPos0++274TempValue0 = 16275TempValue1 = -384276CallFunction(Spotlights_UpdateCorner)277278// Bottom right279ArrayPos0++280TempValue0 = -8281TempValue1 = 0282CallFunction(Spotlights_UpdateCorner)283284// Bottom left285ArrayPos0++286TempValue0 = 8287TempValue1 = 0288CallFunction(Spotlights_UpdateCorner)289290ArrayPos0++291break292293case 2294// Two secondary spotlights295296// Make it draw above everything else again297Object.DrawOrder = 5298299// 2 spotlight rectangles means 8 vertices and 2 faces3003DScene.NoVertices = 83013DScene.NoFaces = 2302303// Set the display colors...304FaceBuffer[0].Color = Object.SecondaryDisplayColor305FaceBuffer[1].Color = Object.SecondaryDisplayColor306307// ...and then apply the spotlight offset...308Object.XPos -= 48309310// ..but then set the colors again? Why is this done twice?311FaceBuffer[0].Color = Object.SecondaryDisplayColor312FaceBuffer[1].Color = Object.SecondaryDisplayColor313314// Make the spotlight move315TempValue0 = Oscillation316TempValue0 <<= 1317Sin(Object.Rotation, TempValue0)318Object.Rotation >>= 4319Object.Rotation += 500320321// Move all the vertexes as needed322323// Top right324ArrayPos0 = 0325TempValue0 = -20326TempValue1 = -384327CallFunction(Spotlights_UpdateCorner)328329// Top left330ArrayPos0++331TempValue0 = 20332TempValue1 = -384333CallFunction(Spotlights_UpdateCorner)334335// Bottom right336ArrayPos0++337TempValue0 = -10338TempValue1 = 0339CallFunction(Spotlights_UpdateCorner)340341// Bottom left342ArrayPos0++343TempValue0 = 10344TempValue1 = 0345CallFunction(Spotlights_UpdateCorner)346347ArrayPos0++348349// Do spotlight 2 now, starting with its small X offset350Object.XPos += 96351352TempValue0 = Oscillation353TempValue0 += 32354TempValue0 <<= 1355Sin(Object.Rotation, TempValue0)356Object.Rotation >>= 3357Object.Rotation += 508358359// Top right360TempValue0 = -16361TempValue1 = -420362CallFunction(Spotlights_UpdateCorner)363364// Top left365ArrayPos0++366TempValue0 = 16367TempValue1 = -420368CallFunction(Spotlights_UpdateCorner)369370// Bottom right371ArrayPos0++372TempValue0 = -8373TempValue1 = 0374CallFunction(Spotlights_UpdateCorner)375376// Bottom left377ArrayPos0++378TempValue0 = 8379TempValue1 = 0380CallFunction(Spotlights_UpdateCorner)381382ArrayPos0++383break384385case 3386// Single small primary spotlight387388// This version should draw above everything else as well389Object.DrawOrder = 5390391// 1 spotlight rectangle has four corners and one face3923DScene.NoVertices = 43933DScene.NoFaces = 1394395FaceBuffer[0].Color = Object.PrimaryDisplayColor396397// Bounce the spotlight as needed398TempValue0 = 512399TempValue0 -= Oscillation400TempValue0 *= 3401Sin(Object.Rotation, TempValue0)402Object.Rotation /= 12403Object.Rotation += 520404405// Top right406ArrayPos0 = 0407TempValue0 = -12408TempValue1 = -384409CallFunction(Spotlights_UpdateCorner)410411// Top left412ArrayPos0++413TempValue0 = 12414TempValue1 = -384415CallFunction(Spotlights_UpdateCorner)416417// Bottom right418ArrayPos0++419TempValue0 = -4420TempValue1 = 0421CallFunction(Spotlights_UpdateCorner)422423// Bottom left424ArrayPos0++425TempValue0 = 4426TempValue1 = 0427CallFunction(Spotlights_UpdateCorner)428ArrayPos0++429break430431case 4432// A pair of primary and secondary spotlights433434// This variant should draw in the BG435Object.DrawOrder = 2436437// 2 rectangles means that there should be 8 vertices and 2 faces4383DScene.NoVertices = 84393DScene.NoFaces = 2440441Object.XPos -= 48442443FaceBuffer[0].Color = Object.PrimaryDisplayColor444FaceBuffer[1].Color = Object.SecondaryDisplayColor445446// First do spotlight 1447448// Update its rotation449TempValue0 = Oscillation450TempValue0 += 64451TempValue0 <<= 2452Sin(Object.Rotation, TempValue0)453Object.Rotation /= 20454Object.Rotation += 496455456// Top right457ArrayPos0 = 0458TempValue0 = -14459TempValue1 = -420460CallFunction(Spotlights_UpdateCorner)461462// Top left463ArrayPos0++464TempValue0 = 14465TempValue1 = -420466CallFunction(Spotlights_UpdateCorner)467468// Bottom right469ArrayPos0++470TempValue0 = -4471TempValue1 = 0472CallFunction(Spotlights_UpdateCorner)473474// Bottom left475ArrayPos0++476TempValue0 = 4477TempValue1 = 0478CallFunction(Spotlights_UpdateCorner)479480ArrayPos0++481482// Do spotlight 2 now483484// Total shift of 48 from its starting position, keeping the above subtraction of 48 in mind485Object.XPos += 96486487// Rotate the spotlight488TempValue0 = Oscillation489TempValue0 <<= 1490Sin(Object.Rotation, TempValue0)491Object.Rotation >>= 4492Object.Rotation += 520493494// Top right495TempValue0 = -24496TempValue1 = -420497CallFunction(Spotlights_UpdateCorner)498499// Top left500ArrayPos0++501TempValue0 = 24502TempValue1 = -420503CallFunction(Spotlights_UpdateCorner)504505// Bottom right506ArrayPos0++507TempValue0 = -16508TempValue1 = 0509CallFunction(Spotlights_UpdateCorner)510511// Bottom left512ArrayPos0++513TempValue0 = 16514TempValue1 = 0515CallFunction(Spotlights_UpdateCorner)516517ArrayPos0++518break519520end switch521522end sub523524525sub ObjectDraw526// The spotlights are all 3d, so instead of drawing sprites, draw the entire 3d scene instead527Draw3DScene()528529end sub530531532sub ObjectStartup533534// Reset the 3d stuff535MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)536MatrixTranslateXYZ(MAT_VIEW, 0, 0, 0)537538// Setup the first spotlight539FaceBuffer[0].a = 0540FaceBuffer[0].b = 1541FaceBuffer[0].c = 2542FaceBuffer[0].d = 3543FaceBuffer[0].Flag = FACE_FLAG_COLOURED_2D544545// Setup the second spotlight546FaceBuffer[1].a = 4547FaceBuffer[1].b = 5548FaceBuffer[1].c = 6549FaceBuffer[1].d = 7550FaceBuffer[1].Flag = FACE_FLAG_COLOURED_2D551552// Loop through all obejcts in the stage and setup all Spotlights objects553ArrayPos0 = 32554while ArrayPos0 < 1056555if Object[ArrayPos0].Type == TypeName[Spotlights]556557// Spotlights should always be active558Object[ArrayPos0].Priority = PRIORITY_ACTIVE559560// The default draw priority for a spotlight should be above the stage & objects but below the HUD561Object[ArrayPos0].DrawOrder = 5562563// And set up the initial starting checkpoint value as well564Object[ArrayPos0].Checkpoint = Screen.CenterX565566// Setup the Spotlight's colors based on the current time period567switch HUD.CurrentTimePeriod568case TIME_PRESENT569// Present gets standard colors - set the primary spotlight to green570Object[ArrayPos0].PrimaryBaseColor = 128571Object[ArrayPos0].PrimaryBaseColor <<= 16572TempValue0 = 224573TempValue0 <<= 8574Object[ArrayPos0].PrimaryBaseColor += TempValue0575Object[ArrayPos0].PrimaryBaseColor += 128576577// Set the secondary spotlight to yellow578Object[ArrayPos0].SecondaryBaseColor = 224579Object[ArrayPos0].SecondaryBaseColor <<= 16580TempValue0 = 224581TempValue0 <<= 8582Object[ArrayPos0].SecondaryBaseColor += TempValue0583Object[ArrayPos0].SecondaryBaseColor += 0584break585586// No case 1 since spotlights didn't even exist in the Past...587588case TIME_GOOD_FUTURE589// The Good Future gets nice and bright colors - primary spotlight is brown590Object[ArrayPos0].PrimaryBaseColor = 192591Object[ArrayPos0].PrimaryBaseColor <<= 16592TempValue0 = 128593TempValue0 <<= 8594Object[ArrayPos0].PrimaryBaseColor += TempValue0595Object[ArrayPos0].PrimaryBaseColor += 0596597// And the secondary spotlight is blue598Object[ArrayPos0].SecondaryBaseColor = 0599Object[ArrayPos0].SecondaryBaseColor <<= 16600TempValue0 = 192601TempValue0 <<= 8602Object[ArrayPos0].SecondaryBaseColor += TempValue0603Object[ArrayPos0].SecondaryBaseColor += 224604break605606case TIME_BAD_FUTURE607// Bad Future gets cool and fancy colors, primary spotlight is pink608Object[ArrayPos0].PrimaryBaseColor = 224609Object[ArrayPos0].PrimaryBaseColor <<= 16610TempValue0 = 64611TempValue0 <<= 8612Object[ArrayPos0].PrimaryBaseColor += TempValue0613Object[ArrayPos0].PrimaryBaseColor += 128614615// And secondary spotlight is purple616Object[ArrayPos0].SecondaryBaseColor = 224617Object[ArrayPos0].SecondaryBaseColor <<= 16618TempValue0 = 128619TempValue0 <<= 8620Object[ArrayPos0].SecondaryBaseColor += TempValue0621Object[ArrayPos0].SecondaryBaseColor += 192622break623624end switch625626end if627628ArrayPos0++629loop630631// Set the initial screen offset, this is used in calculations for cycling spotlights632Screen.XOffset = Player.XPos633Screen.XOffset >>= 16634Screen.XOffset -= Screen.CenterX635636end sub637638639// ========================640// Editor Subs641// ========================642643644sub RSDKDraw645DrawSprite(0)646end sub647648649sub RSDKLoad650LoadSpriteSheet("Global/Display.gif")651SpriteFrame(-16, -16, 32, 32, 1, 143) // "Script" Icon652653// This object uses 3d, so there's not really any good way to show it in the editor...654// It's normally placed out of bounds though, so it doesn't matter too much anyway655656SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")657end sub658659660