Path: blob/main/Scripts/Special/HWBackG_S1.txt
1319 views
//---------------Sonic CD HW Background Script----------------//1//--------Scripted by Christian Whitehead 'The Taxman'--------//2//-------Unpacked By Rubberduckycooly's Script Unpacker-------//34// Do note, even if the Object's name implies that it's only to be used in HW mode,5// it always gets used, even in SW mode!67// Aliases8#alias Object.Value0 : Object.Timer910// These pair of values correspond to X coordinates on the sprite sheet11#alias Object.Value1 : Object.SpriteL12#alias Object.Value2 : Object.SpriteR1314// These pair of values correspond to Y coodinates on the sprite sheet15// Value4 - SpriteB - is unused16#alias Object.Value3 : Object.SpriteT17#alias Object.Value4 : Object.SpriteB1819// Oscillating value from 0 to 1023, used to determine the base X position/angle for the background20#alias Object.Value5 : Object.Oscillation2122// The following values were changed between initial release and the current release23// -> The gist of it is, an extra face was added to smooth things out so some other24// stuff had to be adjusted accordingly too2526// How many Faces & Vertexes there are in the Object27// Originally 5 and 20, respectivly, though one update changed it to make it a bit larger instead28#alias 6 : HWBACK_FACECOUNT29#alias 24 : HWBACK_VERTEXCOUNT3031// The Offset used when wrapping around from the upper half to lower half Vertexes32// Similarly to the above, this was 15 before this object got updated33#alias 19 : HWBACK_VERTEXOFFSET3435// Priority36#alias 1 : PRIORITY_ACTIVE3738// Face Buffer Flags39#alias 1 : FACE_FLAG_TEXTURED_2D404142sub ObjectDraw43Object.Timer++44if Object.Timer > 545Object.Timer = 04647Object.Frame++48Object.Frame &= 314950// As needed, switch the current Palette to another one if needed51// Palette banks 0 and 1 are inverse of each other, for the background aspects, where52// red becomes blue and vise-versa53if Object.Frame > 1554SetActivePalette(1, 0, Screen.YSize)55else56SetActivePalette(0, 0, Screen.YSize)57end if5859// Update the left bounds for the sprite to use60Object.SpriteL = Object.Frame61Object.SpriteL &= 362Object.SpriteL <<= 76364// Each sprite is 128 pixels wide, so just take the left bounds and65// add 127 to that to get to the other side66Object.SpriteR = Object.SpriteL67Object.SpriteR += 1276869// Also find the top bounds for the sprite to use70Object.SpriteT = Object.Frame71Object.SpriteT &= 1572Object.SpriteT >>= 273Object.SpriteT <<= 77475// And then similarly, since the sprite is 128 pixels tall,76// just add 127 to the top bounds to get the bottom bounds77Object.SpriteB = Object.SpriteT78Object.SpriteB += 12779end if8081// Update the Oscillation value, over a range of 102482Object.Oscillation++83Object.Oscillation &= 10238485// Round down the Oscillation value to range from an angle of 0 through 51186TempValue4 = Object.Oscillation87TempValue4 >>= 18889// Get the base sprite Top for the following vertexes to use90TempValue1 = Object.SpriteT9192// Starat from Vertex 0, in accordance to what was set to the Faces in ObjectStartup93ArrayPos0 = 09495// Get the value for the top of the vertexes to follow96Sin(TempValue3, TempValue4)97TempValue3 >>= 298TempValue3 -= 12899100// Inverse that value for the bottom of the vertexes to use101TempValue4 += 256102TempValue4 &= 511103104// And now, update all the vertexes105106// Vertex 0, top left of the first (top left rectangle)107VertexBuffer[ArrayPos0].u = Object.SpriteL108VertexBuffer[ArrayPos0].v = TempValue1109VertexBuffer[ArrayPos0].x = TempValue3110ArrayPos0++111112// Move the X113TempValue3 += 128114115// Vertex 1, top right of the first face (top left rectangle)116VertexBuffer[ArrayPos0].u = Object.SpriteR117VertexBuffer[ArrayPos0].v = TempValue1118VertexBuffer[ArrayPos0].x = TempValue3119ArrayPos0 += 3120121// Vertex 4, top left of the second face122VertexBuffer[ArrayPos0].u = Object.SpriteL123VertexBuffer[ArrayPos0].v = TempValue1124VertexBuffer[ArrayPos0].x = TempValue3125ArrayPos0++126127TempValue3 += 128128129// Vertex 5, top right of the second face130VertexBuffer[ArrayPos0].u = Object.SpriteR131VertexBuffer[ArrayPos0].v = TempValue1132VertexBuffer[ArrayPos0].x = TempValue3133ArrayPos0 += 3134135// Vertex 8, top left of the third face136VertexBuffer[ArrayPos0].u = Object.SpriteL137VertexBuffer[ArrayPos0].v = TempValue1138VertexBuffer[ArrayPos0].x = TempValue3139ArrayPos0++140141TempValue3 += 128142143// Vertex 9, top right of the third face144VertexBuffer[ArrayPos0].u = Object.SpriteR145VertexBuffer[ArrayPos0].v = TempValue1146VertexBuffer[ArrayPos0].x = TempValue3147ArrayPos0 += 3148149// Vertex 12, top left of the fourth face150VertexBuffer[ArrayPos0].u = Object.SpriteL151VertexBuffer[ArrayPos0].v = TempValue1152VertexBuffer[ArrayPos0].x = TempValue3153ArrayPos0++154155TempValue3 += 128156157// Vertex 13, top right of the foruth face158VertexBuffer[ArrayPos0].u = Object.SpriteR159VertexBuffer[ArrayPos0].v = TempValue1160VertexBuffer[ArrayPos0].x = TempValue3161ArrayPos0 += 3162163// Vertex 16, top left of the fifth face164VertexBuffer[ArrayPos0].u = Object.SpriteL165VertexBuffer[ArrayPos0].v = TempValue1166VertexBuffer[ArrayPos0].x = TempValue3167ArrayPos0++168169TempValue3 += 128170171// Vertex 17, top right of the fifth face172VertexBuffer[ArrayPos0].u = Object.SpriteR173VertexBuffer[ArrayPos0].v = TempValue1174VertexBuffer[ArrayPos0].x = TempValue3175176// The following is for the sixth face, which isn't in the Steam version177178ArrayPos0 += 3179180// Vertex 20, top left of the sixth face181VertexBuffer[ArrayPos0].u = Object.SpriteL182VertexBuffer[ArrayPos0].v = TempValue1183VertexBuffer[ArrayPos0].x = TempValue3184ArrayPos0++185186TempValue3 += 128187188// Vertex 21, top right of the sixth face189VertexBuffer[ArrayPos0].u = Object.SpriteR190VertexBuffer[ArrayPos0].v = TempValue1191VertexBuffer[ArrayPos0].x = TempValue3192193// And now, go back as needed to reach the vertexes for the bottom of the faces194ArrayPos0 -= HWBACK_VERTEXOFFSET195196// Move the sprite Y position to now be at the actual bottom of the sprite197// (This is gonna make it SpriteB, essentially)198TempValue1 += 128199200// Get the new, inverted x position201// -> TempValue4 was inverted above already202Sin(TempValue3, TempValue4)203TempValue3 >>= 2204TempValue3 -= 128205206// Vertex 2, bottom left of the first face207VertexBuffer[ArrayPos0].u = Object.SpriteL208VertexBuffer[ArrayPos0].v = TempValue1209VertexBuffer[ArrayPos0].x = TempValue3210ArrayPos0++211212TempValue3 += 128213214// Vertex 3, bottom right of the first face215VertexBuffer[ArrayPos0].u = Object.SpriteR216VertexBuffer[ArrayPos0].v = TempValue1217VertexBuffer[ArrayPos0].x = TempValue3218ArrayPos0 += 3219220// Vertex 6, bottom left of the second face221VertexBuffer[ArrayPos0].u = Object.SpriteL222VertexBuffer[ArrayPos0].v = TempValue1223VertexBuffer[ArrayPos0].x = TempValue3224ArrayPos0++225226TempValue3 += 128227228// Vertex 7, bottom right of the second face229VertexBuffer[ArrayPos0].u = Object.SpriteR230VertexBuffer[ArrayPos0].v = TempValue1231VertexBuffer[ArrayPos0].x = TempValue3232ArrayPos0 += 3233234// Vertex 10, bottom left of the third face235VertexBuffer[ArrayPos0].u = Object.SpriteL236VertexBuffer[ArrayPos0].v = TempValue1237VertexBuffer[ArrayPos0].x = TempValue3238ArrayPos0++239240TempValue3 += 128241242// Vertex 11, bottom right of the third face243VertexBuffer[ArrayPos0].u = Object.SpriteR244VertexBuffer[ArrayPos0].v = TempValue1245VertexBuffer[ArrayPos0].x = TempValue3246ArrayPos0 += 3247248// Vertex 14, bottom left of the fourth face249VertexBuffer[ArrayPos0].u = Object.SpriteL250VertexBuffer[ArrayPos0].v = TempValue1251VertexBuffer[ArrayPos0].x = TempValue3252ArrayPos0++253254TempValue3 += 128255256// Vertex 15, bottom right of the fourth face257VertexBuffer[ArrayPos0].u = Object.SpriteR258VertexBuffer[ArrayPos0].v = TempValue1259VertexBuffer[ArrayPos0].x = TempValue3260ArrayPos0 += 3261262// Vertex 18, bottom left of the fifth face263VertexBuffer[ArrayPos0].u = Object.SpriteL264VertexBuffer[ArrayPos0].v = TempValue1265VertexBuffer[ArrayPos0].x = TempValue3266ArrayPos0++267268TempValue3 += 128269270// Vertex 19, bottom right of the fifth face271VertexBuffer[ArrayPos0].u = Object.SpriteR272VertexBuffer[ArrayPos0].v = TempValue1273VertexBuffer[ArrayPos0].x = TempValue3274275// Extra sixth face, not in the original Steam release276277ArrayPos0 += 3278279// Vertex 22, bottom left of the sixth face280VertexBuffer[ArrayPos0].u = Object.SpriteL281VertexBuffer[ArrayPos0].v = TempValue1282VertexBuffer[ArrayPos0].x = TempValue3283ArrayPos0++284285TempValue3 += 128286287// Vertex 23, bottom right of the sixth face288VertexBuffer[ArrayPos0].u = Object.SpriteR289VertexBuffer[ArrayPos0].v = TempValue1290VertexBuffer[ArrayPos0].x = TempValue3291292// And now, set the number of faces and vertexes as needed, so that293// the 3d Scene draw function will know how many things to draw2943DScene.NoVertices = HWBACK_VERTEXCOUNT2953DScene.NoFaces = HWBACK_FACECOUNT296297Draw3DScene()298299end sub300301302sub ObjectStartup303304// Reset the 3d stuff to be normal305MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)306MatrixTranslateXYZ(MAT_VIEW, 0, 0, 0)307308// Turn the background into the version with only the water, without the wave background309Stage.ActiveLayer[0] = 3310311LoadSpriteSheet("Special/SSBG1.gif")312313// Place an HW Background Object into the scene, in the last of the Reserved Object Slots314// This happens, regardless of if the game is in SW or HW render mode, despite the Object's name315Object[31].Type = TypeName[HW Background]316317// Make it always active, so that it constantly runs318Object[31].Priority = PRIORITY_ACTIVE319320// This is a Background, so make it draw as one of course321Object[31].DrawOrder = 0322323// Set initial sprite bounds324// SpriteB is never referenced much, but set it here anyway325Object[31].SpriteL = 0326Object[31].SpriteR = 128327Object[31].SpriteT = 0328Object[31].SpriteB = 128329330ArrayPos0 = 0331TempValue0 = 0332333// Setup all the Faces for the background334while ArrayPos0 < HWBACK_FACECOUNT335336// Set the Face's corners337// TempValue0 corresponds to a VertexBuffer ID338FaceBuffer[ArrayPos0].a = TempValue0339TempValue0++340FaceBuffer[ArrayPos0].b = TempValue0341TempValue0++342FaceBuffer[ArrayPos0].c = TempValue0343TempValue0++344FaceBuffer[ArrayPos0].d = TempValue0345TempValue0++346347FaceBuffer[ArrayPos0].Flag = FACE_FLAG_TEXTURED_2D348349// Move onto the next Face350351ArrayPos0++352loop353354// Set all Vertexes to have a z value of 1355// -> This doesn't matter too much really, as 2D Faces don't use the z value356ArrayPos0 = 0357while ArrayPos0 < HWBACK_VERTEXCOUNT358VertexBuffer[ArrayPos0].z = 1359ArrayPos0++360loop361362// Set all the y positions for all the vertexes363364TempValue0 = 0365ArrayPos0 = 0366while TempValue0 < 128367368// First, set up all the upper vertexes, with a y value of 0369370// First face371VertexBuffer[ArrayPos0].y = TempValue0372ArrayPos0++373VertexBuffer[ArrayPos0].y = TempValue0374ArrayPos0 += 3375376// Second face377VertexBuffer[ArrayPos0].y = TempValue0378ArrayPos0++379VertexBuffer[ArrayPos0].y = TempValue0380ArrayPos0 += 3381382// Third face383VertexBuffer[ArrayPos0].y = TempValue0384ArrayPos0++385VertexBuffer[ArrayPos0].y = TempValue0386ArrayPos0 += 3387388// Fourth face389VertexBuffer[ArrayPos0].y = TempValue0390ArrayPos0++391VertexBuffer[ArrayPos0].y = TempValue0392ArrayPos0 += 3393394// Fifth face395VertexBuffer[ArrayPos0].y = TempValue0396ArrayPos0++397VertexBuffer[ArrayPos0].y = TempValue0398399// Extra Sixth face400ArrayPos0 += 3401VertexBuffer[ArrayPos0].y = TempValue0402ArrayPos0++403VertexBuffer[ArrayPos0].y = TempValue0404405// Loop back to the lower half vertexes406ArrayPos0 -= HWBACK_VERTEXOFFSET407408// Each vertex should be 128 pixels tall409TempValue0 += 128410411// First face412VertexBuffer[ArrayPos0].y = TempValue0413ArrayPos0++414VertexBuffer[ArrayPos0].y = TempValue0415ArrayPos0 += 3416417// Second face418VertexBuffer[ArrayPos0].y = TempValue0419ArrayPos0++420VertexBuffer[ArrayPos0].y = TempValue0421ArrayPos0 += 3422423// Third face424VertexBuffer[ArrayPos0].y = TempValue0425ArrayPos0++426VertexBuffer[ArrayPos0].y = TempValue0427ArrayPos0 += 3428429// Fourth face430VertexBuffer[ArrayPos0].y = TempValue0431ArrayPos0++432VertexBuffer[ArrayPos0].y = TempValue0433ArrayPos0 += 3434435// Fifth face436VertexBuffer[ArrayPos0].y = TempValue0437ArrayPos0++438VertexBuffer[ArrayPos0].y = TempValue0439440// Extra, sixth face441ArrayPos0 += 3442VertexBuffer[ArrayPos0].y = TempValue0443ArrayPos0++444VertexBuffer[ArrayPos0].y = TempValue0445446ArrayPos0++447448// Setup the alternate palette449450// First, copy the current entire palette bank 0 over to palette bank 1451CopyPalette(0, 1)452453// And now, load 32 colors from the external palette cycle file into454// palette bank 1, starting from slot 208455LoadPalette("SS1H_PalCycle.act", 1, 208, 0, 32)456loop457458end sub459460461// ========================462// Editor Subs463// ========================464465sub RSDKDraw466DrawSprite(0)467end sub468469470sub RSDKLoad471LoadSpriteSheet("Special/SSBG1.gif")472SpriteFrame(-32, -32, 64, 64, 1, 143)473474SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")475end sub476477478